Skip to content

derived Show instances aren't protected from RebindableSyntax+OverloadedStrings

When using both RebindableSyntax and OverloadedStrings, deriving (Show) no longer works.

Example program:

{-# 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:

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.

Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information