Opened 3 years ago

Closed 3 years ago

#5566 closed bug (fixed)

instance decls via TH: dropped methods and stack overflows

Reported by: FSalad Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Test Case: ghci/scripts/T5566
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

{-# LANGUAGE TemplateHaskell #-}

class C a where
    c :: a

$([d| instance C Int where c = 0 |] )

data D = D

$([d| instance C D where c = D |] )

$([d| instance Show D where show _ = "D" |] )

Loading this into GHCI:

/tmp/Foo.hs:6:3:
    Warning: No explicit method nor default method for `c'
    In the instance declaration for `C Int'

/tmp/Foo.hs:10:3:
    Warning: No explicit method nor default method for `c'
    In the instance declaration for `C D'
Ok, modules loaded: Main.
ghci> c :: Int
*** Exception: /tmp/Foo.hs:6:3-35: No instance nor default method for class operation Main.c

ghci> c :: D
*** Exception: stack overflow
ghci> show D
"*** Exception: stack overflow
ghci> 

I also tried putting C and/or D into separate modules, to no effect.

Change History (2)

comment:1 Changed 3 years ago by FSalad

  • Type of failure changed from None/Unknown to Incorrect result at runtime

comment:2 Changed 3 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to ghci/scripts/T5566

Happily this is OK in HEAD; I fixed a related bug recently. I'll add a regression test though.

Simon

Note: See TracTickets for help on using tickets.