]> granicus.if.org Git - php/commitdiff
Adjust assignment line number for match
authorIlija Tovilo <ilija.tovilo@me.com>
Sat, 5 Sep 2020 14:33:22 +0000 (16:33 +0200)
committerIlija Tovilo <ilija.tovilo@me.com>
Mon, 7 Sep 2020 22:08:18 +0000 (00:08 +0200)
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

Zend/zend_compile.c
sapi/phpdbg/tests/match_breakpoints_001.phpt [new file with mode: 0644]
sapi/phpdbg/tests/match_breakpoints_002.phpt [new file with mode: 0644]
sapi/phpdbg/tests/match_breakpoints_003.phpt [new file with mode: 0644]
sapi/phpdbg/tests/match_breakpoints_004.phpt [new file with mode: 0644]

index 7eb2d79fe72f560c8647e8a003649385ffbe8ec5..5d1c4a6207a8d5146639ef5e3f96c5250c2215f1 100644 (file)
@@ -3063,6 +3063,7 @@ void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
                        zend_delayed_compile_var(&var_node, var_ast, BP_VAR_W, 0);
                        zend_compile_expr(&expr_node, expr_ast);
                        zend_delayed_compile_end(offset);
+                       CG(zend_lineno) = zend_ast_get_lineno(var_ast);
                        zend_emit_op_tmp(result, ZEND_ASSIGN, &var_node, &expr_node);
                        return;
                case ZEND_AST_STATIC_PROP:
diff --git a/sapi/phpdbg/tests/match_breakpoints_001.phpt b/sapi/phpdbg/tests/match_breakpoints_001.phpt
new file mode 100644 (file)
index 0000000..9ef7417
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Test match default breakpoint with variable assignment
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+b 5
+b 10
+r
+q
+--EXPECTF--
+[Successful compilation of %s.php]
+prompt> [Breakpoint #0 added at %s.php:5]
+prompt> [Breakpoint #1 added at %s.php:10]
+prompt> [Breakpoint #1 at %s.php:10, hits: 1]
+>00010:     default => 'bar', // breakpoint #1
+ 00011: };
+ 00012: 
+prompt>
+--FILE--
+<?php
+
+$foo = match (0) {
+    0 => 'foo',
+    default => 'bar', // breakpoint #0
+};
+
+$foo = match (1) {
+    0 => 'foo',
+    default => 'bar', // breakpoint #1
+};
diff --git a/sapi/phpdbg/tests/match_breakpoints_002.phpt b/sapi/phpdbg/tests/match_breakpoints_002.phpt
new file mode 100644 (file)
index 0000000..21b0b4e
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+Test match default breakpoint with property assignment
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+b 7
+b 12
+r
+q
+--EXPECTF--
+[Successful compilation of %s.php]
+prompt> [Breakpoint #0 added at %s.php:7]
+prompt> [Breakpoint #1 added at %s.php:12]
+prompt> [Breakpoint #1 at %s.php:12, hits: 1]
+>00012:     default => 'bar', // breakpoint #1
+ 00013: };
+ 00014: 
+prompt>
+--FILE--
+<?php
+
+$foo = new stdClass();
+
+$foo->bar = match (0) {
+    0 => 'foo',
+    default => 'bar', // breakpoint #0
+};
+
+$foo->bar = match (1) {
+    0 => 'foo',
+    default => 'bar', // breakpoint #1
+};
diff --git a/sapi/phpdbg/tests/match_breakpoints_003.phpt b/sapi/phpdbg/tests/match_breakpoints_003.phpt
new file mode 100644 (file)
index 0000000..dbd7eb7
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+Test match default breakpoint with dim assignment
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+b 7
+b 12
+r
+q
+--EXPECTF--
+[Successful compilation of %s.php]
+prompt> [Breakpoint #0 added at %s.php:7]
+prompt> [Breakpoint #1 added at %s.php:12]
+prompt> [Breakpoint #1 at %s.php:12, hits: 1]
+>00012:     default => 'bar', // breakpoint #1
+ 00013: };
+ 00014: 
+prompt>
+--FILE--
+<?php
+
+$foo = [];
+
+$foo['foo'] = match (0) {
+    0 => 'foo',
+    default => 'bar', // breakpoint #0
+};
+
+$foo->bar = match (1) {
+    0 => 'foo',
+    default => 'bar', // breakpoint #1
+};
diff --git a/sapi/phpdbg/tests/match_breakpoints_004.phpt b/sapi/phpdbg/tests/match_breakpoints_004.phpt
new file mode 100644 (file)
index 0000000..d59555e
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+Test match default breakpoint with static variable assignment
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+b 9
+b 14
+r
+q
+--EXPECTF--
+[Successful compilation of %s.php]
+prompt> [Breakpoint #0 added at %s.php:9]
+prompt> [Breakpoint #1 added at %s.php:14]
+prompt> [Breakpoint #1 at %s.php:14, hits: 1]
+>00014:     default => 'bar', // breakpoint #1
+ 00015: };
+ 00016: 
+prompt>
+--FILE--
+<?php
+
+class Foo {
+    public static $bar;
+}
+
+Foo::$bar = match (0) {
+    0 => 'foo',
+    default => 'bar', // breakpoint #0
+};
+
+Foo::$bar = match (1) {
+    0 => 'foo',
+    default => 'bar', // breakpoint #1
+};