Opened 22 months ago

Last modified 11 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 (4)

comment:1 Changed 22 months ago by ezyang

Cc: adamagundry added

CC'ing adamgundry.

comment:2 Changed 18 months ago by adamgundry

Cc: adamgundry added; adamagundry removed
Keywords: orf added

comment:3 Changed 18 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.

comment:4 Changed 11 months ago by tejon

I've just run into this as well, with the additional observation that if module C re-exports modules A and B, then C must also have DuplicateRecordFields. (Of course, C needing it is the immediate intuition anyway; but it's not always true that it's only needed at (n-1 of) the definition points.

This is just a slightly annoying curiosity when one controls all the relevant modules, but it seems like it shuts down the extension completely if one is working with external modules that don't have DuplicateRecordFields enabled (because why should they, internally there are none).

Note: See TracTickets for help on using tickets.