Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#5689 closed bug (fixed)

The 'impossible' happened: type-inference succeeds somehow in code which isn't type-safe

Reported by: nicolast Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.0.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: typecheck/should_fail/T5689
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

While trying to figure out how Haskell handles OCaml's value restriction, I created some code which I thought shouldn't type-check.

It did, though, and makes GHCi panic on execution, or makes GHC fail during compilation.

Minor changes to the code makes it no longer type-check, as expected.

Here's the code, including some comments which show when compilation does fail as expected:

{-# LANGUAGE ScopedTypeVariables #-}

import Data.IORef

main :: IO ()
main = do
    (r :: IORef (t -> t)) <- newIORef id
    -- r <- newIORef i -- => Type-check error

    writeIORef r (\v -> if v then False else True)

    c <- readIORef r

    print $ c True

    print $ c 1234

    -- print $ c Nothing -- => Type-check error
    -- print $ c (1 :: Int) -- => Type-check error

When replacing the "print $ c 1234" line with one of the last 2 lines, type-checking fails.
When removing the explicit type-annotation on 'r', type-checking fails when "print $ c 1234" is left in place.

Here's the GHCi and GHC output:

Prelude> :load demo1.hs
[1 of 1] Compiling Main             ( demo1.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
ghc: panic! (the 'impossible' happened)
  (GHC version 7.0.4 for x86_64-unknown-linux):
	nameModule $dNum{v ann}

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
$ ghc --make demo1.hs
[1 of 1] Compiling Main             ( demo1.hs, demo1.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 7.0.4 for x86_64-unknown-linux):
	initC: srt_lbl

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Change History (2)

comment:1 Changed 3 years ago by michalt

  • Resolution set to fixed
  • Status changed from new to closed

Thanks for reporting! This seems to be fixed in 7.2.2:

[1 of 1] Compiling Main             ( Test.hs, Test.o )

Test.hs:14:15:
    Couldn't match type `t' with `Bool'
    In the first argument of `c', namely `True'
    In the second argument of `($)', namely `c True'
    In a stmt of a 'do' block: print $ c True

and in HEAD:

[1 of 1] Compiling Main             ( Test.hs, Test.o )

Test.hs:10:28:
    Couldn't match type `t' with `Bool'
    In the expression: v
    In the expression: if v then False else True
    In the second argument of `writeIORef', namely
      `(\ v -> if v then False else True)'

I don't think there'll be any more 7.0.x releases, so I'm closing.

comment:2 Changed 3 years ago by simonpj

  • difficulty set to Unknown
  • Test Case set to typecheck/should_fail/T5689
Note: See TracTickets for help on using tickets.