[php-src] Issue #18985: Inner expression compilation (for match) can result in wrong line numbers
| From: | nielsdos | Date: | Mon, 30 Jun 2025 21:00:51 +0000 |
| Subject: | [php-src] Issue #18985: Inner expression compilation (for match) can result in wrong line numbers | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250349@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/18985
Author: nielsdos
### Description
The following code:
```php
<?php
echo match(15) {
13 => "A",
15 => "B",
default => "C",
};
```
Resulted in this output:
```
L0002 0000 MATCH int(15) 13: 0001, 15: 0003, default: 0005
L0003 0001 T1 = QM_ASSIGN string("A")
L0003 0002 JMP 0007
L0004 0003 T1 = QM_ASSIGN string("B")
L0004 0004 JMP 0007
L0005 0005 T1 = QM_ASSIGN string("C")
L0005 0006 JMP 0007
L0005 0007 ECHO T1
<<<<<<<<<<<<<<<<<<<<<<<<
line 5 instead of 2!
L0007 0008 RETURN int(1)
```
But I expected this output instead:
```
L0002 0000 MATCH int(15) 13: 0001, 15: 0003, default: 0005
L0003 0001 T1 = QM_ASSIGN string("A")
L0003 0002 JMP 0007
L0004 0003 T1 = QM_ASSIGN string("B")
L0004 0004 JMP 0007
L0005 0005 T1 = QM_ASSIGN string("C")
L0005 0006 JMP 0007
L0002 0007 ECHO T1
L0007 0008 RETURN int(1)
```
The echo is on line 2, not line 5. This is because the line no gets overwritten. There's
probably many more of these cases.
Discovered via https://github.com/krakjoe/pcov/issues/87
Possible fix idea (may be incomplete):
https://gist.github.com/nielsdos/fe1a4b30aee84efff23f32dc4b0e5ffe
cc @iluuu1994
### PHP Version
```plain
8.3+
```
### Operating System
_No response_