Skip to content

Commit 6bc97b5

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Improve switch continue warning
2 parents c8f809f + 1850785 commit 6bc97b5

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

Zend/tests/continue_targeting_switch_warning.phpt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ function test() {
2222
}
2323
}
2424

25+
switch ($bar) {
26+
case 0:
27+
while ($xyz) {
28+
continue 2; // INVALID
29+
}
30+
case 1:
31+
while ($xyz) {
32+
continue;
33+
}
34+
case 2:
35+
while ($xyz) {
36+
break 2;
37+
}
38+
}
39+
2540
while ($foo) {
2641
switch ($bar) {
2742
case 0:
@@ -42,8 +57,10 @@ function test() {
4257

4358
?>
4459
--EXPECTF--
45-
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in %s on line 6
60+
Warning: "continue" targeting switch is equivalent to "break" in %s on line 6
4661

4762
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in %s on line 14
4863

49-
Warning: "continue 2" targeting switch is equivalent to "break 2". Did you mean to use "continue 3"? in %s on line 26
64+
Warning: "continue 2" targeting switch is equivalent to "break 2" in %s on line 25
65+
66+
Warning: "continue 2" targeting switch is equivalent to "break 2". Did you mean to use "continue 3"? in %s on line 41

Zend/zend_compile.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4967,15 +4967,26 @@ void zend_compile_break_continue(zend_ast *ast) /* {{{ */
49674967

49684968
if (CG(context).brk_cont_array[cur].is_switch) {
49694969
if (depth == 1) {
4970-
zend_error(E_WARNING,
4971-
"\"continue\" targeting switch is equivalent to \"break\". " \
4972-
"Did you mean to use \"continue " ZEND_LONG_FMT "\"?",
4973-
depth + 1);
4970+
if (CG(context).brk_cont_array[cur].parent == -1) {
4971+
zend_error(E_WARNING,
4972+
"\"continue\" targeting switch is equivalent to \"break\"");
4973+
} else {
4974+
zend_error(E_WARNING,
4975+
"\"continue\" targeting switch is equivalent to \"break\". " \
4976+
"Did you mean to use \"continue " ZEND_LONG_FMT "\"?",
4977+
depth + 1);
4978+
}
49744979
} else {
4975-
zend_error(E_WARNING,
4976-
"\"continue " ZEND_LONG_FMT "\" targeting switch is equivalent to \"break " ZEND_LONG_FMT "\". " \
4977-
"Did you mean to use \"continue " ZEND_LONG_FMT "\"?",
4978-
depth, depth, depth + 1);
4980+
if (CG(context).brk_cont_array[cur].parent == -1) {
4981+
zend_error(E_WARNING,
4982+
"\"continue " ZEND_LONG_FMT "\" targeting switch is equivalent to \"break " ZEND_LONG_FMT "\"",
4983+
depth, depth);
4984+
} else {
4985+
zend_error(E_WARNING,
4986+
"\"continue " ZEND_LONG_FMT "\" targeting switch is equivalent to \"break " ZEND_LONG_FMT "\". " \
4987+
"Did you mean to use \"continue " ZEND_LONG_FMT "\"?",
4988+
depth, depth, depth + 1);
4989+
}
49794990
}
49804991
}
49814992
}

0 commit comments

Comments
 (0)