]> Repositorios git - classgraph.git/commit
Fix data-family R: rewrite to substitute rep tyvars with use-site args
authorJavier Sagredo <[email protected]>
Wed, 6 May 2026 23:38:11 +0000 (01:38 +0200)
committerJavier Sagredo <[email protected]>
Wed, 6 May 2026 23:51:06 +0000 (01:51 +0200)
commit50879af16ed6fedefb2d8b3db37a5852d11b461d
tree8c826df2e5bf3523bc0250becac7184ff60c3a4d
parent38882da32f21057d1c6a481d655b2f3a4b22abc8
Fix data-family R: rewrite to substitute rep tyvars with use-site args

The previous rewrite (commit 723a7c3) called tyConFamInst_maybe and
fed parentArgs straight into typeArg. parentArgs reference the rep
TyCon's *internal* type variables, not the use-site args; without a
substitution they leak through typeArg's TyVar lookup as
@OtherArg "<reptv>"@ because they're absent from boundTvs. So
@R:CrateList Int@ was rewriting to @Crate [<reptv>]@ — which broke
both the rendering (the user saw rep-internal names) and the chain
resolution (replaceFamilyApp's biUnify still succeeded by luck of
the wildcard rule, but the visible label was wrong).

Build a Subst from the rep's tyConTyVars to the actual use-site args
and apply it to parentArgs before recursing. With this fix
@R:CrateList Int@ extracts as @FamilyApp Crate [TyConApp List
[TyConApp Int []]]@ and renders as @Crate [Int]@; the polymorphic
case @R:CrateList a@ in an instance head extracts as
@FamilyApp Crate [TyConApp List [TyVarRef 0]]@ and renders as
@Crate [a]@.

Demo gains a @CrateBound (Crate [a])@ instance so the polymorphic-rep
path is regression-covered.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
examples/demo/src/Demo/MoreFamilies.hs
src/Classgraph/Extract.hs