Opened 2 years ago

Closed 2 years ago

#14365 closed bug (fixed)

Panic with (bogus?) deriving in hs-boot: newTyConEtadArity

Reported by: happykitten Owned by:
Priority: normal Milestone: 8.4.1
Component: Compiler Version: 8.2.1
Keywords: deriving Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: deriving/should_fail/T14365
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4102
Wiki Page:

Description

$ cat A.hs
module Main where

import {-# SOURCE #-} B

main = return ()
$ cat B.hs
module B where

data Foo a = Foo a
  deriving (Functor)
$ cat B.hs-boot
module B where

data Foo a
  deriving (Functor)
$ ghc --make A.hs
[1 of 3] Compiling B[boot]          ( B.hs-boot, B.o-boot )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.2.1 for i386-unknown-linux):
	newTyConEtadArity
  Foo
  Call stack:
      CallStack (from HasCallStack):
        prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable
        callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable
        pprPanic, called at compiler/types/TyCon.hs:2149:27 in ghc:TyCon

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Change History (3)

comment:1 Changed 2 years ago by RyanGlScott

Differential Rev(s): Phab:D4102
Keywords: deriving added
Status: newpatch

Well that's embarrassing. The GHC users' guide states that you can't have derived instances in .hs-boot files, but clearly we weren't checking for this in practice. Phab:D4102 is an attempt to do so.

comment:2 Changed 2 years ago by Ryan Scott <ryan.gl.scott@…>

In 101a8c7/ghc:

Error when deriving instances in hs-boot files

Summary:
According to the GHC users' guide, one cannot derive
instances for data types in `.hs-boot` files.
However, GHC was not enforcing this in practice, which led to
#14365.

Fix this by actually throwing an error if a derived instance is
detected in an `.hs-boot` file (and recommend how to fix it in the
error message.)

Test Plan: make test TEST=T14365

Reviewers: ezyang, austin, bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie

GHC Trac Issues: #14365

Differential Revision: https://phabricator.haskell.org/D4102

comment:3 Changed 2 years ago by RyanGlScott

Milestone: 8.4.1
Resolution: fixed
Status: patchclosed
Test Case: deriving/should_fail/T14365
Note: See TracTickets for help on using tickets.