Fix number type variable collision in arithmetic operators#131
Merged
mdgriffith merged 1 commit intomdgriffith:mainfrom Mar 31, 2026
Merged
Conversation
When multiple arithmetic operators appeared as siblings (e.g. in a tuple or record), their internal "number" type variables could collide because toExpressionDetails reuses index values across siblings. The fix eagerly resolves fully-determined type variables in applyType after unification, so concrete types (Float, Int, etc.) are stored directly in the result instead of leaving GenericType references in the inference cache where they could be overwritten by siblings. This is a general fix in Compiler.applyType that protects all callers, not just arithmetic operators. Before: `Elm.tuple (Elm.Op.plus (Elm.float 1.5) (Elm.float 2.5)) (Elm.Op.plus (Elm.int 1) (Elm.int 2))` generated `( Int, Int )` instead of `( Float, Int )`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
|
amazing. Tests, clear explanation, 😻 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When multiple arithmetic operators appeared within the same tuple or record, their internal
numbertype variables could collide becausetoExpressionDetailsreuses index values across siblings.This eagerly resolves type variables in
applyTypeafter unification, so concrete types (Float, Int, etc.) are stored directly in the result instead of leavingGenericTypereferences in the inference cache where they could be overwritten by siblings.Before:
generated
( Int, Int )Now it correctly generates the type annotation
( Float, Int ).