Skip to content

Commit f3d8ac1

Browse files
committed
Fix JIT trait type errors
We need to load EX->func here rather than use a hardcoded op_array, as it may be copied with adjusted scope for traits.
1 parent f15b5ff commit f3d8ac1

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

Zend/tests/trait_type_errors.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Type errors for methods from traits should refer to using class
3+
--FILE--
4+
<?php
5+
6+
trait T {
7+
public function test1($arg): int {
8+
return $arg;
9+
}
10+
public function test2(int $arg) {
11+
}
12+
public function test3(int $arg = 42) {
13+
}
14+
}
15+
16+
class C {
17+
use T;
18+
}
19+
class P extends C {
20+
}
21+
22+
$c = new C;
23+
try {
24+
$c->test1("foo");
25+
} catch (TypeError $e) {
26+
echo $e->getMessage(), "\n";
27+
}
28+
try {
29+
$c->test2("foo");
30+
} catch (TypeError $e) {
31+
echo $e->getMessage(), "\n";
32+
}
33+
try {
34+
$c->test3("foo");
35+
} catch (TypeError $e) {
36+
echo $e->getMessage(), "\n";
37+
}
38+
39+
?>
40+
--EXPECTF--
41+
Return value of C::test1() must be of the type int, string returned
42+
Argument 1 passed to C::test2() must be of the type int, string given, called in %s on line %d
43+
Argument 1 passed to C::test3() must be of the type int, string given, called in %s on line %d

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8640,7 +8640,7 @@ static int zend_jit_recv(dasm_State **Dst, const zend_op *opline, const zend_op_
86408640
| mov FCARG1a, r0
86418641
| mov r0, EX->run_time_cache
86428642
| add r0, opline->extended_value
8643-
| LOAD_ADDR FCARG2a, (ptrdiff_t)op_array
8643+
| mov FCARG2a, EX->func
86448644
|.if X64WIN
86458645
| mov CARG3, arg_num
86468646
| LOAD_ADDR CARG4, (ptrdiff_t)arg_info
@@ -8784,7 +8784,7 @@ static int zend_jit_recv_init(dasm_State **Dst, const zend_op *opline, const zen
87848784
| mov FCARG1a, r0
87858785
| mov r0, EX->run_time_cache
87868786
| lea r0, [r0 + opline->extended_value]
8787-
| LOAD_ADDR FCARG2a, (ptrdiff_t)op_array
8787+
| mov FCARG2a, EX->func
87888788
|.if X64WIN
87898789
| mov CARG3, arg_num
87908790
| LOAD_ADDR CARG4, (ptrdiff_t)arg_info
@@ -9345,7 +9345,7 @@ static zend_bool zend_jit_verify_return_type(dasm_State **Dst, const zend_op *op
93459345
| mov FCARG1a, r0
93469346
| mov r0, EX->run_time_cache
93479347
| add r0, opline->op2.num
9348-
| LOAD_ADDR FCARG2a, (ptrdiff_t)op_array
9348+
| mov FCARG2a, EX->func
93499349
|.if X64
93509350
| LOAD_ADDR CARG3, (ptrdiff_t)arg_info
93519351
| mov CARG4, r0

0 commit comments

Comments
 (0)