Skip to content

Test that short-circuiting actually short-circuits - #97

Merged
revarbat merged 1 commit into
mainfrom
test-shortcircuit-coverage
Aug 15, 2026
Merged

Test that short-circuiting actually short-circuits#97
revarbat merged 1 commit into
mainfrom
test-shortcircuit-coverage

Conversation

@revarbat

Copy link
Copy Markdown
Member

What

&&/|| and the ternary already had laziness tests, but only for the AST interpreter (test_expr_eval.cpp's RightSideNotEvaluatedWhenShortCircuited and OnlyChosenBranchEvaluates). The compiled path's own test (TernaryAndShortCircuitLogicalOps) asserts only the result — which an eager compiler computes just as correctly — so nothing would have failed if the JumpIfFalse/JumpIfTrue the compiler emits around the right operand or the untaken branch ever went away.

The list comprehensions' if/if-else clauses had the same gap in both engines: their tests check the resulting list, which an eager implementation also gets right.

Tests added

Each runs a marker echo() from inside the branch that must never run, and asserts the exact echo output — an extra evaluation shows up as an extra line.

Test Path
BytecodeCompiler.ShortCircuitDoesNotEvaluateRightOperandCompiled VM, && and ||, both directions
BytecodeCompiler.TernaryOnlyEvaluatesChosenBranchCompiled VM, ternary
ListComprehension.ForIfSkipsBodyWhenConditionFails{Interpreted,Compiled} both engines
ListComprehension.ForIfElseEvaluatesOnlyTheChosenBranch{Interpreted,Compiled} both engines

Verified non-vacuous by mutation

Temporary mutation Result
Inverted the VM's jumps in bytecode_compiler.cpp all 4 compiled tests fail; interpreted ones still pass
Made expr_eval.cpp's ListCompIf/ListCompIfElse cases eager both interpreted tests fail

That second run is also what showed the interpreted variants need an explicit ScopedVm(false) — a top-level list comprehension compiles by default, so without it they were re-testing the VM.

Result

No behavior change; the evaluator was already correct on all six cases. Full suite passes (865 tests), and again under OSCAD_BYTECODE_VM=0 and =1.

Version bumped 0.32.0 → 0.32.1.

🤖 Generated with Claude Code

`&&`/`||` and the ternary already had laziness tests, but only for the
AST interpreter (test_expr_eval.cpp's RightSideNotEvaluatedWhenShortCircuited
and OnlyChosenBranchEvaluates). The compiled path's own test asserted only
the RESULT -- which an eager compiler computes just as correctly -- so
nothing would have failed if the JumpIfFalse/JumpIfTrue the compiler emits
around the right operand or the untaken branch ever went away. The list
comprehensions' `if`/`if-else` clauses had the same gap in both engines:
their tests check the resulting list, which an eager implementation also
gets right.

Six tests that close it, each running a marker echo() from inside the
branch that must never run and asserting the exact echo output, so an
extra evaluation shows up as an extra line:

  BytecodeCompiler.ShortCircuitDoesNotEvaluateRightOperandCompiled
  BytecodeCompiler.TernaryOnlyEvaluatesChosenBranchCompiled
  ListComprehension.ForIfSkipsBodyWhenConditionFails{Interpreted,Compiled}
  ListComprehension.ForIfElseEvaluatesOnlyTheChosenBranch{Interpreted,Compiled}

Verified non-vacuous by mutation: inverting the VM's jumps in
bytecode_compiler.cpp fails all four compiled tests (and leaves the
interpreted ones passing), while making expr_eval.cpp's ListCompIf/
ListCompIfElse cases eager fails both interpreted ones. That second run is
also what showed the interpreted variants need an explicit ScopedVm(false)
-- a top-level list comprehension compiles by default, so without it they
were re-testing the VM.

No behavior change; the evaluator was already correct on all six.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@revarbat
revarbat merged commit 92672c4 into main Aug 15, 2026
3 checks passed
@revarbat
revarbat deleted the test-shortcircuit-coverage branch August 15, 2026 05:40
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.

1 participant