Opened 7 months ago

Closed 7 months ago

Last modified 6 months ago

#16394 closed bug (fixed)

GHC internal error while typechecking of instance definition

Reported by: Day1721 Owned by:
Priority: low Milestone: 8.8.1
Component: Compiler (Type checker) Version: 8.6.3
Keywords: Cc:
Operating System: Linux Architecture: Unknown/Multiple
Type of failure: Incorrect error/warning at compile-time Test Case: typecheck/should_fail/T16394
Blocked By: Blocking:
Related Tickets: Differential Rev(s): MR!496
Wiki Page:

Description

Hello.
This code won't typecheck because of GHC internal error.

{-# LANGUAGE PolyKinds, TypeFamilies, DataKinds #-}

class C a where
    type T (n :: a)

--       v--DIFF--v
instance C a => C b => C (a, b) where
    type T '(n, m) = (T n, T m)

with error message:

Bug.hs:7:10: error:
    • GHC internal error: ‘T’ is not in scope during type checking, but it passed the renamer
      tcl_env of environment: [a1LS :-> Type variable ‘a’ = a :: *,
                               a1LT :-> Type variable ‘b’ = b :: *]
    • In the type instance declaration for ‘T’
      In the instance declaration for ‘C b => C (a, b)’
  |
7 |     type T (n, m) = (T n, T m)
  |          ^
Failed, no modules loaded.

but this works fine:

{-# LANGUAGE PolyKinds, TypeFamilies, DataKinds #-}

class C a where
    type T (n :: a)

--       v--DIFF--v
instance (C a, C b) => C (a, b) where
    type T '(n, m) = (T n, T m)

Not sure is a bug, but either way it would be better to make more understandable error message

Change History (5)

comment:1 Changed 7 months ago by simonpj

Happily, HEAD gives

T16394.hs:9:10: error:
    Illegal class instance: `C a => C b => C (a, b)'
      Class instances must be of the form
        context => C ty_1 ... ty_n
      where `C' is a class
  |
9 | instance C a => C b => C (a, b) where
  |          ^^^^^^^^^^^^^^^^^^^^^^

Would someone like to add a regression test and close this?

comment:2 Changed 7 months ago by bgamari

Resolution: fixed
Status: newclosed

Done in !496.

comment:3 Changed 7 months ago by bgamari

Milestone: 8.8.1

comment:4 Changed 6 months ago by simonpj

Differential Rev(s): MR!496
Test Case: typecheck/should_fail/T16394

comment:5 Changed 6 months ago by Ben Gamari <ben@…>

In 10a97120/ghc:

testsuite: Add testcase for #16394
Note: See TracTickets for help on using tickets.