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
Apply 2 suggestion(s) to 2 file(s)
Co-authored-by: sheaf
- - - - -
2 changed files:
- compiler/GHC/Tc/Validity.hs
- testsuite/tests/overloadedrecflds/should_run/T26295.hs
Changes:
=====================================
compiler/GHC/Tc/Validity.hs
=====================================
@@ -1723,8 +1723,11 @@ checkHasFieldInst cls tys@[_k_ty, _r_rep, _a_rep, lbl_ty, r_ty, _a_ty] =
| let lbl_str = FieldLabelString lbl
, Just fl <- lookupTyConFieldLabel lbl_str tc
-> do
- -- this logic vaguely mirrors 'matchHasField',
- -- generally we should allow to define HasField instances which GHC will not solve for.
+ -- GHC does not provide HasField instances for naughty record selectors
+ -- (see Note [Naughty record selectors] in GHC.Tc.TyCl.Utils),
+ -- so don't prevent the user from writing such instances.
+ -- See GHC.Tc.Instance.Class.matchHasField.
+ -- Test case: T26295.
sel_id <- tcLookupId $ flSelector fl
if isNaughtyRecordSelector sel_id
then return ()
=====================================
testsuite/tests/overloadedrecflds/should_run/T26295.hs
=====================================
@@ -12,7 +12,7 @@ data R = forall a b. (a ~ Int, b ~ Char) => MkR
, field_b :: b
}
--- fields in R are naught, so we can define own HasField instances for them.
+-- fields in R are naughty, so we can define custom HasField instancs for them
instance a ~ Int => HasField "field_a" R a where
getField (MkR a _) = a
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a05f102c5e5fcdb99457914c44224993...
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a05f102c5e5fcdb99457914c44224993...
You're receiving this email because of your account on gitlab.haskell.org.