Fix mixed-type addition chain incorrectly treated as pure string concatenation#2337
Merged
Conversation
….0 + 'm' should be '5m' not '23m') Co-authored-by: lahma <171892+lahma@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix wrong evaluation of mixed type expressions in Jint
Fix mixed-type addition chain incorrectly treated as pure string concatenation
Mar 19, 2026
lahma
approved these changes
Mar 19, 2026
lahma
marked this pull request as ready for review
March 19, 2026 16:44
lahma
enabled auto-merge (squash)
March 19, 2026 17:02
This was referenced Mar 23, 2026
This was referenced Jun 8, 2026
This was referenced Jun 29, 2026
This was referenced Jul 7, 2026
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.
The
StringConcatenationExpressionoptimization introduced in 4.6.0 incorrectly flattened any left-recursive+chain containing a string literal — regardless of position — into a single string concat pass. This broke left-to-right numeric evaluation when numeric operands preceded the string literal.Changes
JintBinaryExpression.cs—TryBuildStringConcatenationnow only creates aStringConcatenationExpressionwhen the string literal appears at operand index 0 or 1. A string at index ≥ 2 means the first operation (operands[0] + operands[1]) may be numeric addition, so flattening is unsafe. Adds a defensiveoperands.Count < 2guard with an explanatory comment.StringTests.cs— AddsMixedTypeAdditionShouldEvaluateLeftToRightregression test covering the reported case and related variants.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.