Skip to content

Poor error message with DuplicateRecordFields import

Given the following two files:

{-# LANGUAGE DuplicateRecordFields #-}
module X where

data Dog = Dog { name::String }
data Human = Human { name::Int }
{-# LANGUAGE DuplicateRecordFields #-}
module Y where

import X

foo = undefined name

If we try to compile Y.hs twice, we get first:

[1 of 2] Compiling X                ( X.hs, X.o )
[2 of 2] Compiling Y                ( Y.hs, Y.o )

Y.hs:6:17: error:
    Ambiguous occurrence ‘name’
    It could refer to
       either the field ‘name’,
              imported from ‘X’ at Y.hs:4:1-8
              (and originally defined at X.hs:5:22-25)
           or the field ‘name’,
              imported from ‘X’ at Y.hs:4:1-8
              (and originally defined at X.hs:4:18-21)

and then:

[2 of 2] Compiling Y                ( Y.hs, Y.o )

Y.hs:6:17: error:
    Ambiguous occurrence ‘name’
    It could refer to
       either the field ‘name’, imported from ‘X’ at Y.hs:4:1-8
           or the field ‘name’, imported from ‘X’ at Y.hs:4:1-8
  |
6 | foo = undefined name
  |                 ^^^^

The second error apparently refers to the same thing twice.

Proposed solution: change the error to:

       either the field ‘name’ of record `Dog`, imported from ‘X’ at Y.hs:4:1-8
           or the field ‘name’ of record `Human`, imported from ‘X’ at Y.hs:4:1-8
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information