Fix generic parameter resolution in inline functions with static member constraints #4160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix generic parameter resolution in inline functions with static member constraints
Note: Claude Code did this for me, so it could be terrible
Description
This PR fixes a bug (#4093) where inline functions with multiple generic type parameters and static member constraints would incorrectly resolve all trait calls to the first type parameter's witness.
The Issue
When using inline functions with multiple generic parameters that have static member constraints, all static member calls would resolve to the first type parameter:
Root Cause
The issue occurred in two places:
Solution
Enhanced Witness Resolution: Added
tryFindWitnessWithSourceTypes
that uses source type information to select the correct witness when multiple witnesses match. It determines which generic parameter is being resolved and selects the corresponding witness based on position.Fixed Nested Inline Functions: Modified the generic argument handling in
inlineExpr
to compose mappings rather than replace them, ensuring that inner inline functions can resolve their generic parameters through the outer function's context.Changes
tryFindWitnessWithSourceTypes
inFSharp2Fable.Util.fs
to handle witness disambiguationFSharp2Fable.fs
to use source types for witness selectionTesting
The fix has been tested with:
All scenarios now work correctly.
Impact
This fix enables proper use of inline functions with multiple generic parameters having static member constraints, which is important for generic programming patterns in F#.