Oleg Grenrus pushed to branch wip/T26295 at Glasgow Haskell Compiler / GHC
Commits:
-
a05f102c
by Oleg Grenrus at 2025-08-11T09:22:39+00:00
2 changed files:
Changes:
... | ... | @@ -1723,8 +1723,11 @@ checkHasFieldInst cls tys@[_k_ty, _r_rep, _a_rep, lbl_ty, r_ty, _a_ty] = |
1723 | 1723 | | let lbl_str = FieldLabelString lbl
|
1724 | 1724 | , Just fl <- lookupTyConFieldLabel lbl_str tc
|
1725 | 1725 | -> do
|
1726 | - -- this logic vaguely mirrors 'matchHasField',
|
|
1727 | - -- generally we should allow to define HasField instances which GHC will not solve for.
|
|
1726 | + -- GHC does not provide HasField instances for naughty record selectors
|
|
1727 | + -- (see Note [Naughty record selectors] in GHC.Tc.TyCl.Utils),
|
|
1728 | + -- so don't prevent the user from writing such instances.
|
|
1729 | + -- See GHC.Tc.Instance.Class.matchHasField.
|
|
1730 | + -- Test case: T26295.
|
|
1728 | 1731 | sel_id <- tcLookupId $ flSelector fl
|
1729 | 1732 | if isNaughtyRecordSelector sel_id
|
1730 | 1733 | then return ()
|
... | ... | @@ -12,7 +12,7 @@ data R = forall a b. (a ~ Int, b ~ Char) => MkR |
12 | 12 | , field_b :: b
|
13 | 13 | }
|
14 | 14 | |
15 | --- fields in R are naught, so we can define own HasField instances for them.
|
|
15 | +-- fields in R are naughty, so we can define custom HasField instancs for them
|
|
16 | 16 | instance a ~ Int => HasField "field_a" R a where
|
17 | 17 | getField (MkR a _) = a
|
18 | 18 |