Opened 16 months ago

Closed 16 months ago

Last modified 16 months ago

#12097 closed bug (invalid)

DuplicateRecordFields appears not to work in GHCi

Reported by: bgamari Owned by:
Priority: normal Milestone: 8.0.2
Component: Compiler (Type checker) Version: 8.0.1
Keywords: ORF Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

This was noticed shortly after the 8.0.1 announcement,

$ ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/ben/.ghci
λ> :set -XDuplicateRecordFields 
λ> data A = A {test :: String}
λ> data B = B {test :: Int}
λ> print $ test (A 42)

<interactive>:4:9: error:
    Ambiguous occurrence ‘test’
    It could refer to either the field ‘test’,
                             defined at <interactive>:2:13
                          or the field ‘test’, defined at <interactive>:3:13

The equivalent program compiled as a module works as expected,

{-# LANGUAGE DuplicateRecordFields #-}

module Hi where
data A = A { test :: Int }    deriving Show
data B = B { test :: String } deriving Show

x :: A
x = A 42

main = do
    print x
    print (A 42)
$ runghc Hi.hs
A {test = 42}
A {test = 42}

Change History (3)

comment:1 Changed 16 months ago by bgamari

Summary: DuplicateRecordFields appears not to work inDuplicateRecordFields appears not to work in GHCi

comment:2 Changed 16 months ago by bgamari

Resolution: invalid
Status: newclosed

Never mind; in my haste I completed butchered the example. If one adds a test in the expressions being printed above typechecking fails in when compiled as a module as well.

This is likely due to the typechecking limitations of DuplicateRecordFields, although I don't know for certain.

comment:3 Changed 16 months ago by adamgundry

Keywords: ORF added

This is indeed expected behaviour. See #11343.

Note: See TracTickets for help on using tickets.