Typed holes should take record wildcards into account
Summary
When using record wildcards together with typed holes, you don't get very useful information.
This is especially painful if you are using record wildcards as a workaround for #12376 (as suggested in comment #12376 (comment 125684)). And also if you are using typed holes in combination with tools like wingman which gives typed holes superpowers.
Steps to reproduce
{-# LANGUAGE RecordWildCards #-}
data Foo = Foo {foo :: Int}
test :: Foo
test = Foo {..}
where
foo = _
Gives the suggestion:
T.hs:8:11: error:
• Found hole: _ :: p
Where: ‘p’ is a rigid type variable bound by
the inferred type of foo :: p
at T.hs:8:5-11
• In an equation for ‘foo’: foo = _
In an equation for ‘test’:
test
= Foo {..}
where
foo = _
• Relevant bindings include
foo :: p (bound at T.hs:8:5)
test :: Foo (bound at T.hs:6:1)
|
8 | foo = _
| ^
Expected behavior
GHC should say that the type of the hole must be Int
because that is the type of the foo
field. The typed holes should be consistent with the type error you get when you use a wrong type, e.g.:
{-# LANGUAGE RecordWildCards #-}
data Foo = Foo {foo :: Int}
test :: Foo
test = Foo {..}
where
foo = ()
Gives the error:
T.hs:6:13: error:
• Couldn't match expected type ‘Int’ with actual type ‘()’
• In the ‘foo’ field of a record
In the expression: Foo {..}
In an equation for ‘test’:
test
= Foo {..}
where
foo = ()
|
6 | test = Foo {..}
| ^^
So GHC does know that foo :: Int
should hold.
Environment
- GHC version used: 9.2.4