Fix internal error FS0073 w/nested inline SRTP and multiple overloads#19710
Fix internal error FS0073 w/nested inline SRTP and multiple overloads#19710gusty wants to merge 2 commits into
Conversation
❗ Release notes required
|
f2c9225 to
6bb273f
Compare
T-Gro
left a comment
There was a problem hiding this comment.
Review Summary
The fix is sound — using ChooseTyparSolution to default unsolved typars in GenTypeAux is consistent with how the compiler handles this in other late-stage passes (optimizer for Expr.TyChoose, pattern match compilation, quotation translation). The regression test is comprehensive and correctly uses compileExeAndRun since this is a codegen bug.
Comment accuracy (minor)
IlxGen.fs line 718: The comment says "can arise in fsi for inline SRTP functions" but the bug also reproduces with fsc (compiled code), not just FSI. Suggest:
// Unsolved type variable not in the TypeReprEnv — can arise for inline SRTP // functions where constraint resolution leaves phantom typars unsolved.
Potential spurious warning 3559
ChooseTyparSolution → ChooseTyparSolutionAndRange emits typrelNeverRefinedAwayFromTop (informational warning 3559) for unconstrained TyparKind.Type typars when DiagnosticForObjInference is enabled. Since the phantom typars being defaulted here are internal artifacts from FreshenMethInfo, not user-visible type variables, this would produce a confusing warning pointing at the method definition site. This is low priority since 3559 is opt-in, but worth noting — a future hardening could call ChooseTyparSolutionAndRange directly and skip the warning path.
Unrelated commit
The branch includes commit de1f4006362 (Array.exists2 XML doc fix from PR #19672) which is not in main and unrelated to this PR. Consider rebasing it out before merge to keep the PR focused.
Overall
The approach is correct and well-tested. The ContainsKey guard prevents the ICE while producing valid IL (the phantom typars genuinely don't affect runtime behavior — they're in wildcard _ positions). Approve once the comment is updated and the unrelated commit is cleaned up.
a68a775 to
9ff6dc6
Compare
|
@T-Gro comment is fixed and PR is rebased, this is ready to squash-merge to main. |
Root cause: In
CodegenWitnessExprForTraitConstraint, whenSolveMemberConstraintresolves a trait call,FreshenMethInfocreates fresh type parameters for the method. During overload resolution, the fresh typar for a wildcard_position gets unified with the trait call's anonymous typar, but neither gets solved to a concrete type. The solution'sminstthen carries these unsolved typars throughGenWitnessExpr→BuildFSharpMethodCall→ IlxGen, where they crash because the typar isn't in theTypeReprEnv.Fix: After
SolveMemberConstraintsucceeds, identify any unsolved typars in the solution'sminstthat were freshly introduced during resolution (not present in the original trait constraint's types) and default them usingChooseTyparSolution. This ensures all type arguments in the generated expression are concrete before they reach IL codegen, without affecting typars from the calling context.Fixes #19709
Checklist