Ticket #3621 (closed bug: fixed)

Opened 4 years ago

Last modified 4 years ago

"No match in record selector Var.tcTyVarDetails" with incorrect multi-parameter newtype derivation

Reported by: pwb Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.10.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: deriving/should_fail/T3621 Blocked By:
Blocking: Related Tickets:

Description

{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Monad.State
newtype WrappedState s a = WS { runWS :: State s a }
    deriving (Monad, MonadState state)

Note that the 'deriving' for MonadState has the wrong variable name. It should be rejected with something like "not in scope: type variable 'state'" but instead this happens:

[pwb@rhuidean tmp]$ ghc bug.hs 
ghc: panic! (the 'impossible' happened)
  (GHC version 6.10.4 for x86_64-unknown-linux):
	No match in record selector Var.tcTyVarDetails

Change History

Changed 4 years ago by simonpj

  • status changed from new to closed
  • difficulty set to Unknown
  • resolution set to fixed
  • testcase set to deriving/should_fail/T3621

Actually it shouldn't be rejected. For example

class C a b 
data S = MkS
instance C a S
newtype T = MkT S deriving( C a )

Here, the derived instance declaration looks like

instance C a T 

which is fine, although 'a' is not a parameter of T.

However the compiler should not crash. And, happily, here's what the HEAD says (and hence 6.12):

T3621.hs:11:21:
    Couldn't match expected type `state' against inferred type `s'
      `state' is a rigid type variable bound by
              the instance declaration at T3621.hs:11:32
      `s' is a rigid type variable bound by
          the instance declaration at T3621.hs:10:21
    When using functional dependencies to combine
      MonadState s (State s),
        arising from the dependency `m -> s'
        in the instance declaration at T3621.hs:8:9
      MonadState state (State s),
        arising from the instance declaration at T3621.hs:11:21-36
    When checking the super-classes of an instance declaration
    In the instance declaration for `MonadState state (WrappedState s)'

Which seems plausible.

I'll add your program to our regression tests though.

Simon

Note: See TracTickets for help on using tickets.