Opened 5 years ago

Closed 4 years ago

#6147 closed bug (fixed)

GeneralizedNewtypeDeriving should fail with data families

Reported by: rl Owned by: simonpj
Priority: high Milestone: 7.8.1
Component: Compiler (Type checker) Version: 7.2.1
Keywords: Cc: bos@…, bgamari@…, hackage.haskell.org@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC accepts invalid program Test Case: deriving/should_fail/T6147
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Here is an example:

{-# LANGUAGE GeneralizedNewtypeDeriving, TypeFamilies #-}
module Foo where

data family T a
data instance T Int = T_Int Int

class C a where
  foo :: a -> T a

instance C Int where
  foo = T_Int

newtype Foo = Foo Int deriving(C)

The deriving(C) clause on Foo should fail but instead it derives an instance which can't possible be correct since there is no corresponding data instance T Foo. This is closely related to #2721 (where newtype deriving was disabled in the presence of associated types) but much more difficult to test for. Probably also related to #1496.

Change History (7)

comment:1 Changed 5 years ago by rl

In fact, we can easily get a segfault by adding these two lines to the above:

data instance T Foo = T1 (Int -> Int)
main = case foo (Foo 0) of T1 f -> print (f 5)

comment:2 Changed 5 years ago by bos

Cc: bos@… added

comment:3 Changed 5 years ago by igloo

Component: CompilerCompiler (Type checker)
difficulty: Unknown
Milestone: 7.8.1
Owner: set to simonpj
Priority: normalhigh

Thanks for the report. Simon, looks like another one for you.

comment:4 Changed 5 years ago by bgamari

Cc: bgamari@… added

comment:5 Changed 5 years ago by liyang

Cc: hackage.haskell.org@… added

comment:6 Changed 4 years ago by Richard Eisenberg <eir@…>

In 9e0c1ae57526bacaca044a7ce5a6491fb6a7cb42/ghc:

Test #6147, which was fixed with the roles commit.

comment:7 Changed 4 years ago by goldfire

Resolution: fixed
Status: newclosed
Test Case: deriving/should_fail/T6147
Note: See TracTickets for help on using tickets.