GHC calls an unambiguous record update ambiguous
Inspired by https://github.com/haskell/error-messages/issues/57
Here is the example:
data R = MkR1 { foo :: Int }
| MkR2 { bar :: Int }
data S = MkS { foo :: Int, bar :: Int }
blah x = x { foo = 5, bar = 6 }
GHC says
Scratch.hs:37:10: error:
* Record update is ambiguous, and requires a type signature
* In the expression: x {foo = 5, bar = 6}
In an equation for `blah': blah x = x {foo = 5, bar = 6}
|
37 | blah x = x { foo = 5, bar = 6 }
| ^^^^^^^^^^^^^^^^^^^^^^
But it's not ambiguous. GHC rightly rejects that record-update if I write blah :: R -> R
as a type signature, because foo
and bar
are in different constructors. In the record-update ambiguity check, GHC should take constructor choice into account.