Skip to content

Commit 8a49310

Browse files
committed
Adjust assignment line number for match
Otherwise the assignment will have the same number as the default arm which will 1. mis-trigger a breakpoint and 2. mark the line as covered even when it isn't. Closes GH-6083
1 parent af0ba0b commit 8a49310

5 files changed

+129
-0
lines changed

Zend/zend_compile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,6 +3063,7 @@ void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
30633063
zend_delayed_compile_var(&var_node, var_ast, BP_VAR_W, 0);
30643064
zend_compile_expr(&expr_node, expr_ast);
30653065
zend_delayed_compile_end(offset);
3066+
CG(zend_lineno) = zend_ast_get_lineno(var_ast);
30663067
zend_emit_op_tmp(result, ZEND_ASSIGN, &var_node, &expr_node);
30673068
return;
30683069
case ZEND_AST_STATIC_PROP:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Test match default breakpoint with variable assignment
3+
--INI--
4+
opcache.enable_cli=0
5+
--PHPDBG--
6+
b 5
7+
b 10
8+
r
9+
q
10+
--EXPECTF--
11+
[Successful compilation of %s.php]
12+
prompt> [Breakpoint #0 added at %s.php:5]
13+
prompt> [Breakpoint #1 added at %s.php:10]
14+
prompt> [Breakpoint #1 at %s.php:10, hits: 1]
15+
>00010: default => 'bar', // breakpoint #1
16+
00011: };
17+
00012:
18+
prompt>
19+
--FILE--
20+
<?php
21+
22+
$foo = match (0) {
23+
0 => 'foo',
24+
default => 'bar', // breakpoint #0
25+
};
26+
27+
$foo = match (1) {
28+
0 => 'foo',
29+
default => 'bar', // breakpoint #1
30+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Test match default breakpoint with property assignment
3+
--INI--
4+
opcache.enable_cli=0
5+
--PHPDBG--
6+
b 7
7+
b 12
8+
r
9+
q
10+
--EXPECTF--
11+
[Successful compilation of %s.php]
12+
prompt> [Breakpoint #0 added at %s.php:7]
13+
prompt> [Breakpoint #1 added at %s.php:12]
14+
prompt> [Breakpoint #1 at %s.php:12, hits: 1]
15+
>00012: default => 'bar', // breakpoint #1
16+
00013: };
17+
00014:
18+
prompt>
19+
--FILE--
20+
<?php
21+
22+
$foo = new stdClass();
23+
24+
$foo->bar = match (0) {
25+
0 => 'foo',
26+
default => 'bar', // breakpoint #0
27+
};
28+
29+
$foo->bar = match (1) {
30+
0 => 'foo',
31+
default => 'bar', // breakpoint #1
32+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Test match default breakpoint with dim assignment
3+
--INI--
4+
opcache.enable_cli=0
5+
--PHPDBG--
6+
b 7
7+
b 12
8+
r
9+
q
10+
--EXPECTF--
11+
[Successful compilation of %s.php]
12+
prompt> [Breakpoint #0 added at %s.php:7]
13+
prompt> [Breakpoint #1 added at %s.php:12]
14+
prompt> [Breakpoint #1 at %s.php:12, hits: 1]
15+
>00012: default => 'bar', // breakpoint #1
16+
00013: };
17+
00014:
18+
prompt>
19+
--FILE--
20+
<?php
21+
22+
$foo = [];
23+
24+
$foo['foo'] = match (0) {
25+
0 => 'foo',
26+
default => 'bar', // breakpoint #0
27+
};
28+
29+
$foo->bar = match (1) {
30+
0 => 'foo',
31+
default => 'bar', // breakpoint #1
32+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Test match default breakpoint with static variable assignment
3+
--INI--
4+
opcache.enable_cli=0
5+
--PHPDBG--
6+
b 9
7+
b 14
8+
r
9+
q
10+
--EXPECTF--
11+
[Successful compilation of %s.php]
12+
prompt> [Breakpoint #0 added at %s.php:9]
13+
prompt> [Breakpoint #1 added at %s.php:14]
14+
prompt> [Breakpoint #1 at %s.php:14, hits: 1]
15+
>00014: default => 'bar', // breakpoint #1
16+
00015: };
17+
00016:
18+
prompt>
19+
--FILE--
20+
<?php
21+
22+
class Foo {
23+
public static $bar;
24+
}
25+
26+
Foo::$bar = match (0) {
27+
0 => 'foo',
28+
default => 'bar', // breakpoint #0
29+
};
30+
31+
Foo::$bar = match (1) {
32+
0 => 'foo',
33+
default => 'bar', // breakpoint #1
34+
};

0 commit comments

Comments
 (0)