Bad error message under DisambiguateRecordFields
Summary
DisambiguateRecordFields can still give some unexpected errors about (un)ambiguous record fields in the presence of other errors.
Steps to reproduce
Compiling this:
{-# LANGUAGE DisambiguateRecordFields #-}
data A = A { sum :: Int }
data B = B
myA = B { sum = 0 }
Produces the error:
T2.hs:6:11: error:
Ambiguous occurrence ‘sum’
It could refer to
either ‘Prelude.sum’,
imported from ‘Prelude’ at T2.hs:1:1
(and originally defined in ‘Data.Foldable’)
or the field ‘sum’, defined at T2.hs:3:13
|
6 | myA = B { sum = 0 }
| ^^^
Note that this only works for names that are already defined in imported modules. That's why I chose the name sum
.
Expected behavior
I expect to see the error that would happen if you remove the data A
declaration, namely:
T2.hs:6:7: error:
• Constructor ‘B’ does not have field ‘sum’
• In the expression: B {sum = 0}
In an equation for ‘myA’: myA = B {sum = 0}
|
6 | myA = B { sum = 0 }
| ^^^^^^^^^^^^^
Environment
- GHC version used: 8.10.7