Skip to content

fix(switch): continue N targeting an outer switch leaves it like break N - #14368

Merged
orklah merged 5 commits into
vimeo:masterfrom
jirkace:fix/14018-continue-targets-switch
Nov 22, 2026
Merged

orklah merged 5 commits into
vimeo:masterfrom
jirkace:fix/14018-continue-targets-switch

Conversation

@jirkace

@jirkace jirkace commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

continue N whose target is an outer switch is reported as ContinueOutsideLoop, and the variables it carries out of the switch are lost.

Before

switch ($outer) {
    case "A":
        switch ($inner) {
            case "x":
                $q = 1;
                continue 2; // ContinueOutsideLoop: Continue called when not in loop
        }

        $q = 2;
        break;
    default:
        $q = 3;
}
// $q: 2|3

After

// $q: 1|2|3, in PHP `continue 2` targeting a switch acts like `break 2`

Fixes #14018

…k N vimeo#14018

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 429791e. Configure here.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 751 96.7 $\color{gray}{\textsf{+0.7\%}}$ 25 908 53 462 682
✅ symfony 3 600 201.6 $\color{gray}{\textsf{-1.3\%}}$ 50 611 98 405 1 528
✅ doctrine-orm 381 20.9 $\color{gray}{\textsf{+0.2\%}}$ 3 481 6 143 0
✅ psl 617 26.4 $\color{gray}{\textsf{-0.1\%}}$ 1 375 5 615 1
✅ phpunit 455 19.5 $\color{gray}{\textsf{-0.2\%}}$ 1 731 3 410 18
✅ php-parser 226 13.4 $\color{gray}{\textsf{+0.9\%}}$ 17 132 21 025 0
✅ tempest 895 36.1 $\color{gray}{\textsf{+0.8\%}}$ 5 047 10 528 252
✅ amphp-amp 68 1.6 $\color{gray}{\textsf{+0.6\%}}$ 29 49 0
✅ webmozarts-assert 272 3.7 $\color{gray}{\textsf{+2.5\%}}$ 577 2 720 0
✅ guzzle-promises 44 1.3 $\color{gray}{\textsf{+3.1\%}}$ 155 434 2
✅ monolog 135 4.7 $\color{gray}{\textsf{+0.9\%}}$ 913 2 479 10
✅ drupal 4 841 237.4 $\color{gray}{\textsf{-2.4\%}}$ 97 591 169 293 583
Total 13 285 663.5 $\color{gray}{\textsf{-1.1\%}}$ 204 550 373 563 3 076
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.

head 3923b3a · base c5f4dfd (merge-base) · workflow run

jirkace and others added 2 commits November 20, 2026 18:42
…h of the case vimeo#14018

Outer switches are given to the case actions as their own break type, so that `break N` and
`continue N` past the switch of the case stay a way out of it, as master's nested `break 2`
handling expects, instead of looking like a `break` of that switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@orklah orklah 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.

Thanks, the fix is right on every nesting I tried (switch > loop > switch with continue 3, a loop
between the switches, all cases leaving with continue 2).

One thing: continueTargetingAnOuterSwitchInALoopLeavesTheSwitchNotTheLoop also passes on master, since
it asserts no type and master reports nothing there, although master gets that path wrong. Could you make
it assert the type? For example:

'continueTargetingAnOuterSwitchInALoopLeavesTheSwitchNotTheLoop' => [
    'code' => '<?php
        $r = 0;
        foreach (["A", "B"] as $s) {
            switch ($s) {
                case "A":
                    switch (uniqid()) {
                        case "x":
                            $q = 1;
                            continue 2;
                    }

                    $q = 2;
                    break;
                default:
                    $q = 3;
            }

            $r = $q;
        }',
    'assertions' => [
        '$r===' => '1|2|3', // master: 0|2|3
    ],
    'ignored_issues' => [],
    'php_version' => '7.4',
],

jirkace and others added 2 commits November 21, 2026 16:15
…f the variable

It passed on master as well because it asserted nothing; $r is 1|2|3 here and 0|2|3 on master.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jirkace

jirkace commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 3923b3a. continueTargetingAnOuterSwitchInALoopLeavesTheSwitchNotTheLoop is your snippet with '$r===' => '1|2|3'; on master it is 0|2|3. @orklah

@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 22, 2026

@orklah orklah 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.

Thanks @jirkace!

@orklah
orklah merged commit 177a649 into vimeo:master Nov 22, 2026
71 of 72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

continue N targeting a switch is reported as ContinueOutsideLoop and loses its variables

2 participants