
#14549: RecordWildCards doesn't work properly in repl -------------------------------------+------------------------------------- Reporter: akegalj | Owner: (none) Type: bug | Status: new Priority: lowest | Milestone: Component: GHCi | Version: 8.2.1 Resolution: | Keywords: repl, | recordwildcards Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by AntC): I would expect an error; the question is what error? If you write that code as a program, the compiler doesn't go past the second line: `Multiple declarations of ‘t1’` * The declaration for `Test` puts name `t1` in scope -- as a field selector function. * The `t1 = 2` (tries to) create a different declaration of `t1` ===> fail. In the repl, I guess the `t1 = 2` shadows `Test`'s declaration of `t1`, so you don't get a failure at that point. This works: {{{ data Test = Test { t1 :: Int, t2 :: Int } deriving Show tt = let t1 = 2 in Test { t2 = 2, ..} main = print tt }}} You might also get your code to work if you compiled the declaration for `Test` into a separate module and imported it. (In effect that's what I'm doing with the `let`.) Then `t1` would refer to your local variable, and wouldn't clash with imported `t1`. In an expression using record syntax `Test { t2 = 2, t1 = t1 }`, the lhs `t1` must be a field label, the rhs `t1` must be your local variable. Then `Test { t2 = 2, .. }` should work. In general, the repl is a tool for hacking quick-and-dirty. Don't expect that if it accepts some line of code you have an overall coherent program. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14549#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler