Opened 9 months ago

Last modified 5 months ago

#13352 new bug

Strange requirement for re-exported duplicate record fields

Reported by: crockeea Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.2
Keywords: orf Cc: adamgundry
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

In the following example,

module A(A(..)) where
data A = A {x::Int}

module B(B(..)) where
data B = B {x::Bool}

{-# LANGUAGE DuplicateRecordFields #-}
module C(A(..),B(..)) where
import A(A(..))
import B(B(..))

I get an error about conflicting exports for 'x'. This doesn't seem right to me: I've got -XDuplicateRecordFields exactly where the duplicate occurs.

However, I noticed that the if I move the pragma to A.hs, C.hs compiles without error:

{-# LANGUAGE DuplicateRecordFields #-}
module A(A(..)) where
data A = A {x::Int}

module B(B(..)) where
data B = B {x::Bool}

module C(A(..),B(..)) where
import A(A(..))
import B(B(..))

This is bizarre because it is asymmetric (I arbitrarily put the pragma in A.hs, but it need not occur in B.hs), and because no duplicate records exist in module A, but they do exist in module C, where the pragma isn't needed.

Change History (3)

comment:1 Changed 9 months ago by ezyang

Cc: adamagundry added

CC'ing adamgundry.

comment:2 Changed 6 months ago by adamgundry

Cc: adamgundry added; adamagundry removed
Keywords: orf added

comment:3 Changed 5 months ago by adamgundry

Sorry, I've only just seen this as ezyang's CC missed. :(

This is an awkward corner of the DuplicateRecordFields implementation: as you've observed, the extension needs to be enabled at the definition site of (all but one of) a set of record fields in order for them to be re-exported by a single module. In principle it would be possible to fix this by changing the implementation to mangle selector names regardless of whether the extension is enabled. However, I suspect this would be a nontrivial amount of work relative to the benefit.

Note: See TracTickets for help on using tickets.