- Add isContinueExpr method to AstNodeType for continue statement detection - Introduce inContinuableLoop context flag to track for/foreach/while/do-while loops - Update CompilerBase to maintain continuable loop state during compilation - Modify LoopControlTrait to validate continue statements only within continuable loops - Enhance SwitchTrait to allow continue as valid case ending expression - Add comprehensive tests for continue in switch nested in various loop types - Create test cases for invalid continue usage outside loops - Update version number from 1094 to 1095pull/43/head
parent
c86e847c8f
commit
9a7de8ee31
10 changed files with 125 additions and 3 deletions
@ -0,0 +1,53 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
use native_types; |
||||||
|
|
||||||
|
function switch_continue_in_for(): void |
||||||
|
{ |
||||||
|
for ($i = 0; $i < 2; $i++) { |
||||||
|
switch ($i) { |
||||||
|
case 0: |
||||||
|
continue; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function switch_continue_in_foreach(array $values): void |
||||||
|
{ |
||||||
|
foreach ($values as $value) { |
||||||
|
switch ($value) { |
||||||
|
case 0: |
||||||
|
continue; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function switch_continue_in_while(): void |
||||||
|
{ |
||||||
|
$i = 0; |
||||||
|
while ($i++ < 2) { |
||||||
|
switch ($i) { |
||||||
|
case 1: |
||||||
|
continue; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function switch_continue_in_do_while(): void |
||||||
|
{ |
||||||
|
$i = 0; |
||||||
|
do { |
||||||
|
switch ($i++) { |
||||||
|
case 0: |
||||||
|
continue; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} while ($i < 2); |
||||||
|
} |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
function standalone_dynamic_switch_continue(mixed $value): void |
||||||
|
{ |
||||||
|
switch ($value) { |
||||||
|
case 1: |
||||||
|
continue; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
use native_types; |
||||||
|
|
||||||
|
function standalone_switch_continue(int $value): void |
||||||
|
{ |
||||||
|
switch ($value) { |
||||||
|
case 1: |
||||||
|
continue; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,25 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
class LoopControlTest extends \BaseTest |
||||||
|
{ |
||||||
|
public function testContinueInStandaloneSwitchIsRejected(): void |
||||||
|
{ |
||||||
|
$this->exec( |
||||||
|
'Cannot continue outside loop', |
||||||
|
'control-flow/standalone-switch-continue.php', |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
public function testContinueInStandaloneDynamicSwitchIsRejected(): void |
||||||
|
{ |
||||||
|
$this->exec( |
||||||
|
'Cannot continue outside loop', |
||||||
|
'control-flow/standalone-dynamic-switch-continue.php', |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
public function testContinueInSwitchNestedInLoopsIsAllowed(): void |
||||||
|
{ |
||||||
|
$this->compile('control-flow/loop-switch-continue.php'); |
||||||
|
} |
||||||
|
} |
||||||
@ -1 +1 @@ |
|||||||
1094 |
1095 |
||||||
|
|||||||
Loading…
Reference in new issue