[GHC] #13870: Empty record construction for record-less constructor gives surprising runtime error (and surprisingly few warnings)

#13870: Empty record construction for record-less constructor gives surprising runtime error (and surprisingly few warnings) -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: newcomer | Operating System: Unknown/Multiple Architecture: | Type of failure: Poor/confusing Unknown/Multiple | error message Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The crux of this ticket is this sort of code: {{{#!hs module Main where f :: Maybe Int f = Just{} main :: IO () main = print f }}} {{{ $ runghc --ghc-arg=-Wall Bug.hs Just Bug.hs: Bug.hs:4:5-10: Missing field in record construction }}} Yikes. There are a couple of very surprising things happening here. First, the message `Missing field in record construction` is very misleading. After all, `Just` has no records! We really should give a more specific error which highlights this fact. (The fact that you can even use record construction syntax with a record- less constructor in the first place is a bit baffling, but the [https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-520003.1... language standard does allow it], so I suppose we have to live with this.) The second surprising bit is the fact that is program compiled with no warnings whatsoever. This is in contrast to, say, the `Identity` datatype, which has a record (`runIdentity`): {{{#!hs module Main where import Data.Functor.Identity f :: Identity Int f = Identity{} main :: IO () main = print f }}} {{{ $ runghc --ghc-arg=-Wall Bug.hs Bug.hs:6:5: warning: [-Wmissing-fields] • Fields of ‘Identity’ not initialised: runIdentity • In the expression: Identity {} In an equation for ‘f’: f = Identity {} Identity Bug.hs: Bug.hs:6:5-14: Missing field in record construction runIdentity }}} Here, GHC warned me that I was doing something stupid. GHC ought to be warning me with equivalent fervor when I use `Just{}`. The warning would obviously have to be tweaked a bit, since warning that `Fields of ‘Just’ not initialised` doesn't make any sense, but you get the idea. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13870 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13870: Empty record construction for record-less constructor gives surprising runtime error (and surprisingly few warnings) -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: sighingnow Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3940 Wiki Page: | -------------------------------------+------------------------------------- Changes (by sighingnow): * owner: (none) => sighingnow * differential: => Phab:D3940 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13870#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13870: Empty record construction for record-less constructor gives surprising runtime error (and surprisingly few warnings) -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: sighingnow Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Poor/confusing | Test Case: error message | deSugar/should_compile/T13870 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3940 Wiki Page: | -------------------------------------+------------------------------------- Changes (by sighingnow): * testcase: => deSugar/should_compile/T13870 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13870#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13870: Empty record construction for record-less constructor gives surprising
runtime error (and surprisingly few warnings)
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: sighingnow
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Poor/confusing | Test Case:
error message | deSugar/should_compile/T13870
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3940
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13870: Empty record construction for record-less constructor gives surprising runtime error (and surprisingly few warnings) -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: sighingnow Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Poor/confusing | Test Case: error message | deSugar/should_compile/T13870 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3940 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed * milestone: => 8.4.1 Comment: Given that this isn't a regression in 8.2 I think we'll wait until 8.4 to release this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13870#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC