Opened 5 years ago

Closed 5 years ago

#9071 closed bug (fixed)

Panic with -XDeriveFunctor when deriving from a non-Functor in a separate module

Reported by: bens Owned by:
Priority: normal Milestone: 7.8.3
Component: Compiler Version: 7.8.2
Keywords: Cc: ben.d.sinclair@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case: deriving/should_fail/T9071, T9071_2
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Mu in the same file

src/Main.hs

{-# LANGUAGE DeriveFunctor #-}

module Main where

newtype Mu f = Mu (f (Mu f))
newtype K a b = K a
newtype F a = F (Mu (K a)) deriving Functor

main :: IO ()
main = return ()

$ cabal build
Building panic-0.1.0.0...
Preprocessing executable 'panic' for panic-0.1.0.0...
[1 of 1] Compiling Main             ( src/Main.hs, dist/build/panic/panic-tmp/Main.o )

src/Main.hs:7:37:
    No instance for (Functor Mu)
      arising from the first field of ‘F’ (type ‘Mu (K a)’)
    Possible fix:
      use a standalone 'deriving instance' declaration,
        so you can specify the instance context yourself
    When deriving the instance for (Functor F)

Mu in a separate file

src/Mu.hs

module Mu where

newtype Mu f = Mu (f (Mu f))

src/Main.hs

{-# LANGUAGE DeriveFunctor #-}

module Main where

import Mu

newtype K a b = K a
newtype F a = F (Mu (K a)) deriving Functor

main :: IO ()
main = return ()

$ cabal build
Building panic-0.1.0.0...
Preprocessing executable 'panic' for panic-0.1.0.0...
[1 of 2] Compiling Mu               ( src/Mu.hs, dist/build/panic/panic-tmp/Mu.o )
[2 of 2] Compiling Main             ( src/Main.hs, dist/build/panic/panic-tmp/Main.o )

src/Main.hs:8:37:ghc: panic! (the 'impossible' happened)
  (GHC version 7.8.2 for x86_64-unknown-linux):
	Prelude.(!!): index too large


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

Change History (13)

comment:1 Changed 5 years ago by bens

It also crashes when running ghc directly, as in

ghc --make -isrc src/Main.hs

with any level of optimisation.

comment:2 Changed 5 years ago by bens

Cc: ben.d.sinclair@… added

comment:3 Changed 5 years ago by simonpj

Owner: set to simonpj

Ugh. Good catch. Fixing.

comment:4 Changed 5 years ago by Simon Peyton Jones <simonpj@…>

In 13a330e87cf459311a7f164e1e57baf877741da6/ghc:

Fix Trac #9071, an egregious bug in TcDeriv.inferConstraints

The constraints for Functor don't line up 1-1 with the arguments
(they are fetched out from sub-terms of the type), but the surrounding
code was mistakenly assuming they were in 1-1 association.

comment:5 Changed 5 years ago by Simon Peyton Jones <simonpj@…>

In 59b4e6d0ba504b33cc7064d489b8ec485a7703f4/ghc:

Adding missing test files for #9071

comment:6 Changed 5 years ago by simonpj

Status: newmerge
Test Case: deriving/should_fail/T9071, T9071_2

Fixed. Please merge to 7.8 branch.

Simon

comment:7 Changed 5 years ago by thoughtpolice

Milestone: 7.8.3

comment:8 Changed 5 years ago by thoughtpolice

Resolution: fixed
Status: mergeclosed

Merged into 7.8.3.

comment:9 Changed 5 years ago by rwbarton

Owner: simonpj deleted
Resolution: fixed
Status: closednew

There's some leftover debugging output in compiler/typecheck/TcRnTypes.lhs. Reopening so that it can be fixed and merged into 7.8.3.

comment:10 Changed 5 years ago by simonpj

Reid, thanks. Can you identify the "leftover debugging output" and/or offer a patch? Ta

Simon

comment:11 Changed 5 years ago by Reid Barton <rwbarton@…>

In c44da48c6d19b3d8cc0ba34328576683410f8ec2/ghc:

Remove extraneous debugging output (#9071)

comment:12 Changed 5 years ago by rwbarton

Status: newmerge

comment:13 Changed 5 years ago by thoughtpolice

Resolution: fixed
Status: mergeclosed

This was actually merged and I missed it.

Note: See TracTickets for help on using tickets.