[GHC] #13838: -Wdeferred-type-errors; ghc: panic!; VoidRep; ((() -> ()) :: *) ~# (IO Any :: *)

#13838: -Wdeferred-type-errors; ghc: panic!; VoidRep; ((() -> ()) :: *) ~# (IO Any :: *) -------------------------------------+------------------------------------- Reporter: harry | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Compile-time Unknown/Multiple | crash or panic Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- My Compiler told me to report this so here you go: {{{ [1 of 1] Compiling Main ( ghc_bug.hs, interpreted ) ghc_bug.hs:3:1: warning: [-Wdeferred-type-errors] * Couldn't match expected type `IO t0' with actual type `() -> ()' * Probable cause: `main' is applied to too few arguments In the expression: main When checking the type of the IO action `main' ghc_bug.hs:3:8: warning: [-Wdeferred-type-errors] * Couldn't match expected type `() -> () -> ()' with actual type `()' * The function `()' is applied to one argument, but its type `()' has none In the expression: () () In an equation for `main': main = () () ghc: panic! (the 'impossible' happened) (GHC version 8.0.1 for x86_64-unknown-linux): corePrepPgm [False] cobox_r1a0 = typeError @ 'VoidRep @ ((() -> ()) :: *) ~# (IO Any :: *) "ghc_bug.hs:3:1: error:\n\ \ * Couldn't match expected type `IO t0' with actual type `() -> ()'\n\ \ * Probable cause: `main' is applied to too few arguments\n\ \ In the expression: main\n\ \ When checking the type of the IO action `main'\n\ \(deferred type error)"# Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} {{{#!hs main :: () -> () main = () () }}} which that in "ghc_bug.hs" "ghc ghc_bug.hs -fdefer-type-errors -dcore-lint -v" gives me the following: {{{ Glasgow Haskell Compiler, Version 8.0.1, stage 2 booted by GHC version 7.10.3 Using binary package database: /usr/lib/ghc-8.0.1/package.conf.d/package.cache Using binary package database: /home/harry/.ghc/x86_64-linux-8.0.1/package.conf.d/package.cache loading package database /usr/lib/ghc-8.0.1/package.conf.d loading package database /home/harry/.ghc/x86_64-linux-8.0.1/package.conf.d wired-in package ghc-prim mapped to ghc-prim-0.5.0.0 wired-in package integer-gmp mapped to integer-gmp-1.0.0.1 wired-in package base mapped to base-4.9.0.0 wired-in package rts mapped to rts wired-in package template-haskell mapped to template-haskell-2.11.0.0 wired-in package ghc mapped to ghc-8.0.1 wired-in package dph-seq not found. wired-in package dph-par not found. Hsc static flags: loading package database /usr/lib/ghc-8.0.1/package.conf.d loading package database /home/harry/.ghc/x86_64-linux-8.0.1/package.conf.d wired-in package ghc-prim mapped to ghc-prim-0.5.0.0 wired-in package integer-gmp mapped to integer-gmp-1.0.0.1 wired-in package base mapped to base-4.9.0.0 wired-in package rts mapped to rts-1.0 wired-in package template-haskell mapped to template-haskell-2.11.0.0 wired-in package ghc mapped to ghc-8.0.1 wired-in package dph-seq not found. wired-in package dph-par not found. *** Chasing dependencies: Chasing modules from: *ghc_bug.hs !!! Chasing dependencies: finished in 0.42 milliseconds, allocated 0.211 megabytes Stable obj: [] Stable BCO: [] Ready for upsweep [NONREC ModSummary { ms_hs_date = ****-**-** **:**:**.********** *** ms_mod = Main, ms_textual_imps = [(Nothing, Prelude)] ms_srcimps = [] }] *** Deleting temp files: Deleting: compile: input file ghc_bug.hs *** Checking old interface for Main: [1 of 1] Compiling Main ( ghc_bug.hs, ghc_bug.o ) *** Parser [Main]: !!! Parser [Main]: finished in 0.14 milliseconds, allocated 0.089 megabytes *** Renamer/typechecker [Main]: !!! Renamer/typechecker [Main]: finished in 28.70 milliseconds, allocated 14.769 megabytes *** Desugar [Main]: Result size of Desugar (after optimization) = {terms: 19, types: 52, coercions: 4} *** Core Linted result of Desugar (after optimization): *** Core Lint errors : in result of Desugar (after optimization) *** <no location info>: warning: [RHS of cobox_aOD :: ((() -> ()) :: *) ~# (IO Any :: *)] The type of this binder is primitive: cobox_aOD Binder's type: ((() -> ()) :: *) ~# (IO Any :: *) *** Offending Program *** main :: () -> () [LclIdX, Str=DmdType] main = case typeError @ 'VoidRep @ (() :: *) ~# ((() -> () -> ()) :: *) "ghc_bug.hs:2:8: error:\n\ \ * Couldn't match expected type `() -> () -> ()'\n\ \ with actual type `()'\n\ \ * The function `()' is applied to one argument,\n\ \ but its type `()' has none\n\ \ In the expression: () ()\n\ \ In an equation for `main': main = () ()\n\ \(deferred type error)"# of cobox_aOE { __DEFAULT -> (() `cast` (Sub cobox_aOE :: (() :: *) ~R# ((() -> () -> ()) :: *))) () } $trModule :: Module [LclIdX, Str=DmdType] $trModule = Module (TrNameS "main"#) (TrNameS "Main"#) cobox_aOD :: ((() -> ()) :: *) ~# (IO Any :: *) [LclId[CoVarId], Str=DmdType] cobox_aOD = typeError @ 'VoidRep @ ((() -> ()) :: *) ~# (IO Any :: *) "ghc_bug.hs:2:1: error:\n\ \ * Couldn't match expected type `IO t0' with actual type `() -> ()'\n\ \ * Probable cause: `main' is applied to too few arguments\n\ \ In the expression: main\n\ \ When checking the type of the IO action `main'\n\ \(deferred type error)"# main :: IO Any [LclIdX, Str=DmdType] main = runMainIO @ Any (main `cast` (Sub cobox_aOD :: ((() -> ()) :: *) ~R# (IO Any :: *))) *** End of Offense *** <no location info>: error: Compilation had errors *** Deleting temp files: Deleting: *** Deleting temp dirs: Deleting: }}} and gcc version is: gcc version 7.1.1 20170516 (GCC) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13838 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13838: -Wdeferred-type-errors; ghc: panic!; VoidRep; ((() -> ()) :: *) ~# (IO Any :: *) -------------------------------------+------------------------------------- Reporter: harry | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Thanks for the bug report. Interestingly, this program no longer panics with just `-fdefer-type- errors` on GHC 8.2.1 or HEAD: {{{ $ /opt/ghc/8.2.1/bin/ghc Bug.hs -fdefer-type-errors [1 of 1] Compiling Main ( Bug.hs, Bug.o ) Bug.hs:2:1: warning: [-Wdeferred-type-errors] • Couldn't match expected type ‘IO t0’ with actual type ‘() -> ()’ • Probable cause: ‘main’ is applied to too few arguments In the expression: main When checking the type of the IO action ‘main’ | 2 | main = () () | ^ Bug.hs:2:8: warning: [-Wdeferred-type-errors] • Couldn't match expected type ‘() -> () -> ()’ with actual type ‘()’ • The function ‘()’ is applied to one argument, but its type ‘()’ has none In the expression: () () In an equation for ‘main’: main = () () | 2 | main = () () | ^^^^^ Linking Bug ... }}} (It also appears to be `-dcore-lint`-safe.) However, the output isn't exactly what I'd expect from a type-incorrect program that was compiled with `-fdefer-type-errors`: {{{ $ ./Bug Bug: main thread exited (uncaught exception) }}} I would have expected something like this: {{{ $ ./Bug Bug: Bug.hs:2:1: error: • Couldn't match expected type ‘IO t0’ with actual type ‘() -> ()’ • Probable cause: ‘main’ is applied to too few arguments In the expression: main When checking the type of the IO action ‘main’ Bug: Bug.hs:2:8: error: • Couldn't match expected type ‘() -> () -> ()’ with actual type ‘()’ • The function ‘()’ is applied to one argument, but its type ‘()’ has none In the expression: () () In an equation for ‘main’: main = () () }}} I'll investigate which commit fixed the panic. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13838#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13838: -Wdeferred-type-errors; ghc: panic!; VoidRep; ((() -> ()) :: *) ~# (IO Any :: *) -------------------------------------+------------------------------------- Reporter: harry | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13292 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #13292 Comment: Ah, this was fixed in 3c62b1d6b672e7727ea5fa56c69bf43e43d0fd8f (Gather constraints locally in checkMain), the fix for #13292. However, the test program from that commit also suffers from the strange output observed in comment:1. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13838#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13838: -Wdeferred-type-errors; ghc: panic!; VoidRep; ((() -> ()) :: *) ~# (IO Any :: *) -------------------------------------+------------------------------------- Reporter: harry | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13292 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by harry): Although my distro ships version 8.0.2 now I still get a "ghc: panic! (the 'impossible' happened)" with this slightly more complex code but within ghci only: With "ghci -fdefer-type-errors" and this code: {{{#!hs bad1 :: [()] bad1 = num bad2 :: () bad2 = num num = 9 }}} the output: {{{ GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help Prelude> :l ghc_bug_2.hs [1 of 1] Compiling Main ( ghc_bug_2.hs, interpreted ) ghc_bug_2.hs:2:8: warning: [-Wdeferred-type-errors] * Couldn't match expected type `[()]' with actual type `()' * In the expression: num In an equation for `bad1': bad1 = num ghc: panic! (the 'impossible' happened) (GHC version 8.0.2 for x86_64-unknown-linux): corePrepPgm [False] cobox_r196 = typeError @ 'VoidRep @ (() :: *) ~# ([()] :: *) "ghc_bug_2.hs:2:8: error:\n\ \ * Couldn't match expected type `[()]' with actual type `()'\n\ \ * In the expression: num\n\ \ In an equation for `bad1': bad1 = num\n\ \(deferred type error)"# Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
}}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13838#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13838: -Wdeferred-type-errors on a program with main not of type IO () yields "main thread exited (uncaught exception)" -------------------------------------+------------------------------------- Reporter: harry | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13292 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Correct, that is entirely expected. To be clear: the GHC panic/Core Lint error bug exists in GHC 8.0.2, but not 8.2. However, a bug persists in GHC 8.2 where actually running the code yields `main thread exited (uncaught exception)`, which shouldn't happen. I'll update the title accordingly. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13838#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13838: -Wdeferred-type-errors on a program with main not of type IO () yields "main thread exited (uncaught exception)" -------------------------------------+------------------------------------- Reporter: harry | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13292 | Differential Rev(s): Phab:D4708 Wiki Page: | -------------------------------------+------------------------------------- Changes (by sighingnow): * status: new => patch * differential: => Phab:D4708 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13838#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13838: -Wdeferred-type-errors on a program with main not of type IO () yields
"main thread exited (uncaught exception)"
-------------------------------------+-------------------------------------
Reporter: harry | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time | Unknown/Multiple
crash or panic | Test Case:
Blocked By: | Blocking:
Related Tickets: #13292 | Differential Rev(s): Phab:D4708
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13838: -Wdeferred-type-errors on a program with main not of type IO () yields "main thread exited (uncaught exception)" -------------------------------------+------------------------------------- Reporter: harry | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: T13838 Blocked By: | Blocking: Related Tickets: #13292 | Differential Rev(s): Phab:D4708 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * testcase: => T13838 * status: patch => closed * resolution: => fixed * milestone: => 8.6.1 Comment: I believe this should now be fixed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13838#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC