Skip to content

fix(compiler): preserve PHP switch comparison semantics - #89

Merged
matyhtf merged 1 commit into
swoole:masterfrom
yavon007:codex/fix-switch-type-comparisons
Sep 7, 2026
Merged

fix(compiler): preserve PHP switch comparison semantics#89
matyhtf merged 1 commit into
swoole:masterfrom
yavon007:codex/fix-switch-type-comparisons

Conversation

@yavon007

Copy link
Copy Markdown
Contributor

Typed boolean switch subjects could take the wrong branch: true did not match case 2 after lowering to a C++ switch. Integer subjects with floating-point case labels generated invalid C++ and failed to compile.

Check all labels before lowering any case bodies. Keep the native switch path for integer labels whose comparisons agree with PHP, including boolean subjects with labels 0 and 1. Route other cases through the existing comparison path and convert labels to their PHP truth value when comparing a boolean subject.

Add separate PHPT regressions for boolean/numeric comparisons and integer subjects with floating-point labels.

Validation on Linux ARM64 with PHP 8.5.10:

  • Both new regressions fail before the fix and pass afterward; their expected output matches plain PHP.
  • tests/compiler/switch: 8/8 passed with native AOT compilation.
  • LoopControlTest: 7 tests / 15 assertions passed.
  • Applied together with the separate trailing-empty-case fix: all three new PHPT regressions passed.
  • git diff --check passed.

@matyhtf
matyhtfforce-pushed the codex/fix-switch-type-comparisons branch from e71f708 to 94cd9a1CompareSeptember 7, 2026 09:24
@matyhtf
matyhtf merged commit 6aae5f7 into swoole:masterSep 7, 2026
8 checks passed
Sign up for freeto 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

@yavon007@matyhtf