[GHC] #14783: Initializing record with similarly named field from a different record results in warning rather than error

#14783: Initializing record with similarly named field from a different record results in warning rather than error -------------------------------------+------------------------------------- Reporter: | Owner: (none) ulrikrasmussen | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: records | Operating System: Unknown/Multiple DuplicateRecordFields | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- When a record is initialized using a similarly named field from another record, the compiler ignores the initialization and generates a warning instead of throwing an error. I believe this is a bug introduced in GHC 8.0.1 (and probably related to `DuplicateRecordFields`), since earlier versions of GHC would refuse to compile the code. Consider the following example: {{{ -- A.hs module A where data A = A { a :: (), b :: () } -- B.hs module B where data B = B { a :: (), b :: () } -- Main.hs module Main where import A hiding (a) import B x = A { a = (), b = () } main = case x of A () () -> return () }}} On GHC 8.0.1, this compiles (with a warning), and the program throws an exception when run: {{{ $ stack ghc --compiler ghc-8.0.1 -- --make Main.hs [1 of 3] Compiling B ( B.hs, B.o ) [2 of 3] Compiling A ( A.hs, A.o ) [3 of 3] Compiling Main ( Main.hs, Main.o ) Main.hs:5:7: warning: [-Wmissing-fields] • Fields of ‘A’ not initialised: a • In the expression: A {a = (), b = ()} In an equation for ‘x’: x = A {a = (), b = ()} Linking Main ... $ ./Main Main: Main.hs:5:7-26: Missing field in record construction a }}} On GHC 7.10.3, the program will not compile: {{{ $ stack ghc --compiler ghc-7.10.3 -- --make Main.hs [1 of 3] Compiling B ( B.hs, B.o ) [2 of 3] Compiling A ( A.hs, A.o ) [3 of 3] Compiling Main ( Main.hs, Main.o ) Main.hs:5:7: Constructor ‘A’ does not have field ‘a’ In the expression: A {a = (), b = ()} In an equation for ‘x’: x = A {a = (), b = ()} }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14783 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14783: Initializing record with similarly named field from a different record results in warning rather than error -------------------------------------+------------------------------------- Reporter: ulrikrasmussen | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: records | DuplicateRecordFields Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ulrikrasmussen): * Attachment "A.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14783 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14783: Initializing record with similarly named field from a different record results in warning rather than error -------------------------------------+------------------------------------- Reporter: ulrikrasmussen | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: records | DuplicateRecordFields Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ulrikrasmussen): * Attachment "B.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14783 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14783: Initializing record with similarly named field from a different record results in warning rather than error -------------------------------------+------------------------------------- Reporter: ulrikrasmussen | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: records | DuplicateRecordFields Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ulrikrasmussen): * Attachment "Main.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14783 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14783: Initializing record with similarly named field from a different record results in warning rather than error -------------------------------------+------------------------------------- Reporter: ulrikrasmussen | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: records | DuplicateRecordFields ORF Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: records DuplicateRecordFields => records DuplicateRecordFields ORF -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14783#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14783: Initializing record with similarly named field from a different record results in warning rather than error -------------------------------------+------------------------------------- Reporter: ulrikrasmussen | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: records | DuplicateRecordFields ORF Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by adamgundry): * cc: adamgundry (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14783#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14783: Initializing record with similarly named field from a different record results in warning rather than error -------------------------------------+------------------------------------- Reporter: ulrikrasmussen | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.3 Component: Compiler | Version: 8.0.1 Resolution: duplicate | Keywords: records | DuplicateRecordFields ORF Operating System: Unknown/Multiple | Architecture: Type of failure: GHC accepts | Unknown/Multiple invalid program | Test Case: Blocked By: | Blocking: Related Tickets: #13847 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by adamgundry): * status: new => closed * failure: None/Unknown => GHC accepts invalid program * resolution: => duplicate * related: => #13847 * milestone: => 8.2.3 Comment: Thanks for the report! This bug exists in 8.0.x and 8.2.x but is fixed in the 8.4.x series. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14783#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC