Skip to content

Fix equality-chain branches and tuple foreach targets - #700

Merged
lagergren merged 3 commits into
masterfrom
fix/compiler-equality-and-tuple-loops
Oct 14, 2026
Merged

lagergren merged 3 commits into
masterfrom
fix/compiler-equality-and-tuple-loops

Conversation

@lagergren

@lagergren lagergren commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Why?

  • Equality chains containing a constant, such as left == 3 == right or left == Null == right, can take the wrong conditional branch.
  • A foreach loop that unpacks tuples into properties or array elements crashes the compiler during code generation.

How?

  • Require every equality-chain operand to match the constant, honoring both normal and negated conditional branches.
  • Assign each unpacked tuple value through its own destination instead of the absent single-value destination.
  • Add readable Ecstasy regressions to the existing manual test modules, with one commit per bug.
  • Teach Tree-sitter to parse existing tuple assignment targets in foreach loops; the new regression sources exposed this grammar gap in CI.

These fixes were found during the AST cleanup in #693 and are extracted here directly from master for independent review. The constant-folding fix remains separate in #699; this PR does not depend on it.

Changes

  • javatools/src/main/java/org/xvm/compiler/ast/CmpChainExpression.java: correct conditional jumps for equality chains containing a constant.
  • javatools/src/main/java/org/xvm/compiler/ast/ForEachStatement.java: use the current tuple element's assignment target.
  • manualTests/src/main/x/misc.x: exercise all matching/mismatching integer and nullable operand combinations as Boolean values and normal/negated conditions.
  • manualTests/src/main/x/loop.x: check tuple assignment to properties, mutable array elements, and mixed local/property targets.
  • lang/dsl/src/main/resources/templates/grammar.js.template and lang/generated-examples/grammar.js: accept existing local, property and indexed tuple targets, with the ambiguity declaration needed to distinguish foreach from tuple assignment.

Both regressions were reproduced before their respective fixes: the equality test took the wrong branch, and the tuple test failed with a null-pointer exception in ForEachStatement.emitList. With the fixes, all 23 sequential manual-test modules pass. A fresh XDK test run reports 53 passed, eight existing skips, and no failures; spotlessCheck also passes.

The grammar fix passes generation, all 1,032 source-corpus files, 50 DSL tests and 43 native Tree-sitter adapter tests, with no failures or skips. Both the generating template and the checked-in grammar example are updated.

Reproduce the manual-suite verification from the repository root:

./gradlew :manualTests:clean \
    -PincludeBuildManualTests=true -PincludeBuildAttachManualTests=true
./gradlew :manualTests:runSequential \
    -PincludeBuildManualTests=true -PincludeBuildAttachManualTests=true --no-build-cache

Run the clean command separately and wait for it to finish so the manual tests are recompiled with the selected compiler.

@ggleyzer ggleyzer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@lagergren

Copy link
Copy Markdown
Contributor Author

Good catch

Don't thank me, thank the LSP. I have found so many issues like this by just working with the compiler adapter LSP - do try it!

@lagergren
lagergren enabled auto-merge (squash) October 14, 2026 05:59
@lagergren
lagergren merged commit 9af4148 into master Oct 14, 2026
5 checks passed
@lagergren
lagergren deleted the fix/compiler-equality-and-tuple-loops branch October 14, 2026 06:13
lagergren added a commit that referenced this pull request Oct 14, 2026
The equality-chain and tuple foreach target cases in TestAstExpressions
are covered by testEqualityChains in misc.x and testForEachTupleTargets
in loop.x, which came in with #700; keep only the coverage unique to
this module.
lagergren added a commit that referenced this pull request Oct 14, 2026
The equality-chain and tuple foreach target cases in TestAstExpressions
are covered by testEqualityChains in misc.x and testForEachTupleTargets
in loop.x, which came in with #700; keep only the coverage unique to
this module.
lagergren added a commit that referenced this pull request Oct 15, 2026
The equality-chain and tuple foreach target cases in TestAstExpressions
are covered by testEqualityChains in misc.x and testForEachTupleTargets
in loop.x, which came in with #700; keep only the coverage unique to
this module.
lagergren added a commit that referenced this pull request Oct 15, 2026
The equality-chain and tuple foreach target cases in TestAstExpressions
are covered by testEqualityChains in misc.x and testForEachTupleTargets
in loop.x, which came in with #700; keep only the coverage unique to
this module.
lagergren added a commit that referenced this pull request Oct 19, 2026
The equality-chain and tuple foreach target cases in TestAstExpressions
are covered by testEqualityChains in misc.x and testForEachTupleTargets
in loop.x, which came in with #700; keep only the coverage unique to
this module.
lagergren added a commit that referenced this pull request Oct 20, 2026
The equality-chain and tuple foreach target cases in TestAstExpressions
are covered by testEqualityChains in misc.x and testForEachTupleTargets
in loop.x, which came in with #700; keep only the coverage unique to
this module.
lagergren added a commit that referenced this pull request Oct 21, 2026
The equality-chain and tuple foreach target cases in TestAstExpressions
are covered by testEqualityChains in misc.x and testForEachTupleTargets
in loop.x, which came in with #700; keep only the coverage unique to
this module.
lagergren added a commit that referenced this pull request Oct 26, 2026
The equality-chain and tuple foreach target cases in TestAstExpressions
are covered by testEqualityChains in misc.x and testForEachTupleTargets
in loop.x, which came in with #700; keep only the coverage unique to
this module.
lagergren added a commit that referenced this pull request Oct 26, 2026
The equality-chain and tuple foreach target cases in TestAstExpressions
are covered by testEqualityChains in misc.x and testForEachTupleTargets
in loop.x, which came in with #700; keep only the coverage unique to
this module.
lagergren added a commit that referenced this pull request Oct 27, 2026
The equality-chain and tuple foreach target cases in TestAstExpressions
are covered by testEqualityChains in misc.x and testForEachTupleTargets
in loop.x, which came in with #700; keep only the coverage unique to
this module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants