Skip to content

Commit 3b785fd

Browse files
committed
Partial function application groundwork and first-class callable fixes
2 parents 4a5c160 + 7c85795 commit 3b785fd

133 files changed

Lines changed: 1894 additions & 435 deletions

File tree

Some content is hidden

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

‎build/PHPStan/Build/TurboAttributeCollector.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpParser\Comment\Doc;
1010
use PhpParser\Node;
1111
use PhpParser\Node\Arg;
12+
use PhpParser\Node\ArgPlaceholder;
1213
use PhpParser\Node\ArrayItem;
1314
use PhpParser\Node\Expr;
1415
use PhpParser\Node\Expr\Array_;
@@ -254,6 +255,7 @@ final class TurboAttributeCollector
254255
'newExpr' => New_::class,
255256
'classStmt' => Class_::class,
256257
'variadicPlaceholder' => VariadicPlaceholder::class,
258+
'argPlaceholder' => ArgPlaceholder::class,
257259
'scalar' => Scalar::class,
258260
'arrayExpr' => Array_::class,
259261
'unaryMinus' => UnaryMinus::class,

‎build/collision-detector.json‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
"../tests/PHPStan/Levels/data/stubs/function.php",
1919
"../tests/PHPStan/Rules/Properties/data/abstract-final-property-hook-parse-error.php",
2020
"../tests/PHPStan/Rules/Properties/data/final-property-hooks.php",
21-
"../tests/PHPStan/Rules/Cast/data/void-cast.php"
21+
"../tests/PHPStan/Rules/Cast/data/void-cast.php",
22+
"../tests/PHPStan/Analyser/data/bug-15364.php",
23+
"../tests/PHPStan/Analyser/data/partial-function-application-positions.php",
24+
"../tests/PHPStan/Rules/Functions/data/function-callable-dynamic-call-forbidden.php",
25+
"../tests/PHPStan/Rules/Functions/data/function-partial-function-application.php",
26+
"../tests/PHPStan/Rules/Methods/data/method-partial-function-application.php",
27+
"../tests/PHPStan/Rules/Variables/data/partial-function-application.php",
28+
"../tests/PHPStan/Rules/DeadCode/data/partial-function-application-bound-args.php",
29+
"../tests/PHPStan/Rules/Exceptions/data/dead-catch-partial-function-application.php",
30+
"../tests/PHPStan/Rules/Functions/data/partial-function-application-bound-args.php",
31+
"../tests/PHPStan/Rules/Pure/data/partial-function-application-pure.php"
2232
]
2333
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--- src/Dep.php
2+
+++ src/Dep.php
3+
@@ -5,9 +5,9 @@
4+
class Dep
5+
{
6+
7+
- public static function value(): string
8+
+ public static function value(): int
9+
{
10+
- return 'a';
11+
+ return 1;
12+
}
13+
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: 8
3+
phpVersion: 80600
4+
tmpDir: tmp
5+
paths:
6+
- src
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
# @tags result-cache
3+
4+
function set_up() {
5+
e2e::set_up
6+
}
7+
8+
function tear_down() {
9+
e2e::tear_down
10+
}
11+
12+
function test_result_cache_partial_function_application() {
13+
OUTPUT=$(../../bin/phpstan analyse -vv --error-format raw 2>&1) && CODE=0 || CODE=$?
14+
echo "$OUTPUT"
15+
assert_same "0" "$CODE"
16+
# The bound arguments of a partial function application are evaluated when the
17+
# closure is created, so a file binding Dep::value() depends on Dep.php - through
18+
# a function, a method and a static method alike. Unrelated.php does not.
19+
patch -b src/Dep.php < dep.patch
20+
INFO=$(../../bin/phpstan result-cache-info --json)
21+
echo "$INFO"
22+
assert_equals 'true' "$(echo "$INFO" | jq --raw-output '.resultCacheUsed')"
23+
assert_equals '4' "$(echo "$INFO" | jq --raw-output '.filesToAnalyseCount')"
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace ResultCacheE2EPartialFunctionApplication;
4+
5+
class Dep
6+
{
7+
8+
public static function value(): string
9+
{
10+
return 'a';
11+
}
12+
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace ResultCacheE2EPartialFunctionApplication;
4+
5+
class Foo
6+
{
7+
8+
public function m(string $a, string $b): string
9+
{
10+
return $a . $b;
11+
}
12+
13+
public static function s(string $a, string $b): string
14+
{
15+
return $a . $b;
16+
}
17+
18+
}
19+
20+
function f(string $a, string $b): string
21+
{
22+
return $a . $b;
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace ResultCacheE2EPartialFunctionApplication;
4+
5+
function bindToFunction(): \Closure
6+
{
7+
return f(Dep::value(), ?);
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace ResultCacheE2EPartialFunctionApplication;
4+
5+
function bindToMethod(Foo $foo): \Closure
6+
{
7+
return $foo->m(Dep::value(), ?);
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace ResultCacheE2EPartialFunctionApplication;
4+
5+
function bindToStaticMethod(): \Closure
6+
{
7+
return Foo::s(?, Dep::value());
8+
}

0 commit comments

Comments
 (0)