Ticket #1813 (closed merge: fixed)

Opened 6 years ago

Last modified 5 years ago

Strange type representation bug with phantom type synonyms in interactive mode

Reported by: guest Owned by: igloo
Priority: normal Milestone: 6.10 branch
Component: GHCi Version: 6.9
Keywords: Cc: alfonso.acosta@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: tcfail186 Blocked By:
Blocking: Related Tickets:

Description

Sorry for the confusing summary

The following module defines a phatom type synonym and a simple function

module Phantom where

type PhantomSyn a  = Int

f = (\_ -> 2) :: PhantomSyn a -> Int

When running in interactive mode (the bug doesn't seem to be reproducible otherwise) the typechecker gives a strange error

./ghc-inplace  --interactive /tmp/Phantom.hs
GHCi, version 6.9.20071025: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Phantom          ( /tmp/Phantom.hs, interpreted )
Ok, modules loaded: Phantom.
*Phantom> f "incorrectParam"

<interactive>:1:2:
    Couldn't match expected type `PhantomSyn GHC.Prim.Any'
           against inferred type `[Char]'
      Expected type: PhantomSyn GHC.Prim.Any
      Inferred type: [Char]
    In the first argument of `f', namely `"incorrectParam"'
    In the expression: f "incorrectParam"

The typechecker should output

Expected type: PhantomSyn a

If I skip the interactive mode (including the erroneous declaration in the Phantom.hs itself) or I define f as

f :: PhantomSyn a -> Int
f = (\_ -> 2)

The incorrect error report disappears.

Change History

Changed 6 years ago by guest

I think it is an internal representation bug, because Template Haskell also returns an incorrect reification

./ghc-inplace  -fth --interactive /tmp/Phantom.hs
GHCi, version 6.9.20071025: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Phantom          ( /tmp/Phantom.hs, interpreted )
Ok, modules loaded: Phantom.
*Phantom> :m +Language.Haskell.TH
*Phantom Language.Haskell.TH> $(do {i <- reify (mkName "f"); runIO $ putStrLn (pprint i);[| 1 |]})
Loading package array-0.1 ... linking ... done.
Loading package packedstring-0.1 ... linking ... done.
Loading package pretty-1.0 ... linking ... done.
Loading package containers-0.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
Phantom.f :: Phantom.PhantomSyn GHC.Prim.Any -> GHC.Base.Int
Phantom.f :: Phantom.PhantomSyn GHC.Prim.Any -> GHC.Base.Int
Phantom.f :: Phantom.PhantomSyn GHC.Prim.Any -> GHC.Base.Int
Phantom.f :: Phantom.PhantomSyn GHC.Prim.Any -> GHC.Base.Int
1

Changed 6 years ago by guest

  • cc alfonso.acosta@… added

Changed 6 years ago by igloo

  • milestone set to 6.10 branch

Thanks for the report. 6.8.1 seems to work correctly, so I'm milestoning this for 6.10.

Changed 6 years ago by simonpj

  • owner set to simonpj

I'm fixing this (it's easy).

S

Changed 6 years ago by simonpj

  • owner changed from simonpj to igloo
  • testcase set to tcfail186
  • type changed from bug to merge

Done. Patch is

Tue Nov  6 15:31:51 GMT 2007  simonpj@microsoft.com
  * Fix Trac #1813: generalise over *all* type variables at top level, even phantom ones

and it should merge fine onto the 6.8 branch

Simon

Changed 6 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Merged

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.