Skip to content

Commit 652a058

Browse files
krakjoearnaud-lb
authored andcommitted
partial application
1 parent b871261 commit 652a058

File tree

79 files changed

+3502
-509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3502
-509
lines changed

Zend/Optimizer/zend_call_graph.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ ZEND_API void zend_analyze_calls(zend_arena **arena, zend_script *script, uint32
128128
case ZEND_DO_UCALL:
129129
case ZEND_DO_FCALL_BY_NAME:
130130
case ZEND_CALLABLE_CONVERT:
131+
case ZEND_DO_FCALL_PARTIAL:
131132
func_info->flags |= ZEND_FUNC_HAS_CALLS;
132133
if (call_info) {
133134
call_info->caller_call_opline = opline;
@@ -144,6 +145,7 @@ ZEND_API void zend_analyze_calls(zend_arena **arena, zend_script *script, uint32
144145
case ZEND_SEND_VAR_NO_REF:
145146
case ZEND_SEND_VAR_NO_REF_EX:
146147
case ZEND_SEND_USER:
148+
case ZEND_SEND_PLACEHOLDER:
147149
if (call_info) {
148150
if (opline->op2_type == IS_CONST) {
149151
call_info->named_args = 1;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Partial application compile errors: multiple ...
3+
--FILE--
4+
<?php
5+
foo(..., ...);
6+
?>
7+
--EXPECTF--
8+
Fatal error: Variadic placeholder may only appear once in %s on line %d
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Partial application compile errors: only named arguments after ...
3+
--FILE--
4+
<?php
5+
foo(..., ?);
6+
?>
7+
--EXPECTF--
8+
Fatal error: Only named arguments may follow variadic placeholder in %s on line %d
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Partial application compile errors: named arguments must come after placeholder
3+
--FILE--
4+
<?php
5+
foo(n: 5, ?);
6+
?>
7+
--EXPECTF--
8+
Fatal error: Named arguments must come after all placeholders in %s on line %d
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Partial application compile errors: named arguments must come after variadic placeholder
3+
--FILE--
4+
<?php
5+
foo(n: 5, ...);
6+
?>
7+
--EXPECTF--
8+
Fatal error: Named arguments must come after all placeholders in %s on line %d
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Partial application compile errors: follow variadic with un-named arg
3+
--FILE--
4+
<?php
5+
foo(..., $a);
6+
?>
7+
--EXPECTF--
8+
Fatal error: Only named arguments may follow variadic placeholder in %s on line %d
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Partial application compile errors: mix application with unpack (placeholder after)
3+
--FILE--
4+
<?php
5+
foo(...["foo" => "bar"], ...);
6+
?>
7+
--EXPECTF--
8+
Fatal error: Cannot combine partial application and unpacking %s on line %d
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Partial application compile errors: mix application with unpack (placeholder before)
3+
--FILE--
4+
<?php
5+
foo(..., ...["foo" => "bar"]);
6+
?>
7+
--EXPECTF--
8+
Fatal error: Cannot combine partial application and unpacking %s on line %d
9+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Partial application errors: placeholder count errors
3+
--FILE--
4+
<?php
5+
function foo($a, $b, $c) {
6+
7+
}
8+
9+
try {
10+
foo(?);
11+
} catch (Error $ex) {
12+
printf("%s\n", $ex->getMessage());
13+
}
14+
15+
try {
16+
foo(?, ?, ?, ?);
17+
} catch (Error $ex) {
18+
printf("%s\n", $ex->getMessage());
19+
}
20+
21+
try {
22+
property_exists(?);
23+
} catch (Error $ex) {
24+
printf("%s\n", $ex->getMessage());
25+
}
26+
27+
try {
28+
usleep(?, ?);
29+
} catch (Error $ex) {
30+
printf("%s\n", $ex->getMessage());
31+
}
32+
?>
33+
--EXPECTF--
34+
not enough arguments or placeholders for application of foo, 1 given and exactly 3 expected, declared in %s on line 2
35+
too many arguments or placeholders for application of foo, 4 given and a maximum of 3 expected, declared in %s on line 2
36+
not enough arguments or placeholders for application of property_exists, 1 given and exactly 2 expected
37+
too many arguments or placeholders for application of usleep, 2 given and a maximum of 1 expected
38+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Partial application errors: named parameter overwrites placeholder
3+
--FILE--
4+
<?php
5+
function foo($a) {
6+
7+
}
8+
9+
try {
10+
foo(?, a: 1);
11+
} catch (Error $ex) {
12+
printf("%s\n", $ex->getMessage());
13+
}
14+
?>
15+
--EXPECT--
16+
Named parameter $a overwrites previous placeholder
17+

0 commit comments

Comments
 (0)