Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#6001 closed bug (fixed)

Wrong diagnostics for instance signature mismatch

Reported by: heisenbug Owned by: pcapriotti
Priority: normal Milestone: 7.6.1
Component: Compiler Version: 7.5
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Difficulty: Unknown
Test Case: typecheck/should_fail/T6001 Blocked By:
Blocking: Related Tickets:

Description

Consider:


{-# LANGUAGE InstanceSigs?, DataKinds?, KindSignatures?, GADTs #-}

data DayKind? = Work | Rest

data Day :: DayKind? -> * where

Mon
Day Work
Sat
Day Rest

instance Num (Day c) where

fromInteger
Int -> Day p fromInteger 1 = Mon fromInteger 6 = Sat


I get

$ ~/bin/ghci NumGADT.hs
GHCi, version 7.5.20120410: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( NumGADT.hs, interpreted )

NumGADT.hs:10:18:

Method signature does not match class; it should be

fromInteger
forall (p :: DayKind?). Int -> Day p In the instance declaration for `Num (Day c)'

Failed, modules loaded: none.
Prelude>

It appears to me that instead of telling me the expected signature
GHCi simply echoes what I have provided. This is not really useful ;-)

Attachments (1)

NumGADT.hs (262 bytes) - added by heisenbug 2 years ago.
Attaching source snippet for better repro experience

Download all attachments as: .zip

Change History (8)

Changed 2 years ago by heisenbug

Attaching source snippet for better repro experience

comment:1 Changed 2 years ago by pcapriotti

  • Difficulty set to Unknown
  • Owner set to pcapriotti

Thanks for the report.

It's a simple typo in the type checker.

comment:2 Changed 2 years ago by pcapriotti

  • Milestone set to 7.6.1

comment:3 Changed 2 years ago by heisenbug

Yeah, fix is here (for the mixup in the diagnostics)

http://www.haskell.org/pipermail/cvs-ghc/2012-April/072117.html

But when I change the signature to read

instance Num (Day c) where
  fromInteger :: Integer -> Day p
  fromInteger 1 = Mon
  fromInteger 6 = Sat


I still get

NumGADT.hs:10:18:

Method signature does not match class; it should be

fromInteger
Integer -> Day c In the instance declaration for `Num (Day c)'

Is this another bug down the rabbit hole?

comment:4 Changed 2 years ago by heisenbug

Correction to my last woe...

My instance declaration should read

instance Num (Day c) where
  fromInteger :: Integer -> Day c
  fromInteger 1 = Mon
  fromInteger 6 = Sat

because of scoped type variables. Then everything seems to pan out.

comment:5 Changed 2 years ago by p.capriotti@…

commit 148b27b679d351dea967638f27d09325cc74422b

Author: Paolo Capriotti <p.capriotti@gmail.com>
Date:   Thu Apr 12 10:44:31 2012 +0100

    Fix instance signature error message (#6001)
    
    Display class method signature instead of user-provided signature.

 compiler/typecheck/TcInstDcls.lhs |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

comment:6 Changed 2 years ago by pcapriotti

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to typecheck/should_fail/T6001

Added simplified test case (no need for GADTs or DataKinds?).

Thanks.

comment:7 Changed 2 years ago by simonpj

Indeed. The new error message is absolutely right:

NumGADT.hs:10:18:
    Method signature does not match class; it should be
    fromInteger :: Integer -> Day c 
    In the instance declaration for `Num (Day c)' 

So with the above patch (thanks Paolo) all is good.

Note: See TracTickets for help on using tickets.