Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,391
    • Issues 4,391
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 372
    • Merge Requests 372
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8128

Closed
Open
Opened Aug 13, 2013 by Adam Gundry@adamgundryDeveloper

Standalone deriving fails for GADTs due to inaccessible code

Consider the following:

{-# LANGUAGE StandaloneDeriving, GADTs, FlexibleInstances #-}

module StandaloneDerivingGADT where

data T a where
  MkT1 :: T Int
  MkT2 :: (Bool -> Bool) -> T Bool

deriving instance Show (T Int)

This gives the error:

StandaloneDerivingGADT.hs:9:1:
    Couldn't match type ‛Int’ with ‛Bool’
    Inaccessible code in
      a pattern with constructor
        MkT2 :: (Bool -> Bool) -> T Bool,
      in an equation for ‛showsPrec’
    In the pattern: MkT2 b1
    In an equation for ‛showsPrec’:
        showsPrec a (MkT2 b1)
          = showParen
              ((a >= 11)) ((.) (showString "MkT2 ") (showsPrec 11 b1))
    When typechecking the code for  ‛showsPrec’
      in a standalone derived instance for ‛Show (T Int)’:
      To see the code I am typechecking, use -ddump-deriv
    In the instance declaration for ‛Show (T Int)’

The derived instance declaration matches on all the constructors, even if they cannot possibly match. It should omit obviously inaccessible constructors so that this example is accepted. For reference, the derived code is:

  instance GHC.Show.Show
             (StandaloneDerivingGADT.T GHC.Types.Int) where
    GHC.Show.showsPrec _ StandaloneDerivingGADT.MkT1
      = GHC.Show.showString "MkT1"
    GHC.Show.showsPrec a_aij (StandaloneDerivingGADT.MkT2 b1_aik)
      = GHC.Show.showParen
          ((a_aij GHC.Classes.>= 11))
          ((GHC.Base..)
             (GHC.Show.showString "MkT2 ") (GHC.Show.showsPrec 11 b1_aik))
    GHC.Show.showList = GHC.Show.showList__ (GHC.Show.showsPrec 0)

The same problem applies to other derivable classes (e.g. Eq).

Trac metadata
Trac field Value
Version 7.7
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
8.6.1
Milestone
8.6.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#8128