[GHC] #12688: derived Show instances aren't protected from RebindableSyntax+OverloadedStrings

GHC ghc-devs at haskell.org
Tue Oct 11 14:24:58 UTC 2016


#12688: derived Show instances aren't protected from
RebindableSyntax+OverloadedStrings
-------------------------------------+-------------------------------------
           Reporter:  daviddarais    |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.0.1
           Keywords:                 |  Operating System:  Unknown/Multiple
  rebindablesyntax                   |
  overloadedstrings deriving show    |
  string                             |
       Architecture:                 |   Type of failure:  GHC rejects
  Unknown/Multiple                   |  valid program
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 When using both `RebindableSyntax` and `OverloadedStrings`, `deriving
 (Show)` no longer works.

 Example program:

 {{{#!hs
 {-# LANGUAGE RebindableSyntax, OverloadedStrings #-}

 module Bug where

 import Prelude (String,Show(..))

 newtype Text = Text String

 fromString :: String -> Text
 fromString = Text

 x :: Text
 x = "x"

 newtype Foo = Foo ()
   deriving (Show)
 }}}

 In this example, `fromString` is redefined to return a type different from
 `[Char]`. The example `x` typechecks due to to the `RebindableSyntax` and
 `OverloadedStrings` extensions. However, the generated code for the
 `deriving (Show)` instance for Foo does not typecheck, and ghc gives a
 code generation error:

 {{{#!hs
 error:
     • Couldn't match type ‘Text’ with ‘[GHC.Types.Char]’
       Expected type: String
         Actual type: Text
     • In the first argument of ‘GHC.Show.showString’, namely ‘"Foo "’
       In the first argument of ‘(GHC.Base..)’, namely
         ‘(GHC.Show.showString "Foo ")’
       In the second argument of ‘GHC.Show.showParen’, namely
         ‘((GHC.Base..) (GHC.Show.showString "Foo ") (showsPrec 11 b1))’
       When typechecking the code for ‘showsPrec’
         in a derived instance for ‘Show Foo’:
         To see the code I am typechecking, use -ddump-deriv
 }}}

 A solution would be to protect the code generated by `deriving (Show)`
 from `OverloadedStrings` and `RebindableSyntax` extensions.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12688>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list