Opened 3 years ago

Closed 20 months 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@…,…
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):


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 3 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 3 years ago by bos

  • Cc bos@… added

comment:3 Changed 3 years ago by igloo

  • Component changed from Compiler to Compiler (Type checker)
  • difficulty set to Unknown
  • Milestone set to 7.8.1
  • Owner set to simonpj
  • Priority changed from normal to high

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

comment:4 Changed 3 years ago by bgamari

  • Cc bgamari@… added

comment:5 Changed 3 years ago by liyang

  • Cc… added

comment:6 Changed 20 months ago by Richard Eisenberg <eir@…>

In 9e0c1ae57526bacaca044a7ce5a6491fb6a7cb42/ghc:

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

comment:7 Changed 20 months ago by goldfire

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to deriving/should_fail/T6147
Note: See TracTickets for help on using tickets.