From 866af5a3593bd0ae29c7c9d421dfac427eb7321a Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Tue, 10 Nov 2026 18:02:50 +0000 Subject: [PATCH 01/20] Infer the closure signature of partial function applications PartialFunctionApplicationParameters maps the callee's parameters to the closure's following PHP 8.6: positional placeholders, then named ones in the order written, then what ... adds; a ? is required, ... keeps optionality and the variadic; a ? past the declared parameters of a variadic callee is named after the variadic ($rest0, $rest1, ...). createFirstClassCallable() applies it to every variant and drops the variants whose partial application throws when created; when none is left, the closure stays a plain Closure. The native twins call the same PHP helper, which runs only for partial applications. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- build/collision-detector.json | 4 +- .../Virtual/FunctionCallableNodeHandler.php | 8 +- .../Virtual/MethodCallableNodeHandler.php | 5 +- .../InitializerExprTypeResolver.php | 26 +- .../PartialFunctionApplicationParameters.php | 183 ++++++++++++++ ...partial-function-application-signature.php | 152 ++++++++++++ .../Rules/Functions/CallCallablesRuleTest.php | 31 +++ ...ial-function-application-closure-calls.php | 40 ++++ turbo-ext/src/FunctionCallableNodeHandler.cpp | 20 +- turbo-ext/src/InitializerExprTypeResolver.cpp | 63 +++-- turbo-ext/src/MethodCallableNodeHandler.cpp | 18 +- turbo-ext/src/VirtualExprHandlers.h | 6 +- .../generated/InitializerExprTypeResolver.h | 224 +++++++++--------- turbo-ext/src/support.cpp | 1 + turbo-ext/src/support.h | 7 +- 15 files changed, 626 insertions(+), 162 deletions(-) create mode 100644 src/Reflection/PartialFunctionApplicationParameters.php create mode 100644 tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php create mode 100644 tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php diff --git a/build/collision-detector.json b/build/collision-detector.json index 7ac9a60bd96..efc4e013c0f 100644 --- a/build/collision-detector.json +++ b/build/collision-detector.json @@ -29,6 +29,8 @@ "../tests/PHPStan/Rules/DeadCode/data/partial-function-application-bound-args.php", "../tests/PHPStan/Rules/Exceptions/data/dead-catch-partial-function-application.php", "../tests/PHPStan/Rules/Functions/data/partial-function-application-bound-args.php", - "../tests/PHPStan/Rules/Pure/data/partial-function-application-pure.php" + "../tests/PHPStan/Rules/Pure/data/partial-function-application-pure.php", + "../tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php", + "../tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php" ] } diff --git a/src/Analyser/ExprHandler/Virtual/FunctionCallableNodeHandler.php b/src/Analyser/ExprHandler/Virtual/FunctionCallableNodeHandler.php index d454a9b55f6..f75dccaba97 100644 --- a/src/Analyser/ExprHandler/Virtual/FunctionCallableNodeHandler.php +++ b/src/Analyser/ExprHandler/Virtual/FunctionCallableNodeHandler.php @@ -150,10 +150,6 @@ private function getDependencies(MutatingScope $scope, FunctionCallableNode $exp private function resolveType(MutatingScope $scope, FunctionCallableNode $expr, ?ExpressionResult $nameResult): Type { $originalNode = $expr->getOriginalNode(); - if (!$originalNode->isFirstClassCallable()) { - // the signature of a partial function application is not inferred yet - return new ObjectType(Closure::class); - } if ($originalNode->name instanceof Expr) { // $originalNode->name is the same node as $expr->getName(), processed // in processExpr exactly in this branch - read its ExpressionResult @@ -161,7 +157,8 @@ private function resolveType(MutatingScope $scope, FunctionCallableNode $expr, ? throw new ShouldNotHappenException(); } $callableType = $nameResult->getTypeOnScope($scope, $scope->nativeTypesPromoted); - if (self::isClosureObject($callableType)) { + $isFirstClassCallable = $originalNode->isFirstClassCallable(); + if ($isFirstClassCallable && self::isClosureObject($callableType)) { // the first-class callable of a closure object is the object itself return $callableType; } @@ -173,6 +170,7 @@ private function resolveType(MutatingScope $scope, FunctionCallableNode $expr, ? null, $callableType->getCallableParametersAcceptors($scope), $scope->nativeTypesPromoted, + $isFirstClassCallable ? null : $originalNode->getRawArgs(), ); } diff --git a/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php b/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php index 3e09dad7691..b4aefd75347 100644 --- a/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php +++ b/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php @@ -145,10 +145,6 @@ private function resolveType(MutatingScope $scope, MethodCallableNode $expr, Exp if (!$originalNode->name instanceof Identifier) { return new ObjectType(Closure::class); } - if (!$originalNode->isFirstClassCallable()) { - // the signature of a partial function application is not inferred yet - return new ObjectType(Closure::class); - } // $originalNode->var is the same node as $expr->getVar(), processed in // processExpr - read its ExpressionResult instead of Scope::getType() @@ -162,6 +158,7 @@ private function resolveType(MutatingScope $scope, MethodCallableNode $expr, Exp $method, $method->getVariants(), $scope->nativeTypesPromoted, + $originalNode->isFirstClassCallable() ? null : $originalNode->getRawArgs(), ); } diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index be6369d447d..b7917ce07a5 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -4,6 +4,7 @@ use Closure; use PhpParser\Node\Arg; +use PhpParser\Node\ArgPlaceholder; use PhpParser\Node\ComplexType; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp; @@ -27,6 +28,7 @@ use PhpParser\Node\Scalar\MagicConst\File; use PhpParser\Node\Scalar\MagicConst\Line; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\VariadicPlaceholder; use PHPStan\Analyser\ConstantResolver; use PHPStan\Analyser\OutOfClassScope; use PHPStan\Analyser\ValueDependencyCollector; @@ -790,10 +792,7 @@ private function isParameterValueNullable(Param $parameter): bool public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprContext $context, bool $nativeTypesPromoted): Type { - if (!$expr->isFirstClassCallable()) { - // the signature of a partial function application is not inferred yet - return new ObjectType(Closure::class); - } + $partialApplicationArgs = $expr->isFirstClassCallable() ? null : $expr->getRawArgs(); if ($expr instanceof FuncCall) { if ($expr->name instanceof Name) { @@ -803,6 +802,7 @@ public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprCo $function, $function->getVariants(), $nativeTypesPromoted, + $partialApplicationArgs, ); } @@ -841,6 +841,7 @@ public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprCo $method, $method->getVariants(), $nativeTypesPromoted, + $partialApplicationArgs, ); } @@ -853,11 +854,13 @@ public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprCo /** * @param ParametersAcceptor[] $variants + * @param array|null $partialApplicationArgs the arguments of a partial function application, null for a first-class callable */ public function createFirstClassCallable( FunctionReflection|ExtendedMethodReflection|null $function, array $variants, bool $nativeTypesPromoted, + ?array $partialApplicationArgs = null, ): Type { // variants of multi-variant built-ins carry functionMap parameter names, @@ -935,6 +938,15 @@ public function createFirstClassCallable( if (count($namedArgumentNames) > 0) { $parameters = self::renameParameters($parameters, $namedArgumentNames); } + $isVariadic = $variant->isVariadic(); + if ($partialApplicationArgs !== null) { + $partialApplication = PartialFunctionApplicationParameters::apply($parameters, $partialApplicationArgs); + if ($partialApplication === null) { + // creating the closure from this variant throws + continue; + } + [$parameters, $isVariadic] = $partialApplication; + } if ($function !== null) { $assertions = $function->getAsserts(); } elseif ($variant instanceof CallableParametersAcceptor) { @@ -950,7 +962,7 @@ public function createFirstClassCallable( $closureTypes[] = new ClosureType( $parameters, $returnType, - $variant->isVariadic(), + $isVariadic, $variant->getTemplateTypeMap(), $variant->getResolvedTemplateTypeMap(), $variant instanceof ExtendedParametersAcceptor ? $variant->getCallSiteVarianceMap() : TemplateTypeVarianceMap::createEmpty(), @@ -964,6 +976,10 @@ public function createFirstClassCallable( ); } + if ($partialApplicationArgs !== null && count($closureTypes) === 0) { + return new ObjectType(Closure::class); + } + return TypeCombinator::union(...$closureTypes); } diff --git a/src/Reflection/PartialFunctionApplicationParameters.php b/src/Reflection/PartialFunctionApplicationParameters.php new file mode 100644 index 00000000000..03896a8980e --- /dev/null +++ b/src/Reflection/PartialFunctionApplicationParameters.php @@ -0,0 +1,183 @@ + $parameters + * @param array $args + * @return array{list, bool}|null the closure's parameters and whether it is variadic, + * null when creating the closure throws + */ + public static function apply(array $parameters, array $args): ?array + { + $variadicParameter = null; + $declared = $parameters; + if (count($parameters) > 0 && $parameters[count($parameters) - 1]->isVariadic()) { + $variadicParameter = $parameters[count($parameters) - 1]; + unset($declared[count($parameters) - 1]); + } + + $indexesByName = []; + foreach ($declared as $i => $parameter) { + $indexesByName[$parameter->getName()] = $i; + } + + $positional = []; + $named = []; + $covered = []; + $hasVariadicPlaceholder = false; + $position = 0; + $variadicPlaceholders = 0; + $seenNamed = false; + foreach ($args as $arg) { + if ($arg instanceof VariadicPlaceholder) { + $hasVariadicPlaceholder = true; + continue; + } + if ($hasVariadicPlaceholder) { + // the variadic placeholder must be last + return null; + } + + if ($arg instanceof Arg && $arg->unpack) { + // cannot combine partial application and unpacking + return null; + } + + $isPlaceholder = $arg instanceof ArgPlaceholder; + $name = $arg->name; + if ($name === null) { + if ($seenNamed) { + // positional argument after a named one + return null; + } + if (isset($declared[$position])) { + $covered[$position] = true; + if ($isPlaceholder) { + $positional[] = self::required($declared[$position], $declared[$position]->getName()); + } + } elseif ($variadicParameter !== null) { + if ($isPlaceholder) { + $positional[] = self::required($variadicParameter, $variadicParameter->getName() . $variadicPlaceholders); + $variadicPlaceholders++; + } + } else { + // too many arguments + return null; + } + $position++; + continue; + } + + $seenNamed = true; + $nameString = $name->toString(); + if (!array_key_exists($nameString, $indexesByName)) { + if ($isPlaceholder || $variadicParameter === null) { + // a named placeholder for an unknown or variadic parameter, + // or an unknown named argument without a variadic to collect it + return null; + } + continue; + } + + $index = $indexesByName[$nameString]; + if (isset($covered[$index])) { + // overwrites a previous argument or placeholder + return null; + } + $covered[$index] = true; + if (!$isPlaceholder) { + continue; + } + + $named[] = self::required($declared[$index], $nameString); + } + + $closureParameters = [...$positional, ...$named]; + if (!$hasVariadicPlaceholder) { + foreach ($declared as $i => $parameter) { + if (!isset($covered[$i]) && !$parameter->isOptional()) { + // too few arguments + return null; + } + } + + return [$closureParameters, false]; + } + + foreach ($declared as $i => $parameter) { + if (isset($covered[$i])) { + continue; + } + $closureParameters[] = $parameter; + } + if ($variadicParameter !== null) { + $closureParameters[] = $variadicParameter; + } + + return [$closureParameters, $variadicParameter !== null]; + } + + private static function required(ParameterReflection $parameter, string $name): ParameterReflection + { + if ($parameter instanceof ExtendedParameterReflection) { + return new ExtendedDummyParameter( + $name, + $parameter->getType(), + false, + $parameter->passedByReference(), + false, + null, + $parameter->getNativeType(), + $parameter->getPhpDocType(), + $parameter->getOutType(), + $parameter->isImmediatelyInvokedCallable(), + $parameter->getClosureThisType(), + $parameter->getAttributes(), + $parameter->getAllowedConstants(), + $parameter->isPureUnlessCallableIsImpureParameter(), + $parameter->isPureUnlessParameterPassedParameter(), + ); + } + + return new DummyParameter( + $name, + $parameter->getType(), + false, + $parameter->passedByReference(), + false, + null, + ); + } + +} diff --git a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php new file mode 100644 index 00000000000..d56afb066d8 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php @@ -0,0 +1,152 @@ += 8.6 + +declare(strict_types = 1); + +namespace PartialFunctionApplicationSignature; + +use function PHPStan\Testing\assertType; + +function doFoo(int $a, string $b, float $c, bool ...$d): string +{ + return ''; +} + +function opt(int $a, string $b = 'B', float $c = 1.0): int +{ + return 1; +} + +function none(): void +{ +} + +function byRef(int &$a, string $b): void +{ +} + +function withNullableDefault(?int $a = null, string ...$rest): void +{ +} + +/** + * @template T + * @param T $a + * @return T + */ +function identity($a) +{ + return $a; +} + +class Foo +{ + + public function doFoo(int $a, string $b, float ...$c): bool + { + return true; + } + + public static function doStatic(int $a, string $b = 'x'): int + { + return 1; + } + +} + +class Invokable +{ + + public function __invoke(int $a, string $b): bool + { + return true; + } + +} + +class Constants +{ + + const PARTIAL = doFoo(1, ?, ...); + +} + +function functions(): void +{ + // the cases checked against PHP 8.6 + assertType('Closure(float, bool ...): string', doFoo(1, 'b', ...)); + assertType('Closure(string, float, bool ...): string', doFoo(1, ?, ...)); + assertType('Closure(string, bool ...): string', doFoo(1, ?, 3.0, ...)); + assertType('Closure(string, bool ...): string', doFoo(1, ?, 3.0, true, ...)); + assertType('Closure(bool ...): string', doFoo(1, 'b', 3.0, ...)); + assertType('Closure(string): string', doFoo(1, ?, 3.0)); + assertType('Closure(string): string', doFoo(1, ?, 3.0, true)); + assertType('Closure(bool): string', doFoo(1, 'b', 3.0, true, ?)); + assertType('Closure(bool, bool): string', doFoo(1, 'b', 3.0, ?, ?)); + assertType('Closure(bool, bool ...): string', doFoo(1, 'b', 3.0, ?, ...)); + assertType('Closure(bool ...): string', doFoo(1, 'b', 3.0, x: true, ...)); + + // a placeholder is required even for an optional parameter, ... keeps the optionality + assertType('Closure(int): int', opt(?)); + assertType('Closure(int, string): int', opt(?, ?)); + assertType('Closure(string=, float=): int', opt(1, ...)); + assertType('Closure(): int', opt(1, 'b', 2.0, ...)); + assertType('Closure(int|null, string ...): void', withNullableDefault(?, ...)); + + // named placeholders come after the positional ones, in the order they are written, + // and before what ... adds + assertType('Closure(float, int, string): string', doFoo(c: ?, a: ?, b: ?)); + assertType('Closure(int, float, string, bool ...): string', doFoo(?, c: ?, ...)); + assertType('Closure(string, int, float=): int', opt(b: ?, ...)); + assertType('Closure(int): int', opt(?, c: 2.0)); + + // by-ref is kept + assertType('Closure(int, string): void', byRef(?, ?)); + + // the partial application throws when it is created + assertType('Closure', doFoo(1, ?)); + assertType('Closure', none(?)); + assertType('Closure', none(1, ...)); + assertType('Closure', opt(1, 'b', 2.0, ?)); + assertType('Closure', opt(x: ?)); + assertType('Closure', doFoo(1, 'b', 3.0, d: ?)); + assertType('Closure', opt(?, a: 1)); + assertType('Closure', opt(a: ?, a: ?)); + + // built-ins + assertType('Closure(string): (non-empty-string|false)', strtok(?)); + assertType('Closure(string, string): (non-empty-string|false)', strtok(?, ?)); + assertType('Closure(string): int<0, max>', strlen(?)); + assertType('Closure', mt_rand(?)); + + // templates + assertType('Closure(T): T', identity(?)); +} + +function methods(Foo $foo): void +{ + assertType('Closure(string): bool', $foo->doFoo(1, ?)); + assertType('Closure(float, float): bool', $foo->doFoo(1, 'b', ?, ?)); + assertType('Closure(string, float ...): bool', $foo->doFoo(1, ...)); + assertType('Closure', $foo->doFoo(?)); + + assertType('Closure(int): int', Foo::doStatic(?)); + assertType('Closure(int, string=): int', Foo::doStatic(?, ...)); + assertType('Closure(string): int', Foo::doStatic(1, ?)); + assertType('Closure', Foo::doStatic(1, 'b', ?)); +} + +function closures(Invokable $i): void +{ + assertType('Closure(string): bool', $i(1, ?)); + assertType('Closure(int): bool', $i->__invoke(?, 'x')); + assertType('Closure(string, float, bool ...): string', Constants::PARTIAL); + + $c = fn (int $a, string $b, float $c = 1.0): int => 1; + assertType('Closure(string): 1', $c(1, ?)); + assertType('Closure(string, float=): 1', $c(1, ...)); + assertType('Closure', $c(?)); + + $d = doFoo(1, ?, ...); + assertType('Closure(string): string', $d(?, 3.0)); + assertType('Closure(bool): string', $d('b', 3.0, ?)); +} diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index ce9a3cc7ab5..a0dbda702ac 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -493,6 +493,37 @@ public function testBug15442(): void $this->analyse([__DIR__ . '/data/bug-15442.php'], []); } + #[RequiresPhp('>= 8.1.0')] + public function testPartialFunctionApplicationClosureCalls(): void + { + $this->analyse([__DIR__ . '/data/partial-function-application-closure-calls.php'], [ + [ + 'Missing parameter $d0 (bool) in call to closure.', + 24, + ], + [ + 'Missing parameter $d1 (bool) in call to closure.', + 24, + ], + [ + 'Unknown parameter $d in call to closure.', + 24, + ], + [ + 'Parameter $rest0 of closure expects int, string given.', + 29, + ], + [ + 'Closure invoked with 1 parameter, 2 required.', + 33, + ], + [ + 'Parameter #2 $a of closure expects int, float given.', + 39, + ], + ]); + } + #[RequiresPhp('>= 8.1.0')] public function testBug15235(): void { diff --git a/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php b/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php new file mode 100644 index 00000000000..3e9d11a0ac0 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php @@ -0,0 +1,40 @@ += 8.6 + +declare(strict_types = 1); + +namespace PartialFunctionApplicationClosureCalls; + +function doFoo(int $a, string $b, float $c, bool ...$d): string +{ + return ''; +} + +/** + * @param int ...$rest + */ +function opt(int $a, string $b = 'B', int ...$rest): void +{ +} + +function test(): void +{ + // a ? landing in the variadic is named after it: $d0, $d1, ... + $f = doFoo(1, 'b', 3.0, ?, ?); + $f(d0: true, d1: false); + $f(d: true); + + $g = opt(1, 'b', ?, ...); + $g(rest0: 1); + $g(1, 2, 3); + $g(rest0: 'x'); + + // a ? is required even for an optional parameter, and keeps its name + $h = opt(?, ?); + $h(1); + $h(a: 1, b: 'x'); + + // named placeholders come first after the positional ones + $i = doFoo(c: ?, a: ?, b: ?); + $i(1.0, 1, 'b'); + $i(1, 1.0, 'b'); +} diff --git a/turbo-ext/src/FunctionCallableNodeHandler.cpp b/turbo-ext/src/FunctionCallableNodeHandler.cpp index ba9339cb1e0..bfb34cf140d 100644 --- a/turbo-ext/src/FunctionCallableNodeHandler.cpp +++ b/turbo-ext/src/FunctionCallableNodeHandler.cpp @@ -255,12 +255,6 @@ class FunctionCallableNodeHandler zv::Val originalNodeHold; zval *originalNode = ptveh::getterRead(ptveh::functionCallableNodeOriginalNode, expr, PT_LC("getoriginalnode"), originalNodeHold); if (UNEXPECTED(originalNode == NULL)) return zv::Val(); - bool firstClassCallable; - if (UNEXPECTED(!pt_call_like_is_first_class_callable(Z_OBJ_P(originalNode), firstClassCallable))) return zv::Val(); - if (!firstClassCallable) { - // the signature of a partial function application is not inferred yet - return ptveh::closureObjectType(); - } zval *originalName = ptveh::nodeRead(ptveh::funcCallName, originalNode); if (UNEXPECTED(originalName == NULL)) return zv::Val(); int originalNameIsExpr = ptveh::isInstance(originalName, PT_CLASS_EXPR); @@ -279,8 +273,10 @@ class FunctionCallableNodeHandler if (UNEXPECTED(!pt_mutating_scope_native_types_promoted(Z_OBJ_P(scope), nativeTypesPromoted))) return zv::Val(); zv::Val callableType = pt_expression_result_get_type_on_scope(nameResult, scope, nativeTypesPromoted); if (UNEXPECTED(callableType.isUndef())) return zv::Val(); - bool closureObject; - if (UNEXPECTED(!ptveh::isClosureObject(callableType.raw(), closureObject))) return zv::Val(); + bool firstClassCallable; + if (UNEXPECTED(!pt_call_like_is_first_class_callable(Z_OBJ_P(originalNode), firstClassCallable))) return zv::Val(); + bool closureObject = false; + if (firstClassCallable && UNEXPECTED(!ptveh::isClosureObject(callableType.raw(), closureObject))) return zv::Val(); if (closureObject) { // the first-class callable of a closure object is the object itself return callableType; @@ -296,7 +292,13 @@ class FunctionCallableNodeHandler if (UNEXPECTED(!pt_mutating_scope_native_types_promoted(Z_OBJ_P(scope), nativeTypesPromoted))) return zv::Val(); zval null = {}; ZVAL_NULL(&null); - return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), &null, acceptors.raw(), nativeTypesPromoted); + zval *partialApplicationArgs = &null; + zv::Val rawArgsHold; + if (!firstClassCallable) { + partialApplicationArgs = pt_call_like_raw_args(Z_OBJ_P(originalNode), rawArgsHold); + if (UNEXPECTED(partialApplicationArgs == NULL)) return zv::Val(); + } + return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), &null, acceptors.raw(), nativeTypesPromoted, partialApplicationArgs); } zv::Val initializerExprContext = ptveh::initializerExprContextFromScope(scope); diff --git a/turbo-ext/src/InitializerExprTypeResolver.cpp b/turbo-ext/src/InitializerExprTypeResolver.cpp index b97bd81ba40..2d75a8316d8 100644 --- a/turbo-ext/src/InitializerExprTypeResolver.cpp +++ b/turbo-ext/src/InitializerExprTypeResolver.cpp @@ -2169,9 +2169,13 @@ class InitializerExprTypeResolver { bool firstClassCallable; if (UNEXPECTED(!pt_call_like_is_first_class_callable(Z_OBJ_P(expr), firstClassCallable))) return zv::Val(); + zval nullArgs; + ZVAL_NULL(&nullArgs); + zval *partialApplicationArgs = &nullArgs; + zv::Val rawArgsHold; if (!firstClassCallable) { - // the signature of a partial function application is not inferred yet - return newObjectTypeLiteral(PT_LC("Closure")); + partialApplicationArgs = pt_call_like_raw_args(Z_OBJ_P(expr), rawArgsHold); + if (UNEXPECTED(partialApplicationArgs == NULL)) return zv::Val(); } int isFuncCall = isAClass(expr, PT_CLASS_FUNC_CALL); @@ -2191,7 +2195,7 @@ class InitializerExprTypeResolver IETR_VAL(reflectionProvider, reflectionProviderOf(prop(slots::reflectionProviderProvider))); IETR_VAL(function, pt_reflection_provider_get_function(reflectionProvider.raw(), name, context)); IETR_VAL(variants, callOn(function.raw(), mGetVariants)); - return createFirstClassCallable(function.raw(), variants.raw(), nativeTypesPromoted); + return createFirstClassCallable(function.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs); } return newObjectTypeLiteral(PT_LC("Closure")); @@ -2267,7 +2271,7 @@ class InitializerExprTypeResolver } IETR_VAL(variants, callOn(method.raw(), mGetVariants)); - return createFirstClassCallable(method.raw(), variants.raw(), nativeTypesPromoted); + return createFirstClassCallable(method.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs); } int isNew = isAClass(expr, PT_CLASS_NEW); @@ -2333,9 +2337,10 @@ class InitializerExprTypeResolver return zv::Val(std::move(renamed)); } - /* Mirrors createFirstClassCallable(); $function PHP null for null */ - static zv::Val createFirstClassCallable(zval *function, zval *variants, bool nativeTypesPromoted) + /* Mirrors createFirstClassCallable(); $function and $partialApplicationArgs PHP null for null */ + static zv::Val createFirstClassCallable(zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs) { + bool partialApplication = Z_TYPE_P(partialApplicationArgs) != IS_NULL; if (UNEXPECTED(Z_TYPE_P(variants) != IS_ARRAY)) { zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(variants)); if (UNEXPECTED(EG(exception) != NULL)) return zv::Val(); @@ -2480,6 +2485,26 @@ class InitializerExprTypeResolver IETR_VAL(renamedParameters, renameParameters(parameters.raw(), namedArgumentNames.raw())); parameters = std::move(renamedParameters); } + IETR_VAL(isVariadicHold, callOn(variant, mIsVariadic)); + bool isVariadic = zend_is_true(isVariadicHold.raw()); + if (partialApplication) { + static pt_method_site applySite; + zv::Args applyArgv{parameters.raw(), partialApplicationArgs}; + IETR_VAL(applied, pt_call_static_cached(applySite, PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS, PT_LC("apply"), 2, applyArgv)); + if (Z_TYPE_P(applied.raw()) == IS_NULL) { + // creating the closure from this variant throws + continue; + } + if (UNEXPECTED(!requireArray(applied.raw()))) return zv::Val(); + zval *appliedParameters = zend_hash_index_find(Z_ARRVAL_P(applied.raw()), 0); + zval *appliedIsVariadic = zend_hash_index_find(Z_ARRVAL_P(applied.raw()), 1); + if (UNEXPECTED(appliedParameters == NULL || appliedIsVariadic == NULL)) { + pt_throw_should_not_happen(); + return zv::Val(); + } + parameters = zv::Val::copyOf(zv::Ref(appliedParameters)); + isVariadic = zend_is_true(appliedIsVariadic); + } zv::Val assertions; if (hasFunction) { assertions = callOn(function, mGetAsserts); @@ -2494,7 +2519,6 @@ class InitializerExprTypeResolver // like @return ($value is int ? true : false) on is_int(), // also becomes a type predicate of the resulting Closure IETR_VAL(predicateAssertions, withConditionalReturnPredicate(assertions.raw(), variant)); - IETR_VAL(isVariadicHold, callOn(variant, mIsVariadic)); IETR_VAL(templateTypeMap, callOn(variant, mGetTemplateTypeMap)); IETR_VAL(resolvedTemplateTypeMap, callOn(variant, mGetResolvedTemplateTypeMap)); zv::Val callSiteVarianceMap = extendedAcceptor @@ -2506,7 +2530,7 @@ class InitializerExprTypeResolver &closureType, parameters.raw(), returnType.raw(), - zend_is_true(isVariadicHold.raw()), + isVariadic, templateTypeMap.raw(), resolvedTemplateTypeMap.raw(), callSiteVarianceMap.raw(), @@ -2523,6 +2547,10 @@ class InitializerExprTypeResolver closureTypes.push(zv::Val::adopt(closureType)); } + if (partialApplication && zend_hash_num_elements(closureTypes.table()) == 0) { + return newObjectTypeLiteral(PT_LC("Closure")); + } + return unionOf(closureTypes); } @@ -3480,12 +3508,12 @@ zv::Val pt_initializer_expr_type_resolver_get_first_class_callable_type(zval *re return callResolverMethod(site, resolver, PT_LC("getfirstclasscallabletype"), 3, argv); } -zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted) +zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs) { - if (EXPECTED(isNativeResolver(resolver))) return InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted); + if (EXPECTED(isNativeResolver(resolver))) return InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted, partialApplicationArgs); static pt_method_site site; - zv::Args argv{function, variants, nativeTypesPromoted}; - return callResolverMethod(site, resolver, PT_LC("createfirstclasscallable"), 3, argv); + zv::Args argv{function, variants, nativeTypesPromoted, partialApplicationArgs}; + return callResolverMethod(site, resolver, PT_LC("createfirstclasscallable"), 4, argv); } zv::Val pt_initializer_expr_type_resolver_get_class_const_fetch_type_by_reflection(zval *resolver, zval *class_, zval *constantName, zval *classReflection, const pt_ietr_get_type &getTypeCallback, bool nativeTypesPromoted) @@ -3701,9 +3729,14 @@ PT_MINIT_REGISTRATION(pt_register_initializer_expr_type_resolver) }); cls.method(sigs::createFirstClassCallable, [](INTERNAL_FUNCTION_PARAMETERS) { - zval *function, *variants; + zval *function, *variants, *partialApplicationArgs = NULL; bool nativeTypesPromoted; - if (!zp::parse(execute_data, function, variants, nativeTypesPromoted)) RETURN_THROWS(); + if (!zp::parse>(execute_data, function, variants, nativeTypesPromoted, partialApplicationArgs)) RETURN_THROWS(); + zval nullArgs; + if (partialApplicationArgs == NULL) { + ZVAL_NULL(&nullArgs); + partialApplicationArgs = &nullArgs; + } zval nullFunction; if (function == NULL) { ZVAL_NULL(&nullFunction); @@ -3717,7 +3750,7 @@ PT_MINIT_REGISTRATION(pt_register_initializer_expr_type_resolver) RETURN_THROWS(); } } - PT_RETURN_VAL(InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted)); + PT_RETURN_VAL(InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted, partialApplicationArgs)); }); cls.method(sigs::getBitwiseAndType, IETR_OPERATOR_GLUE(self.getOperatorType(IETR_BITWISE_AND, left, right, getTypeCallback))); diff --git a/turbo-ext/src/MethodCallableNodeHandler.cpp b/turbo-ext/src/MethodCallableNodeHandler.cpp index 0f27b68c1c4..cfa6c1ca145 100644 --- a/turbo-ext/src/MethodCallableNodeHandler.cpp +++ b/turbo-ext/src/MethodCallableNodeHandler.cpp @@ -237,12 +237,6 @@ class MethodCallableNodeHandler if (!originalNameIsIdentifier) { return ptveh::closureObjectType(); } - bool firstClassCallable; - if (UNEXPECTED(!pt_call_like_is_first_class_callable(Z_OBJ_P(originalNode), firstClassCallable))) return zv::Val(); - if (!firstClassCallable) { - // the signature of a partial function application is not inferred yet - return ptveh::closureObjectType(); - } // $originalNode->var is the same node as $expr->getVar(), processed in // processExpr - read its ExpressionResult instead of Scope::getType() @@ -265,7 +259,17 @@ class MethodCallableNodeHandler zv::Val variants = pt_extended_method_reflection_call(method.raw(), PT_MR_GET_VARIANTS); if (UNEXPECTED(variants.isUndef())) return zv::Val(); if (UNEXPECTED(!pt_mutating_scope_native_types_promoted(Z_OBJ_P(scope), nativeTypesPromoted))) return zv::Val(); - return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), method.raw(), variants.raw(), nativeTypesPromoted); + bool firstClassCallable; + if (UNEXPECTED(!pt_call_like_is_first_class_callable(Z_OBJ_P(originalNode), firstClassCallable))) return zv::Val(); + zval nullArgs; + ZVAL_NULL(&nullArgs); + zval *partialApplicationArgs = &nullArgs; + zv::Val rawArgsHold; + if (!firstClassCallable) { + partialApplicationArgs = pt_call_like_raw_args(Z_OBJ_P(originalNode), rawArgsHold); + if (UNEXPECTED(partialApplicationArgs == NULL)) return zv::Val(); + } + return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), method.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs); } /* the handler entry (Engine.h) */ diff --git a/turbo-ext/src/VirtualExprHandlers.h b/turbo-ext/src/VirtualExprHandlers.h index de28871e48c..08f752759a7 100644 --- a/turbo-ext/src/VirtualExprHandlers.h +++ b/turbo-ext/src/VirtualExprHandlers.h @@ -141,10 +141,10 @@ inline zval *nodeRead(NodeProp &prop, zval *node) * once they are ported) */ -/* $initializerExprTypeResolver->createFirstClassCallable($function, $variants, $nativeTypesPromoted) */ -inline zv::Val createFirstClassCallable(zval *initializerExprTypeResolver, zval *function, zval *variants, bool nativeTypesPromoted) +/* $initializerExprTypeResolver->createFirstClassCallable($function, $variants, $nativeTypesPromoted, $partialApplicationArgs) */ +inline zv::Val createFirstClassCallable(zval *initializerExprTypeResolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs) { - return pt_initializer_expr_type_resolver_create_first_class_callable(initializerExprTypeResolver, function, variants, nativeTypesPromoted); + return pt_initializer_expr_type_resolver_create_first_class_callable(initializerExprTypeResolver, function, variants, nativeTypesPromoted, partialApplicationArgs); } /* $initializerExprTypeResolver->getFirstClassCallableType($expr, $context, $nativeTypesPromoted) */ diff --git a/turbo-ext/src/generated/InitializerExprTypeResolver.h b/turbo-ext/src/generated/InitializerExprTypeResolver.h index 6c25986814d..239f7de0676 100644 --- a/turbo-ext/src/generated/InitializerExprTypeResolver.h +++ b/turbo-ext/src/generated/InitializerExprTypeResolver.h @@ -99,57 +99,58 @@ inline constexpr char strings[] = "function\0" /* 1081 */ "PHPStan\\Reflection\\FunctionReflection|PHPStan\\Reflection\\ExtendedMethodReflection\0" /* 1090 */ "variants\0" /* 1172 */ - "createFirstClassCallable\0" /* 1181 */ - "parameters\0" /* 1206 */ - "names\0" /* 1217 */ - "renameParameters\0" /* 1223 */ - "getBitwiseAndType\0" /* 1240 */ - "getBitwiseOrType\0" /* 1258 */ - "getBitwiseXorType\0" /* 1275 */ - "getSpaceshipType\0" /* 1293 */ - "getDivType\0" /* 1310 */ - "getModType\0" /* 1321 */ - "getPlusType\0" /* 1332 */ - "getMinusType\0" /* 1344 */ - "getMulType\0" /* 1357 */ - "getPowType\0" /* 1368 */ - "getShiftLeftType\0" /* 1379 */ - "getShiftRightType\0" /* 1396 */ - "leftType\0" /* 1414 */ - "rightType\0" /* 1423 */ - "PHPStan\\Type\\TypeResult\0" /* 1433 */ - "resolveIdenticalType\0" /* 1457 */ - "resolveEqualType\0" /* 1478 */ - "isNonNumericString\0" /* 1495 */ - "PHPStan\\Type\\Constant\\ConstantArrayType\0" /* 1514 */ - "valueComparisonCallback\0" /* 1554 */ - "resolveConstantArrayTypeComparison\0" /* 1578 */ - "class\0" /* 1613 */ - "PhpParser\\Node\\Name|PhpParser\\Node\\Expr\0" /* 1619 */ - "constantName\0" /* 1659 */ - "classReflection\0" /* 1672 */ - "PHPStan\\Reflection\\ClassReflection\0" /* 1688 */ - "false\0" /* 1723 */ - "getClassConstFetchTypeByReflection\0" /* 1729 */ - "fetchedOnType\0" /* 1764 */ - "transformStaticType\0" /* 1778 */ - "getClassConstFetchType\0" /* 1798 */ - "getUnaryPlusType\0" /* 1821 */ - "getUnaryMinusType\0" /* 1838 */ - "getBitwiseNotType\0" /* 1856 */ - "getBitwiseNotTypeFromType\0" /* 1874 */ - "name\0" /* 1900 */ - "PhpParser\\Node\\Name\0" /* 1905 */ - "resolveName\0" /* 1925 */ - "PHPStan\\Type\\TypeWithClassName\0" /* 1937 */ - "resolveTypeByName\0" /* 1968 */ - "classType\0" /* 1986 */ - "methodReflectionCandidate\0" /* 1996 */ - "PHPStan\\Reflection\\MethodReflection\0" /* 2022 */ - "resolveTypeByNameWithLateStaticBinding\0" /* 2058 */ - "PHPStan\\Reflection\\ReflectionProvider\0" /* 2097 */ - "getReflectionProvider\0" /* 2135 */ - "getNeverType"; /* 2157 */ + "partialApplicationArgs\0" /* 1181 */ + "createFirstClassCallable\0" /* 1204 */ + "parameters\0" /* 1229 */ + "names\0" /* 1240 */ + "renameParameters\0" /* 1246 */ + "getBitwiseAndType\0" /* 1263 */ + "getBitwiseOrType\0" /* 1281 */ + "getBitwiseXorType\0" /* 1298 */ + "getSpaceshipType\0" /* 1316 */ + "getDivType\0" /* 1333 */ + "getModType\0" /* 1344 */ + "getPlusType\0" /* 1355 */ + "getMinusType\0" /* 1367 */ + "getMulType\0" /* 1380 */ + "getPowType\0" /* 1391 */ + "getShiftLeftType\0" /* 1402 */ + "getShiftRightType\0" /* 1419 */ + "leftType\0" /* 1437 */ + "rightType\0" /* 1446 */ + "PHPStan\\Type\\TypeResult\0" /* 1456 */ + "resolveIdenticalType\0" /* 1480 */ + "resolveEqualType\0" /* 1501 */ + "isNonNumericString\0" /* 1518 */ + "PHPStan\\Type\\Constant\\ConstantArrayType\0" /* 1537 */ + "valueComparisonCallback\0" /* 1577 */ + "resolveConstantArrayTypeComparison\0" /* 1601 */ + "class\0" /* 1636 */ + "PhpParser\\Node\\Name|PhpParser\\Node\\Expr\0" /* 1642 */ + "constantName\0" /* 1682 */ + "classReflection\0" /* 1695 */ + "PHPStan\\Reflection\\ClassReflection\0" /* 1711 */ + "false\0" /* 1746 */ + "getClassConstFetchTypeByReflection\0" /* 1752 */ + "fetchedOnType\0" /* 1787 */ + "transformStaticType\0" /* 1801 */ + "getClassConstFetchType\0" /* 1821 */ + "getUnaryPlusType\0" /* 1844 */ + "getUnaryMinusType\0" /* 1861 */ + "getBitwiseNotType\0" /* 1879 */ + "getBitwiseNotTypeFromType\0" /* 1897 */ + "name\0" /* 1923 */ + "PhpParser\\Node\\Name\0" /* 1928 */ + "resolveName\0" /* 1948 */ + "PHPStan\\Type\\TypeWithClassName\0" /* 1960 */ + "resolveTypeByName\0" /* 1991 */ + "classType\0" /* 2009 */ + "methodReflectionCandidate\0" /* 2019 */ + "PHPStan\\Reflection\\MethodReflection\0" /* 2045 */ + "resolveTypeByNameWithLateStaticBinding\0" /* 2081 */ + "PHPStan\\Reflection\\ReflectionProvider\0" /* 2120 */ + "getReflectionProvider\0" /* 2158 */ + "getNeverType"; /* 2180 */ inline constexpr reg::PackedArg args[] = { reg::packed(0, 0, 17), /* __construct $constantResolver */ reg::packed(51, 0, 78), /* __construct $reflectionProviderProvider */ @@ -197,9 +198,10 @@ inline constexpr reg::PackedArg args[] = { reg::packed(1081, MAY_BE_NULL, 1090), /* createFirstClassCallable $function */ reg::packed(1172, MAY_BE_ARRAY), /* createFirstClassCallable $variants */ reg::packed(1035, MAY_BE_BOOL), /* createFirstClassCallable $nativeTypesPromoted */ + reg::packed(1181, MAY_BE_NULL | MAY_BE_ARRAY, reg::NoString, false, false, 825), /* createFirstClassCallable $partialApplicationArgs */ reg::packed(626, 0, 627), /* createFirstClassCallable return */ - reg::packed(1206, MAY_BE_ARRAY), /* renameParameters $parameters */ - reg::packed(1217, MAY_BE_ARRAY), /* renameParameters $names */ + reg::packed(1229, MAY_BE_ARRAY), /* renameParameters $parameters */ + reg::packed(1240, MAY_BE_ARRAY), /* renameParameters $names */ reg::packed(626, MAY_BE_ARRAY), /* renameParameters return */ reg::packed(703, 0, 556), /* getBitwiseAndType $left */ reg::packed(708, 0, 556), /* getBitwiseAndType $right */ @@ -249,31 +251,31 @@ inline constexpr reg::PackedArg args[] = { reg::packed(708, 0, 556), /* getShiftRightType $right */ reg::packed(714, MAY_BE_CALLABLE), /* getShiftRightType $getTypeCallback */ reg::packed(626, 0, 627), /* getShiftRightType return */ - reg::packed(1414, 0, 627), /* resolveIdenticalType $leftType */ - reg::packed(1423, 0, 627), /* resolveIdenticalType $rightType */ - reg::packed(626, 0, 1433), /* resolveIdenticalType return */ - reg::packed(1414, 0, 627), /* resolveEqualType $leftType */ - reg::packed(1423, 0, 627), /* resolveEqualType $rightType */ + reg::packed(1437, 0, 627), /* resolveIdenticalType $leftType */ + reg::packed(1446, 0, 627), /* resolveIdenticalType $rightType */ + reg::packed(626, 0, 1456), /* resolveIdenticalType return */ + reg::packed(1437, 0, 627), /* resolveEqualType $leftType */ + reg::packed(1446, 0, 627), /* resolveEqualType $rightType */ reg::packed(789, MAY_BE_NULL, 801, false, false, 825), /* resolveEqualType $phpVersions */ - reg::packed(626, 0, 1433), /* resolveEqualType return */ + reg::packed(626, 0, 1456), /* resolveEqualType return */ reg::packed(907, 0, 627), /* isNonNumericString $type */ reg::packed(789, MAY_BE_ARRAY), /* isNonNumericString $phpVersions */ reg::packed(626, MAY_BE_BOOL), /* isNonNumericString return */ - reg::packed(1414, 0, 1514), /* resolveConstantArrayTypeComparison $leftType */ - reg::packed(1423, 0, 1514), /* resolveConstantArrayTypeComparison $rightType */ - reg::packed(1554, MAY_BE_CALLABLE), /* resolveConstantArrayTypeComparison $valueComparisonCallback */ - reg::packed(626, 0, 1433), /* resolveConstantArrayTypeComparison return */ - reg::packed(1613, 0, 1619), /* getClassConstFetchTypeByReflection $class */ - reg::packed(1659, MAY_BE_STRING), /* getClassConstFetchTypeByReflection $constantName */ - reg::packed(1672, MAY_BE_NULL, 1688), /* getClassConstFetchTypeByReflection $classReflection */ + reg::packed(1437, 0, 1537), /* resolveConstantArrayTypeComparison $leftType */ + reg::packed(1446, 0, 1537), /* resolveConstantArrayTypeComparison $rightType */ + reg::packed(1577, MAY_BE_CALLABLE), /* resolveConstantArrayTypeComparison $valueComparisonCallback */ + reg::packed(626, 0, 1456), /* resolveConstantArrayTypeComparison return */ + reg::packed(1636, 0, 1642), /* getClassConstFetchTypeByReflection $class */ + reg::packed(1682, MAY_BE_STRING), /* getClassConstFetchTypeByReflection $constantName */ + reg::packed(1695, MAY_BE_NULL, 1711), /* getClassConstFetchTypeByReflection $classReflection */ reg::packed(714, MAY_BE_CALLABLE), /* getClassConstFetchTypeByReflection $getTypeCallback */ - reg::packed(1035, MAY_BE_BOOL, reg::NoString, false, false, 1723), /* getClassConstFetchTypeByReflection $nativeTypesPromoted */ + reg::packed(1035, MAY_BE_BOOL, reg::NoString, false, false, 1746), /* getClassConstFetchTypeByReflection $nativeTypesPromoted */ reg::packed(626, 0, 627), /* getClassConstFetchTypeByReflection return */ reg::packed(907, 0, 627), /* transformStaticType $type */ - reg::packed(1764, 0, 627), /* transformStaticType $fetchedOnType */ + reg::packed(1787, 0, 627), /* transformStaticType $fetchedOnType */ reg::packed(626, 0, 627), /* transformStaticType return */ - reg::packed(1613, 0, 1619), /* getClassConstFetchType $class */ - reg::packed(1659, MAY_BE_STRING), /* getClassConstFetchType $constantName */ + reg::packed(1636, 0, 1642), /* getClassConstFetchType $class */ + reg::packed(1682, MAY_BE_STRING), /* getClassConstFetchType $constantName */ reg::packed(653, MAY_BE_NULL | MAY_BE_STRING), /* getClassConstFetchType $className */ reg::packed(714, MAY_BE_CALLABLE), /* getClassConstFetchType $getTypeCallback */ reg::packed(626, 0, 627), /* getClassConstFetchType return */ @@ -288,19 +290,19 @@ inline constexpr reg::PackedArg args[] = { reg::packed(626, 0, 627), /* getBitwiseNotType return */ reg::packed(880, 0, 627), /* getBitwiseNotTypeFromType $exprType */ reg::packed(626, 0, 627), /* getBitwiseNotTypeFromType return */ - reg::packed(1900, 0, 1905), /* resolveName $name */ - reg::packed(1672, MAY_BE_NULL, 1688), /* resolveName $classReflection */ + reg::packed(1923, 0, 1928), /* resolveName $name */ + reg::packed(1695, MAY_BE_NULL, 1711), /* resolveName $classReflection */ reg::packed(626, MAY_BE_STRING), /* resolveName return */ - reg::packed(1900, 0, 1905), /* resolveTypeByName $name */ - reg::packed(1672, MAY_BE_NULL, 1688), /* resolveTypeByName $classReflection */ - reg::packed(626, 0, 1937), /* resolveTypeByName return */ - reg::packed(1613, 0, 1905), /* resolveTypeByNameWithLateStaticBinding $class */ - reg::packed(1986, 0, 627), /* resolveTypeByNameWithLateStaticBinding $classType */ - reg::packed(1996, 0, 2022), /* resolveTypeByNameWithLateStaticBinding $methodReflectionCandidate */ + reg::packed(1923, 0, 1928), /* resolveTypeByName $name */ + reg::packed(1695, MAY_BE_NULL, 1711), /* resolveTypeByName $classReflection */ + reg::packed(626, 0, 1960), /* resolveTypeByName return */ + reg::packed(1636, 0, 1928), /* resolveTypeByNameWithLateStaticBinding $class */ + reg::packed(2009, 0, 627), /* resolveTypeByNameWithLateStaticBinding $classType */ + reg::packed(2019, 0, 2045), /* resolveTypeByNameWithLateStaticBinding $methodReflectionCandidate */ reg::packed(626, 0, 627), /* resolveTypeByNameWithLateStaticBinding return */ - reg::packed(626, 0, 2097), /* getReflectionProvider return */ - reg::packed(1414, 0, 627), /* getNeverType $leftType */ - reg::packed(1423, 0, 627), /* getNeverType $rightType */ + reg::packed(626, 0, 2120), /* getReflectionProvider return */ + reg::packed(1437, 0, 627), /* getNeverType $leftType */ + reg::packed(1446, 0, 627), /* getNeverType $rightType */ reg::packed(626, 0, 627), /* getNeverType return */ }; using Sig = reg::Sig; @@ -319,36 +321,36 @@ inline constexpr sigtab::Sig getCastObjectType = { { 889 /* getCastObjectType */ inline constexpr sigtab::Sig getFunctionType = { { 934 /* getFunctionType */, 4, 32, 4, 36, ZEND_ACC_PUBLIC } }; inline constexpr sigtab::Sig isParameterValueNullable = { { 981 /* isParameterValueNullable */, 1, 37, 1, 38, ZEND_ACC_PRIVATE } }; inline constexpr sigtab::Sig getFirstClassCallableType = { { 1055 /* getFirstClassCallableType */, 3, 39, 3, 42, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig createFirstClassCallable = { { 1181 /* createFirstClassCallable */, 3, 43, 3, 46, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig renameParameters = { { 1223 /* renameParameters */, 2, 47, 2, 49, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; -inline constexpr sigtab::Sig getBitwiseAndType = { { 1240 /* getBitwiseAndType */, 3, 50, 3, 53, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseOrType = { { 1258 /* getBitwiseOrType */, 3, 54, 3, 57, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseXorType = { { 1275 /* getBitwiseXorType */, 3, 58, 3, 61, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getSpaceshipType = { { 1293 /* getSpaceshipType */, 3, 62, 3, 65, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getDivType = { { 1310 /* getDivType */, 3, 66, 3, 69, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getModType = { { 1321 /* getModType */, 3, 70, 3, 73, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getPlusType = { { 1332 /* getPlusType */, 3, 74, 3, 77, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getMinusType = { { 1344 /* getMinusType */, 3, 78, 3, 81, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getMulType = { { 1357 /* getMulType */, 3, 82, 3, 85, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getPowType = { { 1368 /* getPowType */, 3, 86, 3, 89, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getShiftLeftType = { { 1379 /* getShiftLeftType */, 3, 90, 3, 93, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getShiftRightType = { { 1396 /* getShiftRightType */, 3, 94, 3, 97, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig resolveIdenticalType = { { 1457 /* resolveIdenticalType */, 2, 98, 2, 100, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig resolveEqualType = { { 1478 /* resolveEqualType */, 2, 101, 3, 104, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNonNumericString = { { 1495 /* isNonNumericString */, 2, 105, 2, 107, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; -inline constexpr sigtab::Sig resolveConstantArrayTypeComparison = { { 1578 /* resolveConstantArrayTypeComparison */, 3, 108, 3, 111, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getClassConstFetchTypeByReflection = { { 1729 /* getClassConstFetchTypeByReflection */, 4, 112, 5, 117, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig transformStaticType = { { 1778 /* transformStaticType */, 2, 118, 2, 120, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getClassConstFetchType = { { 1798 /* getClassConstFetchType */, 4, 121, 4, 125, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnaryPlusType = { { 1821 /* getUnaryPlusType */, 2, 126, 2, 128, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnaryMinusType = { { 1838 /* getUnaryMinusType */, 2, 129, 2, 131, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseNotType = { { 1856 /* getBitwiseNotType */, 2, 132, 2, 134, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseNotTypeFromType = { { 1874 /* getBitwiseNotTypeFromType */, 1, 135, 1, 136, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig resolveName = { { 1925 /* resolveName */, 2, 137, 2, 139, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig resolveTypeByName = { { 1968 /* resolveTypeByName */, 2, 140, 2, 142, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig resolveTypeByNameWithLateStaticBinding = { { 2058 /* resolveTypeByNameWithLateStaticBinding */, 3, 143, 3, 146, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getReflectionProvider = { { 2135 /* getReflectionProvider */, 0, 147, 0, 147, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getNeverType = { { 2157 /* getNeverType */, 2, 148, 2, 150, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig createFirstClassCallable = { { 1204 /* createFirstClassCallable */, 3, 43, 4, 47, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig renameParameters = { { 1246 /* renameParameters */, 2, 48, 2, 50, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; +inline constexpr sigtab::Sig getBitwiseAndType = { { 1263 /* getBitwiseAndType */, 3, 51, 3, 54, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseOrType = { { 1281 /* getBitwiseOrType */, 3, 55, 3, 58, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseXorType = { { 1298 /* getBitwiseXorType */, 3, 59, 3, 62, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getSpaceshipType = { { 1316 /* getSpaceshipType */, 3, 63, 3, 66, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getDivType = { { 1333 /* getDivType */, 3, 67, 3, 70, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getModType = { { 1344 /* getModType */, 3, 71, 3, 74, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getPlusType = { { 1355 /* getPlusType */, 3, 75, 3, 78, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getMinusType = { { 1367 /* getMinusType */, 3, 79, 3, 82, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getMulType = { { 1380 /* getMulType */, 3, 83, 3, 86, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getPowType = { { 1391 /* getPowType */, 3, 87, 3, 90, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getShiftLeftType = { { 1402 /* getShiftLeftType */, 3, 91, 3, 94, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getShiftRightType = { { 1419 /* getShiftRightType */, 3, 95, 3, 98, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig resolveIdenticalType = { { 1480 /* resolveIdenticalType */, 2, 99, 2, 101, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig resolveEqualType = { { 1501 /* resolveEqualType */, 2, 102, 3, 105, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNonNumericString = { { 1518 /* isNonNumericString */, 2, 106, 2, 108, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; +inline constexpr sigtab::Sig resolveConstantArrayTypeComparison = { { 1601 /* resolveConstantArrayTypeComparison */, 3, 109, 3, 112, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getClassConstFetchTypeByReflection = { { 1752 /* getClassConstFetchTypeByReflection */, 4, 113, 5, 118, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig transformStaticType = { { 1801 /* transformStaticType */, 2, 119, 2, 121, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getClassConstFetchType = { { 1821 /* getClassConstFetchType */, 4, 122, 4, 126, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnaryPlusType = { { 1844 /* getUnaryPlusType */, 2, 127, 2, 129, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnaryMinusType = { { 1861 /* getUnaryMinusType */, 2, 130, 2, 132, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseNotType = { { 1879 /* getBitwiseNotType */, 2, 133, 2, 135, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseNotTypeFromType = { { 1897 /* getBitwiseNotTypeFromType */, 1, 136, 1, 137, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig resolveName = { { 1948 /* resolveName */, 2, 138, 2, 140, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig resolveTypeByName = { { 1991 /* resolveTypeByName */, 2, 141, 2, 143, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig resolveTypeByNameWithLateStaticBinding = { { 2081 /* resolveTypeByNameWithLateStaticBinding */, 3, 144, 3, 147, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getReflectionProvider = { { 2158 /* getReflectionProvider */, 0, 148, 0, 148, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getNeverType = { { 2180 /* getNeverType */, 2, 149, 2, 151, ZEND_ACC_PRIVATE } }; } // namespace sig } // namespace ptdecl::InitializerExprTypeResolver diff --git a/turbo-ext/src/support.cpp b/turbo-ext/src/support.cpp index a9915e4aa8f..ef31d7e0a1a 100644 --- a/turbo-ext/src/support.cpp +++ b/turbo-ext/src/support.cpp @@ -417,6 +417,7 @@ static const pt_class_template pt_class_templates[PT_CLASS_COUNT] = { /* PT_CLASS_TYPE_NODE_DESCRIBER */ {"typeNodeDescriber", "PHPStan\\Type\\TypeNodeDescriber"}, /* PT_CLASS_ARRAY_MAP_CALLBACK_PARAMETER_TYPES */ {"arrayMapCallbackParameterTypes", "PHPStan\\Reflection\\ArrayMapCallbackParameterTypes"}, /* PT_CLASS_VALUE_DEPENDENCY_COLLECTOR */ {"valueDependencyCollector", "PHPStan\\Analyser\\ValueDependencyCollector"}, + /* PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS */ {"partialFunctionApplicationParameters", "PHPStan\\Reflection\\PartialFunctionApplicationParameters"}, }; zend_class_entry *pt_class(int idx) diff --git a/turbo-ext/src/support.h b/turbo-ext/src/support.h index 0ebc55a2717..a538ddf1adc 100644 --- a/turbo-ext/src/support.h +++ b/turbo-ext/src/support.h @@ -523,6 +523,8 @@ enum { PT_CLASS_ARRAY_MAP_CALLBACK_PARAMETER_TYPES, /* the result cache's record of what a declaration's resolution looked up */ PT_CLASS_VALUE_DEPENDENCY_COLLECTOR, + /* the closure parameters of a partial function application */ + PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS, PT_CLASS_COUNT }; @@ -4083,7 +4085,8 @@ enum pt_ietr_binary_operator : uint8_t * ->getCastType($expr, $getTypeCallback) / ->getCastObjectType($exprType) / * ->getFunctionType($type, $isNullable, $isVariadic, $context) / * ->getFirstClassCallableType($expr, $context, $nativeTypesPromoted) / - * ->createFirstClassCallable($function, $variants, $nativeTypesPromoted) / + * ->createFirstClassCallable($function, $variants, $nativeTypesPromoted, + * $partialApplicationArgs) / * ->getClassConstFetchTypeByReflection($class, $constantName, * $classReflection, $getTypeCallback) / ->getUnaryPlusType($expr, * $getTypeCallback) / ->getUnaryMinusType(...) / ->getBitwiseNotType(...): @@ -4103,7 +4106,7 @@ zv::Val pt_initializer_expr_type_resolver_get_cast_type(zval *resolver, zval *ex zv::Val pt_initializer_expr_type_resolver_get_cast_object_type(zval *resolver, zval *exprType); zv::Val pt_initializer_expr_type_resolver_get_function_type(zval *resolver, zval *type, bool isNullable, bool isVariadic, zval *context); zv::Val pt_initializer_expr_type_resolver_get_first_class_callable_type(zval *resolver, zval *expr, zval *context, bool nativeTypesPromoted); -zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted); +zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs); zv::Val pt_initializer_expr_type_resolver_get_class_const_fetch_type_by_reflection(zval *resolver, zval *class_, zval *constantName, zval *classReflection, const pt_ietr_get_type &getTypeCallback, bool nativeTypesPromoted = false); zv::Val pt_initializer_expr_type_resolver_get_unary_plus_type(zval *resolver, zval *expr, const pt_ietr_get_type &getTypeCallback); zv::Val pt_initializer_expr_type_resolver_get_unary_minus_type(zval *resolver, zval *expr, const pt_ietr_get_type &getTypeCallback); From 5242dbbf699f6680ace5bf7ec864e61d3375b5bc Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Tue, 10 Nov 2026 18:25:04 +0000 Subject: [PATCH 02/20] Report partial function application arguments that do not fit the callee FunctionCallableNode, MethodCallableNode and StaticMethodCallableNode gain getArgs() with the bound arguments and placeholders. Their rules pick the variant the placeholders fit and run FunctionCallParametersCheck through the new checkPartialApplication(), which resolves templates from the bound arguments only. The check now reads placeholders: a ? fills a parameter without a value to check, ... lifts the too-few and missing-parameter checks, too many arguments are reported regardless of checkExtraArguments because the creation throws, and the creation-time errors of PHP 8.6 are reported: a named placeholder for an unknown or variadic parameter, unpacking, and ... before another argument. The self-analysis stub of CallLike now includes ArgPlaceholder. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- build/collision-detector.json | 4 +- build/stubs/PhpParserExpr.stub | 29 ++-- src/Node/FunctionCallableNode.php | 13 ++ src/Node/MethodCallableNode.php | 13 ++ src/Node/StaticMethodCallableNode.php | 13 ++ .../PartialFunctionApplicationParameters.php | 38 +++++ src/Rules/FunctionCallParametersCheck.php | 156 ++++++++++++++++-- src/Rules/Functions/FunctionCallableRule.php | 45 ++++- src/Rules/Methods/MethodCallableRule.php | 31 +++- .../Methods/StaticMethodCallableRule.php | 31 +++- .../Functions/FunctionCallableRuleTest.php | 85 ++++++++++ ...partial-function-application-arguments.php | 76 +++++++++ .../Rules/Methods/MethodCallableRuleTest.php | 21 +++ .../Methods/StaticMethodCallableRuleTest.php | 21 +++ ...-function-application-method-arguments.php | 36 ++++ 15 files changed, 578 insertions(+), 34 deletions(-) create mode 100644 tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php create mode 100644 tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php diff --git a/build/collision-detector.json b/build/collision-detector.json index efc4e013c0f..d92f317fc2a 100644 --- a/build/collision-detector.json +++ b/build/collision-detector.json @@ -31,6 +31,8 @@ "../tests/PHPStan/Rules/Functions/data/partial-function-application-bound-args.php", "../tests/PHPStan/Rules/Pure/data/partial-function-application-pure.php", "../tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php", - "../tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php" + "../tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php", + "../tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php", + "../tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php" ] } diff --git a/build/stubs/PhpParserExpr.stub b/build/stubs/PhpParserExpr.stub index 636d8cf5b42..01f47088491 100644 --- a/build/stubs/PhpParserExpr.stub +++ b/build/stubs/PhpParserExpr.stub @@ -5,6 +5,7 @@ namespace PhpParser\Node\Expr; use PhpParser\Node; use PhpParser\NodeAbstract; use PhpParser\Node\Arg; +use PhpParser\Node\ArgPlaceholder; use PhpParser\Node\Expr; use PhpParser\Node\Identifier; use PhpParser\Node\VariadicPlaceholder; @@ -13,38 +14,38 @@ use PhpParser\Node\FunctionLike; abstract class CallLike extends Expr { /** * Return raw arguments, which may be actual Args, or VariadicPlaceholders for first-class - * callables. + * callables, or ArgPlaceholders for partial function application. * - * @return list + * @return list */ abstract public function getRawArgs(): array; /** - * Assert that this is not a first-class callable and return only ordinary Args. + * Assert that this is not a partial function application and return only ordinary Args. * * @return list */ public function getArgs(): array { - assert(!$this->isFirstClassCallable()); + assert(!$this->isPartialFunctionApplication()); return $this->getRawArgs(); } } class FuncCall extends CallLike { - /** @var list Arguments */ + /** @var list Arguments */ public array $args; /** * Constructs a function call node. * * @param Node\Name|Expr $name Function name - * @param list $args Arguments + * @param list $args Arguments * @param array $attributes Additional attributes */ public function __construct(Node $name, array $args = [], array $attributes = []) {} } class MethodCall extends CallLike { - /** @var list Arguments */ + /** @var list Arguments */ public array $args; /** @@ -52,28 +53,28 @@ class MethodCall extends CallLike { * * @param Expr $var Variable holding object * @param string|Identifier|Expr $name Method name - * @param list $args Arguments + * @param list $args Arguments * @param array $attributes Additional attributes */ public function __construct(Expr $var, $name, array $args = [], array $attributes = []) {} } class New_ extends CallLike { - /** @var list Arguments */ + /** @var list Arguments */ public array $args; /** * Constructs a function call node. * * @param Node\Name|Expr|Node\Stmt\Class_ $class Class name (or class node for anonymous classes) - * @param list $args Arguments + * @param list $args Arguments * @param array $attributes Additional attributes */ public function __construct(Node $class, array $args = [], array $attributes = []) {} } class NullsafeMethodCall extends CallLike { - /** @var list Arguments */ + /** @var list Arguments */ public array $args; /** @@ -81,14 +82,14 @@ class NullsafeMethodCall extends CallLike { * * @param Expr $var Variable holding object * @param string|Identifier|Expr $name Method name - * @param list $args Arguments + * @param list $args Arguments * @param array $attributes Additional attributes */ public function __construct(Expr $var, $name, array $args = [], array $attributes = []) {} } class StaticCall extends CallLike { - /** @var list Arguments */ + /** @var list Arguments */ public array $args; /** @@ -96,7 +97,7 @@ class StaticCall extends CallLike { * * @param Node\Name|Expr $class Class name * @param string|Identifier|Expr $name Method name - * @param list $args Arguments + * @param list $args Arguments * @param array $attributes Additional attributes */ public function __construct(Node $class, $name, array $args = [], array $attributes = []) {} diff --git a/src/Node/FunctionCallableNode.php b/src/Node/FunctionCallableNode.php index ac74cc15545..6c70cb03d6a 100644 --- a/src/Node/FunctionCallableNode.php +++ b/src/Node/FunctionCallableNode.php @@ -3,8 +3,11 @@ namespace PHPStan\Node; use Override; +use PhpParser\Node\Arg; +use PhpParser\Node\ArgPlaceholder; use PhpParser\Node\Expr; use PhpParser\Node\Name; +use PhpParser\Node\VariadicPlaceholder; use PHPStan\Node\Printer\ExprPrinter; use PHPStan\Turbo\ReferencedByTurboExtension; @@ -36,6 +39,16 @@ public function getOriginalNode(): Expr\FuncCall return $this->originalNode; } + /** + * The arguments of the call: bound arguments, `?` placeholders and the `...` placeholder. + * + * @return array + */ + public function getArgs(): array + { + return $this->originalNode->getRawArgs(); + } + #[Override] public function getType(): string { diff --git a/src/Node/MethodCallableNode.php b/src/Node/MethodCallableNode.php index 037605111c2..fa530142186 100644 --- a/src/Node/MethodCallableNode.php +++ b/src/Node/MethodCallableNode.php @@ -3,8 +3,11 @@ namespace PHPStan\Node; use Override; +use PhpParser\Node\Arg; +use PhpParser\Node\ArgPlaceholder; use PhpParser\Node\Expr; use PhpParser\Node\Identifier; +use PhpParser\Node\VariadicPlaceholder; use PHPStan\Node\Printer\ExprPrinter; use PHPStan\Turbo\ReferencedByTurboExtension; @@ -45,6 +48,16 @@ public function getOriginalNode(): Expr\MethodCall return $this->originalNode; } + /** + * The arguments of the call: bound arguments, `?` placeholders and the `...` placeholder. + * + * @return array + */ + public function getArgs(): array + { + return $this->originalNode->getRawArgs(); + } + #[Override] public function getType(): string { diff --git a/src/Node/StaticMethodCallableNode.php b/src/Node/StaticMethodCallableNode.php index 02573a06baf..b8287fc3d21 100644 --- a/src/Node/StaticMethodCallableNode.php +++ b/src/Node/StaticMethodCallableNode.php @@ -3,9 +3,12 @@ namespace PHPStan\Node; use Override; +use PhpParser\Node\Arg; +use PhpParser\Node\ArgPlaceholder; use PhpParser\Node\Expr; use PhpParser\Node\Identifier; use PhpParser\Node\Name; +use PhpParser\Node\VariadicPlaceholder; use PHPStan\Node\Printer\ExprPrinter; use PHPStan\Turbo\ReferencedByTurboExtension; @@ -49,6 +52,16 @@ public function getOriginalNode(): Expr\StaticCall return $this->originalNode; } + /** + * The arguments of the call: bound arguments, `?` placeholders and the `...` placeholder. + * + * @return array + */ + public function getArgs(): array + { + return $this->originalNode->getRawArgs(); + } + #[Override] public function getType(): string { diff --git a/src/Reflection/PartialFunctionApplicationParameters.php b/src/Reflection/PartialFunctionApplicationParameters.php index 03896a8980e..6a29db6aa69 100644 --- a/src/Reflection/PartialFunctionApplicationParameters.php +++ b/src/Reflection/PartialFunctionApplicationParameters.php @@ -148,6 +148,44 @@ public static function apply(array $parameters, array $args): ?array return [$closureParameters, $variadicParameter !== null]; } + /** + * The variant whose partial application the arguments fit. When several fit, + * they are combined; when none does, all of them are. + * + * @param array $args + * @param list $variants + * @param list|null $namedArgumentsVariants + */ + public static function selectVariant(array $args, array $variants, ?array $namedArgumentsVariants): ParametersAcceptor + { + if ($namedArgumentsVariants !== null) { + foreach ($args as $arg) { + if (!$arg instanceof VariadicPlaceholder && $arg->name !== null) { + $variants = $namedArgumentsVariants; + break; + } + } + } + + if (count($variants) === 1) { + return $variants[0]; + } + + $fitting = []; + foreach ($variants as $variant) { + if (self::apply($variant->getParameters(), $args) === null) { + continue; + } + $fitting[] = $variant; + } + + if (count($fitting) === 1) { + return $fitting[0]; + } + + return ParametersAcceptorSelector::combineAcceptors(count($fitting) > 0 ? $fitting : $variants); + } + private static function required(ParameterReflection $parameter, string $name): ParameterReflection { if ($parameter instanceof ExtendedParameterReflection) { diff --git a/src/Rules/FunctionCallParametersCheck.php b/src/Rules/FunctionCallParametersCheck.php index 13af1483c79..d5511a1da4e 100644 --- a/src/Rules/FunctionCallParametersCheck.php +++ b/src/Rules/FunctionCallParametersCheck.php @@ -16,6 +16,7 @@ use PHPStan\Reflection\ConstantReflection; use PHPStan\Reflection\ExtendedParameterReflection; use PHPStan\Reflection\FunctionReflection; +use PHPStan\Reflection\GenericParametersAcceptorResolver; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParameterReflection; use PHPStan\Reflection\ParametersAcceptor; @@ -52,6 +53,7 @@ use function lcfirst; use function max; use function sprintf; +use function ucfirst; #[AutowiredService] final class FunctionCallParametersCheck @@ -150,14 +152,46 @@ public function check( $functionParametersMaxCount = -1; } - /** @var array $arguments */ + /** @var array $arguments */ $arguments = []; - /** @var array $args */ - $args = $funcCall->getArgs(); + $isPartialApplication = $funcCall->isPartialFunctionApplication(); + $args = $isPartialApplication ? $funcCall->getRawArgs() : $funcCall->getArgs(); $hasNamedArguments = false; $hasUnpackedArgument = false; + $hasVariadicPlaceholder = false; $errors = []; foreach ($args as $arg) { + if ($hasVariadicPlaceholder) { + $errors[] = RuleErrorBuilder::message('Variadic placeholder must be last.') + ->identifier('argument.variadicPlaceholderNotLast') + ->line($arg->getStartLine()) + ->nonIgnorable() + ->build(); + break; + } + if ($arg instanceof Node\VariadicPlaceholder) { + $hasVariadicPlaceholder = true; + continue; + } + if ($arg instanceof Node\ArgPlaceholder) { + $argumentName = null; + if ($arg->name !== null) { + $hasNamedArguments = true; + $argumentName = $arg->name->toString(); + } + $arguments[] = [$arg, null, false, $argumentName, $arg->getStartLine()]; + continue; + } + + if ($isPartialApplication && $arg->unpack) { + $errors[] = RuleErrorBuilder::message('Cannot combine partial application and unpacking.') + ->identifier('argument.unpackInPartialApplication') + ->line($arg->getStartLine()) + ->nonIgnorable() + ->build(); + continue; + } + $argumentName = null; if ($arg->name !== null) { $hasNamedArguments = true; @@ -295,8 +329,10 @@ public function check( } if ( - $invokedParametersCount < $functionParametersMinCount - || ($this->checkExtraArguments && $invokedParametersCount > $functionParametersMaxCount) + // ... of a partial application fills in the parameters left + ($invokedParametersCount < $functionParametersMinCount && !$hasVariadicPlaceholder) + // a partial application with too many arguments throws when it is created + || (($this->checkExtraArguments || $isPartialApplication) && $functionParametersMaxCount !== -1 && $invokedParametersCount > $functionParametersMaxCount) ) { if ($functionParametersMinCount === $functionParametersMaxCount) { $errors[] = RuleErrorBuilder::message(sprintf( @@ -332,6 +368,7 @@ public function check( if ( !$funcCall instanceof Node\Expr\New_ + && !$isPartialApplication && !$scope->isInFirstLevelStatement() && $scope->getKeepVoidType($funcCall)->isVoid()->yes() ) { @@ -341,7 +378,7 @@ public function check( ->build(); } - [$addedErrors, $argumentsWithParameters] = $this->processArguments($parametersAcceptor, $funcCallLine, $isBuiltin, $arguments, $hasNamedArguments, $missingParameterMessage, $unknownParameterMessage); + [$addedErrors, $argumentsWithParameters] = $this->processArguments($parametersAcceptor, $funcCallLine, $isBuiltin, $arguments, $hasNamedArguments, !$hasVariadicPlaceholder, $missingParameterMessage, $unknownParameterMessage); foreach ($addedErrors as $error) { $errors[] = $error; } @@ -352,6 +389,11 @@ public function check( $positionalArgumentsFix = null; foreach ($argumentsWithParameters as $i => [$argumentValue, $argumentValueType, $unpack, $argumentName, $argumentLine, $parameter, $originalParameter]) { + if ($argumentValue instanceof Node\ArgPlaceholder) { + // a placeholder has no value, it becomes a parameter of the closure + continue; + } + if ($this->checkArgumentTypes && $unpack) { $iterableTypeResult = $this->ruleLevelHelper->findTypeToCheck( $scope, @@ -462,7 +504,7 @@ public function check( // only the parameter of a resolved generic acceptor has an original // type to tell an unresolvable type this call made from a declared one - $unresolvableParameterType = $originalParameter !== null ? $this->unresolvableTypeHelper->getUnresolvableType($parameterType) : null; + $unresolvableParameterType = $originalParameter !== null && !$isPartialApplication ? $this->unresolvableTypeHelper->getUnresolvableType($parameterType) : null; if ( $unresolvableParameterType !== null && $this->unresolvableTypeHelper->getUnresolvableType($originalParameter->getType()) === null @@ -631,7 +673,7 @@ public function check( ))->identifier('argument.byRef')->line($argumentLine)->build(); } - if ($this->checkMissingTypehints && $parametersAcceptor instanceof ResolvedFunctionVariant) { + if ($this->checkMissingTypehints && !$isPartialApplication && $parametersAcceptor instanceof ResolvedFunctionVariant) { $originalParametersAcceptor = $parametersAcceptor->getOriginalParametersAcceptor(); $resolvedTypes = $parametersAcceptor->getResolvedTemplateTypeMap()->getTypes(); if (!$isBuiltin && count($resolvedTypes) > 0) { @@ -716,8 +758,88 @@ static function (Type $type, callable $traverse) use (&$returnTemplateTypes): Ty } /** - * @param array $arguments - * @return array{list, array} + * Checks the bound arguments and placeholders of a partial function application + * against the callee: PHP throws when such a closure is created from arguments + * that do not fit. + * + * @param 'callable'|'method'|'staticMethod'|'function' $nodeType + * @param string $calleeDescription like "function foo" or "method Foo::bar()", escaped for sprintf() + * @return list + */ + public function checkPartialApplication( + ParametersAcceptor $parametersAcceptor, + Scope&NodeCallbackInvoker&CollectedDataEmitter $scope, + bool $isBuiltin, + Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall $call, + string $nodeType, + TrinaryLogic $acceptsNamedArguments, + string $calleeDescription, + FunctionReflection|MethodReflection|null $calleeReflection, + ): array + { + // templates are resolved from the bound arguments, as in a call; + // the ones only the placeholders determine stay unresolved + $argTypes = []; + $position = 0; + foreach ($call->getRawArgs() as $arg) { + if ($arg instanceof Node\VariadicPlaceholder) { + break; + } + if ($arg instanceof Node\ArgPlaceholder) { + if ($arg->name === null) { + $position++; + } + continue; + } + if ($arg->unpack) { + continue; + } + if ($arg->name !== null) { + $argTypes[$arg->name->toString()] = $scope->getType($arg->value); + continue; + } + $argTypes[$position++] = $scope->getType($arg->value); + } + if (!$parametersAcceptor->getTemplateTypeMap()->isEmpty()) { + $parametersAcceptor = GenericParametersAcceptorResolver::resolve($argTypes, $parametersAcceptor); + } + + $applied = ucfirst($calleeDescription) . ' partially applied with'; + + return $this->check( + $parametersAcceptor, + $scope, + $isBuiltin, + $call, + $nodeType, + $acceptsNamedArguments, + $applied . ' %d argument, %d required.', + $applied . ' %d arguments, %d required.', + $applied . ' %d argument, at least %d required.', + $applied . ' %d arguments, at least %d required.', + $applied . ' %d argument, %d-%d required.', + $applied . ' %d arguments, %d-%d required.', + '%s of ' . $calleeDescription . ' expects %s, %s given.', + 'Result of ' . $calleeDescription . ' (void) is used.', + '%s of ' . $calleeDescription . ' is passed by reference, so it expects variables only.', + 'Unable to resolve the template type %s in partial application of ' . $calleeDescription, + 'Missing parameter $%s in partial application of ' . $calleeDescription . '.', + 'Unknown parameter $%s in partial application of ' . $calleeDescription . '.', + 'Return type of partial application of ' . $calleeDescription . ' contains unresolvable type.', + '%s of ' . $calleeDescription . ' contains unresolvable type.', + $applied . ' %s, but it\'s not allowed because of @no-named-arguments.', + 'Constant %s is not allowed for %s of ' . $calleeDescription . '.', + 'Constants %s cannot be combined for %s of ' . $calleeDescription . '.', + 'Combining constants with | is not allowed for %s of ' . $calleeDescription . '.', + null, + $calleeReflection, + ); + } + + /** + * @param array $arguments + * @param bool $checkMissingParameters false when ... of a partial application fills in the parameters left + * @return array{list, array} */ private function processArguments( ParametersAcceptor $parametersAcceptor, @@ -725,6 +847,7 @@ private function processArguments( bool $isBuiltin, array $arguments, bool $hasNamedArguments, + bool $checkMissingParameters, string $missingParameterMessage, string $unknownParameterMessage, ): array @@ -772,6 +895,17 @@ private function processArguments( $parameter = $parameters[$i]; $originalParameter = $originalParameters[$i]; } + } elseif ( + $argumentValue instanceof Node\ArgPlaceholder + && (!array_key_exists($argumentName, $parametersByName) || $parametersByName[$argumentName]->isVariadic()) + ) { + $namedArgumentAlreadyOccurred = true; + $errors[] = RuleErrorBuilder::message(sprintf('Cannot use named placeholder for unknown or variadic parameter $%s.', $argumentName)) + ->identifier('argument.unknown') + ->line($argumentLine) + ->build(); + $newArguments[$i] = [$argumentValue, $argumentValueType, $unpack, $argumentName, $argumentLine, null, null]; + continue; } elseif (array_key_exists($argumentName, $parametersByName)) { $namedArgumentAlreadyOccurred = true; $parameter = $parametersByName[$argumentName]; @@ -828,7 +962,7 @@ private function processArguments( unset($unusedParametersByName[$parameter->getName()]); } - if ($hasNamedArguments) { + if ($hasNamedArguments && $checkMissingParameters) { foreach ($unusedParametersByName as $parameter) { if ($parameter->isOptional()) { continue; diff --git a/src/Rules/Functions/FunctionCallableRule.php b/src/Rules/Functions/FunctionCallableRule.php index fdcecaebeaa..e5d7d65eb89 100644 --- a/src/Rules/Functions/FunctionCallableRule.php +++ b/src/Rules/Functions/FunctionCallableRule.php @@ -3,18 +3,26 @@ namespace PHPStan\Rules\Functions; use PhpParser\Node; +use PHPStan\Analyser\CollectedDataEmitter; +use PHPStan\Analyser\NodeCallbackInvoker; use PHPStan\Analyser\NullsafeOperatorHelper; use PHPStan\Analyser\Scope; use PHPStan\DependencyInjection\AutowiredParameter; use PHPStan\DependencyInjection\RegisteredRule; +use PHPStan\Internal\SprintfHelper; use PHPStan\Node\FunctionCallableNode; +use PHPStan\Reflection\PartialFunctionApplicationParameters; use PHPStan\Reflection\ReflectionProvider; +use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\TrinaryLogic; +use PHPStan\Type\ClosureType; use PHPStan\Type\ErrorType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; +use function array_merge; use function in_array; use function sprintf; use function strtolower; @@ -43,6 +51,7 @@ final class FunctionCallableRule implements Rule public function __construct( private ReflectionProvider $reflectionProvider, private RuleLevelHelper $ruleLevelHelper, + private FunctionCallParametersCheck $parametersCheck, #[AutowiredParameter] private bool $checkFunctionNameCase, #[AutowiredParameter] @@ -56,7 +65,7 @@ public function getNodeType(): string return FunctionCallableNode::class; } - public function processNode(Node $node, Scope $scope): array + public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataEmitter $scope): array { if (!$node->getOriginalNode()->isFirstClassCallable()) { if (!$scope->getPhpVersion()->supportsPartialFunctionApplication()->yes()) { @@ -104,6 +113,19 @@ public function processNode(Node $node, Scope $scope): array ))->identifier('callable.notSupported')->build(); } + if (!$node->getOriginalNode()->isFirstClassCallable()) { + $errors = array_merge($errors, $this->parametersCheck->checkPartialApplication( + PartialFunctionApplicationParameters::selectVariant($node->getArgs(), $function->getVariants(), $function->getNamedArgumentsVariants()), + $scope, + $function->isBuiltin(), + $node->getOriginalNode(), + 'function', + $function->acceptsNamedArguments(), + 'function ' . SprintfHelper::escapeFormatString($function->getName()), + $function, + )); + } + return $errors; } @@ -145,7 +167,26 @@ public function processNode(Node $node, Scope $scope): array ]; } - return []; + if ($node->getOriginalNode()->isFirstClassCallable() || !$isCallable->yes()) { + return []; + } + + $parametersAcceptors = $type->getCallableParametersAcceptors($scope); + $acceptsNamedArguments = TrinaryLogic::createYes(); + foreach ($parametersAcceptors as $parametersAcceptor) { + $acceptsNamedArguments = $acceptsNamedArguments->and($parametersAcceptor->acceptsNamedArguments()); + } + + return $this->parametersCheck->checkPartialApplication( + PartialFunctionApplicationParameters::selectVariant($node->getArgs(), $parametersAcceptors, null), + $scope, + false, + $node->getOriginalNode(), + 'callable', + $acceptsNamedArguments, + $type instanceof ClosureType ? 'closure' : sprintf('callable %s', SprintfHelper::escapeFormatString($type->describe(VerbosityLevel::value()))), + null, + ); } } diff --git a/src/Rules/Methods/MethodCallableRule.php b/src/Rules/Methods/MethodCallableRule.php index c7326882592..13133f7fb2d 100644 --- a/src/Rules/Methods/MethodCallableRule.php +++ b/src/Rules/Methods/MethodCallableRule.php @@ -3,11 +3,17 @@ namespace PHPStan\Rules\Methods; use PhpParser\Node; +use PHPStan\Analyser\CollectedDataEmitter; +use PHPStan\Analyser\NodeCallbackInvoker; use PHPStan\Analyser\Scope; use PHPStan\DependencyInjection\RegisteredRule; +use PHPStan\Internal\SprintfHelper; use PHPStan\Node\MethodCallableNode; +use PHPStan\Reflection\PartialFunctionApplicationParameters; +use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; +use function array_merge; /** * @implements Rule @@ -16,7 +22,10 @@ final class MethodCallableRule implements Rule { - public function __construct(private MethodCallCheck $methodCallCheck) + public function __construct( + private MethodCallCheck $methodCallCheck, + private FunctionCallParametersCheck $parametersCheck, + ) { } @@ -25,7 +34,7 @@ public function getNodeType(): string return MethodCallableNode::class; } - public function processNode(Node $node, Scope $scope): array + public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataEmitter $scope): array { if (!$node->getOriginalNode()->isFirstClassCallable()) { if (!$scope->getPhpVersion()->supportsPartialFunctionApplication()->yes()) { @@ -61,7 +70,23 @@ public function processNode(Node $node, Scope $scope): array $methodNameName = $methodName->toString(); - return $this->methodCallCheck->check($scope, $methodNameName, $node->getVar(), $node->getName())[0]; + [$errors, $methodReflection] = $this->methodCallCheck->check($scope, $methodNameName, $node->getVar(), $node->getName()); + if ($methodReflection === null || $node->getOriginalNode()->isFirstClassCallable()) { + return $errors; + } + + $declaringClass = $methodReflection->getDeclaringClass(); + + return array_merge($errors, $this->parametersCheck->checkPartialApplication( + PartialFunctionApplicationParameters::selectVariant($node->getArgs(), $methodReflection->getVariants(), $methodReflection->getNamedArgumentsVariants()), + $scope, + $declaringClass->isBuiltin(), + $node->getOriginalNode(), + 'method', + $methodReflection->acceptsNamedArguments(), + 'method ' . SprintfHelper::escapeFormatString($declaringClass->getDisplayName() . '::' . $methodReflection->getName() . '()'), + $methodReflection, + )); } } diff --git a/src/Rules/Methods/StaticMethodCallableRule.php b/src/Rules/Methods/StaticMethodCallableRule.php index d845156e90f..73098347ac5 100644 --- a/src/Rules/Methods/StaticMethodCallableRule.php +++ b/src/Rules/Methods/StaticMethodCallableRule.php @@ -3,11 +3,17 @@ namespace PHPStan\Rules\Methods; use PhpParser\Node; +use PHPStan\Analyser\CollectedDataEmitter; +use PHPStan\Analyser\NodeCallbackInvoker; use PHPStan\Analyser\Scope; use PHPStan\DependencyInjection\RegisteredRule; +use PHPStan\Internal\SprintfHelper; use PHPStan\Node\StaticMethodCallableNode; +use PHPStan\Reflection\PartialFunctionApplicationParameters; +use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; +use function array_merge; /** * @implements Rule @@ -16,7 +22,10 @@ final class StaticMethodCallableRule implements Rule { - public function __construct(private StaticMethodCallCheck $methodCallCheck) + public function __construct( + private StaticMethodCallCheck $methodCallCheck, + private FunctionCallParametersCheck $parametersCheck, + ) { } @@ -25,7 +34,7 @@ public function getNodeType(): string return StaticMethodCallableNode::class; } - public function processNode(Node $node, Scope $scope): array + public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataEmitter $scope): array { if (!$node->getOriginalNode()->isFirstClassCallable()) { if (!$scope->getPhpVersion()->supportsPartialFunctionApplication()->yes()) { @@ -52,7 +61,23 @@ public function processNode(Node $node, Scope $scope): array $methodNameName = $methodName->toString(); - return $this->methodCallCheck->check($scope, $methodNameName, $node->getClass(), $node->getName())[0]; + [$errors, $methodReflection] = $this->methodCallCheck->check($scope, $methodNameName, $node->getClass(), $node->getName()); + if ($methodReflection === null || $node->getOriginalNode()->isFirstClassCallable()) { + return $errors; + } + + $declaringClass = $methodReflection->getDeclaringClass(); + + return array_merge($errors, $this->parametersCheck->checkPartialApplication( + PartialFunctionApplicationParameters::selectVariant($node->getArgs(), $methodReflection->getVariants(), $methodReflection->getNamedArgumentsVariants()), + $scope, + $declaringClass->isBuiltin(), + $node->getOriginalNode(), + 'staticMethod', + $methodReflection->acceptsNamedArguments(), + 'static method ' . SprintfHelper::escapeFormatString($declaringClass->getDisplayName() . '::' . $methodReflection->getName() . '()'), + $methodReflection, + )); } } diff --git a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php index 81595b5816d..93073ca5b5b 100644 --- a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php +++ b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php @@ -2,6 +2,7 @@ namespace PHPStan\Rules\Functions; +use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; @@ -30,6 +31,7 @@ protected function getRule(): Rule checkBenevolentUnionTypes: false, discoveringSymbolsTip: true, ), + self::getContainer()->getByType(FunctionCallParametersCheck::class), true, true, ); @@ -158,6 +160,89 @@ public function testPartialFunctionApplication(): void $this->analyse([__DIR__ . '/data/function-partial-function-application.php'], $errors); } + #[RequiresPhp('>= 8.6.0-dev')] + public function testPartialFunctionApplicationArguments(): void + { + $this->analyse([__DIR__ . '/data/partial-function-application-arguments.php'], [ + [ + 'Function PartialFunctionApplicationArguments\\doFoo partially applied with 2 arguments, at least 3 required.', + 35, + ], + [ + 'Function PartialFunctionApplicationArguments\\none partially applied with 1 argument, 0 required.', + 36, + ], + [ + 'Function PartialFunctionApplicationArguments\\none partially applied with 1 argument, 0 required.', + 37, + ], + [ + 'Function PartialFunctionApplicationArguments\\opt partially applied with 4 arguments, 1-3 required.', + 38, + ], + [ + 'Cannot use named placeholder for unknown or variadic parameter $x.', + 39, + ], + [ + 'Cannot use named placeholder for unknown or variadic parameter $d.', + 40, + ], + [ + 'Argument for parameter $a has already been passed.', + 41, + ], + [ + 'Argument for parameter $a has already been passed.', + 42, + ], + [ + 'Parameter #1 $a of function PartialFunctionApplicationArguments\\opt expects int, string given.', + 43, + ], + [ + 'Parameter #1 $a of function PartialFunctionApplicationArguments\\byRef is passed by reference, so it expects variables only.', + 44, + ], + [ + 'Cannot combine partial application and unpacking.', + 45, + ], + [ + 'Function strtok partially applied with 3 arguments, 1-2 required.', + 46, + ], + [ + 'Missing parameter $b (string) in partial application of function PartialFunctionApplicationArguments\\doFoo.', + 47, + ], + [ + 'Missing parameter $c (float) in partial application of function PartialFunctionApplicationArguments\\doFoo.', + 47, + ], + [ + 'Named argument cannot be followed by a positional argument.', + 47, + ], + [ + 'Variadic placeholder must be last.', + 48, + ], + [ + 'Parameter #1 $a of closure expects int, string given.', + 55, + ], + [ + 'Closure partially applied with 3 arguments, 2 required.', + 56, + ], + [ + 'Parameter #1 $a of function PartialFunctionApplicationArguments\\intOnly expects int, string given.', + 75, + ], + ]); + } + public function testConditionallyExecutedCode(): void { $errors = [ diff --git a/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php b/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php new file mode 100644 index 00000000000..393d9e2e053 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php @@ -0,0 +1,76 @@ += 8.6 + +declare(strict_types = 1); + +namespace PartialFunctionApplicationArguments; + +function doFoo(int $a, string $b, float $c, bool ...$d): string +{ + return ''; +} + +function opt(int $a, string $b = 'B', float $c = 1.0): int +{ + return 1; +} + +function none(): void +{ +} + +function byRef(int &$a, string $b): void +{ +} + +function test(int $i, array $arr): void +{ + doFoo(1, ?, 3.0); + doFoo(1, ?, ...); + doFoo(1, 'b', 3.0, x: true, ...); + none(...); + byRef($i, ?); + strtok(?); + opt(?, c: 2.0); + + doFoo(1, ?); + none(?); + none(1, ...); + opt(1, 'b', 2.0, ?); + opt(x: ?, a: 1); + doFoo(1, 'b', 3.0, d: ?); + opt(?, a: 1); + opt(a: ?, a: ?); + opt('x', ?); + byRef(1, ?); + opt(...$arr, ?); + strtok('a', 'b', ?); + doFoo(a: 1, ?); + doFoo(..., ?); +} + +function closures(): void +{ + $c = fn (int $a, string $b): int => 1; + $c(1, ?); + $c('x', ?); + $c(1, 'b', ?); +} + +/** + * @template T of int + * @param T $a + * @return T + */ +function intOnly($a) +{ + return $a; +} + +function templates(): void +{ + // templates are resolved from the bound arguments + usort(?, fn (int $a, int $b): int => $a <=> $b); + array_map(fn (string $s): int => 1, ?); + intOnly(1, ...); + intOnly('x', ...); +} diff --git a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php index 74e4a4164c7..1ded97619c1 100644 --- a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php @@ -2,6 +2,7 @@ namespace PHPStan\Rules\Methods; +use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; @@ -35,6 +36,7 @@ protected function getRule(): Rule checkFunctionNameCase: true, reportMagicMethods: true, ), + self::getContainer()->getByType(FunctionCallParametersCheck::class), ); } @@ -114,6 +116,25 @@ public function testNullsafe(): void ]); } + #[RequiresPhp('>= 8.6.0-dev')] + public function testPartialFunctionApplicationArguments(): void + { + $this->analyse([__DIR__ . '/data/partial-function-application-method-arguments.php'], [ + [ + 'Method PartialFunctionApplicationMethodArguments\\Foo::doFoo() partially applied with 1 argument, at least 2 required.', + 28, + ], + [ + 'Parameter #1 $a of method PartialFunctionApplicationMethodArguments\\Foo::doFoo() expects int, string given.', + 29, + ], + [ + 'Cannot use named placeholder for unknown or variadic parameter $c.', + 30, + ], + ]); + } + public function testConditionallyExecutedCode(): void { $errors = [ diff --git a/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php index dfb921a2be7..0dcb92fd640 100644 --- a/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\ClassForbiddenNameCheck; use PHPStan\Rules\ClassNameCheck; +use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\RestrictedUsage\RestrictedClassNameUsageExtension; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; @@ -52,6 +53,7 @@ protected function getRule(): Rule discoveringSymbolsTip: true, reportMagicMethods: true, ), + self::getContainer()->getByType(FunctionCallParametersCheck::class), ); } @@ -133,6 +135,25 @@ public function testPartialFunctionApplication(): void $this->analyse([__DIR__ . '/data/method-partial-function-application.php'], $errors); } + #[RequiresPhp('>= 8.6.0-dev')] + public function testPartialFunctionApplicationArguments(): void + { + $this->analyse([__DIR__ . '/data/partial-function-application-method-arguments.php'], [ + [ + 'Static method PartialFunctionApplicationMethodArguments\\Foo::doStatic() partially applied with 3 arguments, 1-2 required.', + 31, + ], + [ + 'Missing parameter $a (int) in partial application of static method PartialFunctionApplicationMethodArguments\\Foo::doStatic().', + 32, + ], + [ + 'Argument for parameter $a has already been passed.', + 33, + ], + ]); + } + public function testConditionallyExecutedCode(): void { $errors = [ diff --git a/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php b/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php new file mode 100644 index 00000000000..b70498b4b2c --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php @@ -0,0 +1,36 @@ += 8.6 + +declare(strict_types = 1); + +namespace PartialFunctionApplicationMethodArguments; + +class Foo +{ + + public function doFoo(int $a, string $b, float ...$c): bool + { + return true; + } + + public static function doStatic(int $a, string $b = 'x'): int + { + return 1; + } + + public function test(): void + { + $this->doFoo(1, ?); + $this->doFoo(1, ?, ?, ?); + $this->doFoo(?, ...); + self::doStatic(?); + self::doStatic(1, ?, ...); + + $this->doFoo(?); + $this->doFoo('x', ?); + $this->doFoo(1, 'b', c: ?); + self::doStatic(1, 'b', ?); + self::doStatic(b: ?); + static::doStatic(?, a: 1); + } + +} From eb3ea739f9377072a375335a0f53cb29b132968d Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Tue, 10 Nov 2026 18:25:35 +0000 Subject: [PATCH 03/20] Say that a first-class callable of compact() throws when called PHP 8.6 creates compact(...), extract(...) and the other functions that cannot be called dynamically as first-class callables and throws only when they are called; a partial application of them already throws when it is created. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- src/Rules/Functions/FunctionCallableRule.php | 4 +++- .../Rules/Functions/FunctionCallableRuleTest.php | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Rules/Functions/FunctionCallableRule.php b/src/Rules/Functions/FunctionCallableRule.php index e5d7d65eb89..7f1430d3a34 100644 --- a/src/Rules/Functions/FunctionCallableRule.php +++ b/src/Rules/Functions/FunctionCallableRule.php @@ -108,7 +108,9 @@ public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataE if (in_array(strtolower($function->getName()), self::DYNAMIC_CALL_FORBIDDEN_FUNCTIONS, true)) { $errors[] = RuleErrorBuilder::message(sprintf( - 'Cannot create callable from %s(), it cannot be called dynamically.', + $node->getOriginalNode()->isFirstClassCallable() + ? 'Calling the callable created from %s() throws, it cannot be called dynamically.' + : 'Cannot create callable from %s(), it cannot be called dynamically.', $function->getName(), ))->identifier('callable.notSupported')->build(); } diff --git a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php index 93073ca5b5b..2e05afb4abb 100644 --- a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php +++ b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php @@ -85,27 +85,27 @@ public function testDynamicCallForbidden(): void { $errors = [ [ - 'Cannot create callable from compact(), it cannot be called dynamically.', + 'Calling the callable created from compact() throws, it cannot be called dynamically.', 7, ], [ - 'Cannot create callable from extract(), it cannot be called dynamically.', + 'Calling the callable created from extract() throws, it cannot be called dynamically.', 8, ], [ - 'Cannot create callable from func_get_arg(), it cannot be called dynamically.', + 'Calling the callable created from func_get_arg() throws, it cannot be called dynamically.', 9, ], [ - 'Cannot create callable from func_get_args(), it cannot be called dynamically.', + 'Calling the callable created from func_get_args() throws, it cannot be called dynamically.', 10, ], [ - 'Cannot create callable from func_num_args(), it cannot be called dynamically.', + 'Calling the callable created from func_num_args() throws, it cannot be called dynamically.', 11, ], [ - 'Cannot create callable from get_defined_vars(), it cannot be called dynamically.', + 'Calling the callable created from get_defined_vars() throws, it cannot be called dynamically.', 12, ], [ @@ -113,7 +113,7 @@ public function testDynamicCallForbidden(): void 13, ], [ - 'Cannot create callable from compact(), it cannot be called dynamically.', + 'Calling the callable created from compact() throws, it cannot be called dynamically.', 13, ], ]; From b5d152fcb1ed80cb445510afd41f3f8a28dd29b7 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Tue, 10 Nov 2026 18:39:00 +0000 Subject: [PATCH 04/20] Resolve the templates a partial function application binds PartialFunctionApplicationParameters::apply() infers template types from the types of the bound arguments. In the closure's return type, a template no closure parameter mentions becomes the inferred type and is dropped from the closure's templates; one a closure parameter still mentions is unioned with it, as a call would. So repeat('a', ?) is Closure(int): list<'a'> and pair(?, 'x') is Closure(T): list<'x'|T>. The handlers pass the bound argument types from the scope, constant expressions resolve them with the initializer resolver, and the native twins pass them through the same PHP helper. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- .../Virtual/FunctionCallableNodeHandler.php | 9 +- .../Virtual/MethodCallableNodeHandler.php | 2 + .../StaticMethodCallableNodeHandler.php | 8 +- .../InitializerExprTypeResolver.php | 57 ++-- .../PartialFunctionApplicationParameters.php | 128 ++++++++- ...partial-function-application-signature.php | 39 +++ turbo-ext/src/FunctionCallableNodeHandler.cpp | 11 +- turbo-ext/src/InitializerExprTypeResolver.cpp | 135 ++++++---- .../src/InstantiationCallableNodeHandler.cpp | 4 +- turbo-ext/src/MethodCallableNodeHandler.cpp | 7 +- .../src/StaticMethodCallableNodeHandler.cpp | 12 +- turbo-ext/src/VirtualExprHandlers.h | 29 ++- .../generated/InitializerExprTypeResolver.h | 244 +++++++++--------- turbo-ext/src/support.h | 9 +- 14 files changed, 486 insertions(+), 208 deletions(-) diff --git a/src/Analyser/ExprHandler/Virtual/FunctionCallableNodeHandler.php b/src/Analyser/ExprHandler/Virtual/FunctionCallableNodeHandler.php index f75dccaba97..20aca1ca69e 100644 --- a/src/Analyser/ExprHandler/Virtual/FunctionCallableNodeHandler.php +++ b/src/Analyser/ExprHandler/Virtual/FunctionCallableNodeHandler.php @@ -24,6 +24,7 @@ use PHPStan\Node\FunctionCallableNode; use PHPStan\Reflection\InitializerExprContext; use PHPStan\Reflection\InitializerExprTypeResolver; +use PHPStan\Reflection\PartialFunctionApplicationParameters; use PHPStan\Reflection\ReflectionProvider; use PHPStan\ShouldNotHappenException; use PHPStan\Turbo\ShadowedByTurboExtension; @@ -171,10 +172,16 @@ private function resolveType(MutatingScope $scope, FunctionCallableNode $expr, ? $callableType->getCallableParametersAcceptors($scope), $scope->nativeTypesPromoted, $isFirstClassCallable ? null : $originalNode->getRawArgs(), + $isFirstClassCallable ? [] : PartialFunctionApplicationParameters::getBoundArgTypes($scope, $originalNode), ); } - return $this->initializerExprTypeResolver->getFirstClassCallableType($originalNode, InitializerExprContext::fromScope($scope), $scope->nativeTypesPromoted); + return $this->initializerExprTypeResolver->getFirstClassCallableType( + $originalNode, + InitializerExprContext::fromScope($scope), + $scope->nativeTypesPromoted, + $originalNode->isFirstClassCallable() ? null : PartialFunctionApplicationParameters::getBoundArgTypes($scope, $originalNode), + ); } private static function isClosureObject(Type $type): bool diff --git a/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php b/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php index b4aefd75347..8e561f436f4 100644 --- a/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php +++ b/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php @@ -23,6 +23,7 @@ use PHPStan\DependencyInjection\AutowiredService; use PHPStan\Node\MethodCallableNode; use PHPStan\Reflection\InitializerExprTypeResolver; +use PHPStan\Reflection\PartialFunctionApplicationParameters; use PHPStan\Turbo\ShadowedByTurboExtension; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; @@ -159,6 +160,7 @@ private function resolveType(MutatingScope $scope, MethodCallableNode $expr, Exp $method->getVariants(), $scope->nativeTypesPromoted, $originalNode->isFirstClassCallable() ? null : $originalNode->getRawArgs(), + $originalNode->isFirstClassCallable() ? [] : PartialFunctionApplicationParameters::getBoundArgTypes($scope, $originalNode), ); } diff --git a/src/Analyser/ExprHandler/Virtual/StaticMethodCallableNodeHandler.php b/src/Analyser/ExprHandler/Virtual/StaticMethodCallableNodeHandler.php index e8b84371f33..9d6ee3e47ba 100644 --- a/src/Analyser/ExprHandler/Virtual/StaticMethodCallableNodeHandler.php +++ b/src/Analyser/ExprHandler/Virtual/StaticMethodCallableNodeHandler.php @@ -23,6 +23,7 @@ use PHPStan\Node\StaticMethodCallableNode; use PHPStan\Reflection\InitializerExprContext; use PHPStan\Reflection\InitializerExprTypeResolver; +use PHPStan\Reflection\PartialFunctionApplicationParameters; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Turbo\ShadowedByTurboExtension; use PHPStan\Type\Type; @@ -103,7 +104,12 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex isAlwaysTerminating: $isAlwaysTerminating, throwPoints: $throwPoints, impurePoints: $impurePoints, - typeCallback: fn (bool $nativeTypesPromoted): Type => $this->initializerExprTypeResolver->getFirstClassCallableType($expr->getOriginalNode(), InitializerExprContext::fromScope($beforeScope), $nativeTypesPromoted), + typeCallback: fn (bool $nativeTypesPromoted): Type => $this->initializerExprTypeResolver->getFirstClassCallableType( + $expr->getOriginalNode(), + InitializerExprContext::fromScope($beforeScope), + $nativeTypesPromoted, + $expr->getOriginalNode()->isFirstClassCallable() ? null : PartialFunctionApplicationParameters::getBoundArgTypes($nativeTypesPromoted ? $beforeScope->doNotTreatPhpDocTypesAsCertain() : $beforeScope, $expr->getOriginalNode()), + ), specifyTypesCallback: fn (TypeSpecifierContext $context, bool $nativeTypesPromoted) => $this->defaultNarrowingHelper->specifyDefaultTypes($expr, $context), ); diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index b7917ce07a5..8c5b14c00af 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -790,9 +790,25 @@ private function isParameterValueNullable(Param $parameter): bool return false; } - public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprContext $context, bool $nativeTypesPromoted): Type + /** + * @param array|null $boundArgTypes the types of the bound arguments of a partial function application, + * keyed like its raw arguments; null to resolve them as constant expressions + */ + public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprContext $context, bool $nativeTypesPromoted, ?array $boundArgTypes = null): Type { - $partialApplicationArgs = $expr->isFirstClassCallable() ? null : $expr->getRawArgs(); + $partialApplicationArgs = null; + if (!$expr->isFirstClassCallable()) { + $partialApplicationArgs = $expr->getRawArgs(); + if ($boundArgTypes === null) { + $boundArgTypes = []; + foreach ($partialApplicationArgs as $i => $arg) { + if (!$arg instanceof Arg) { + continue; + } + $boundArgTypes[$i] = $this->getType($arg->value, $context); + } + } + } if ($expr instanceof FuncCall) { if ($expr->name instanceof Name) { @@ -803,6 +819,7 @@ public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprCo $function->getVariants(), $nativeTypesPromoted, $partialApplicationArgs, + $boundArgTypes ?? [], ); } @@ -842,6 +859,7 @@ public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprCo $method->getVariants(), $nativeTypesPromoted, $partialApplicationArgs, + $boundArgTypes ?? [], ); } @@ -855,12 +873,14 @@ public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprCo /** * @param ParametersAcceptor[] $variants * @param array|null $partialApplicationArgs the arguments of a partial function application, null for a first-class callable + * @param array $boundArgTypes the types of the bound arguments of a partial function application, keyed like $partialApplicationArgs */ public function createFirstClassCallable( FunctionReflection|ExtendedMethodReflection|null $function, array $variants, bool $nativeTypesPromoted, ?array $partialApplicationArgs = null, + array $boundArgTypes = [], ): Type { // variants of multi-variant built-ins carry functionMap parameter names, @@ -882,19 +902,6 @@ public function createFirstClassCallable( $returnType = $nativeTypesPromoted ? $variant->getNativeReturnType() : $returnType; } - $templateTags = []; - foreach ($variant->getTemplateTypeMap()->getTypes() as $templateType) { - if (!$templateType instanceof TemplateType) { - continue; - } - $templateTags[$templateType->getName()] = new TemplateTag( - $templateType->getName(), - $templateType->getBound(), - $templateType->getDefault(), - $templateType->getVariance(), - ); - } - $throwPoints = []; $impurePoints = []; $acceptsNamedArguments = TrinaryLogic::createYes(); @@ -939,13 +946,27 @@ public function createFirstClassCallable( $parameters = self::renameParameters($parameters, $namedArgumentNames); } $isVariadic = $variant->isVariadic(); + $templateTypeMap = $variant->getTemplateTypeMap(); if ($partialApplicationArgs !== null) { - $partialApplication = PartialFunctionApplicationParameters::apply($parameters, $partialApplicationArgs); + $partialApplication = PartialFunctionApplicationParameters::apply($parameters, $partialApplicationArgs, $boundArgTypes, $returnType, $templateTypeMap); if ($partialApplication === null) { // creating the closure from this variant throws continue; } - [$parameters, $isVariadic] = $partialApplication; + [$parameters, $isVariadic, $returnType, $templateTypeMap] = $partialApplication; + } + + $templateTags = []; + foreach ($templateTypeMap->getTypes() as $templateType) { + if (!$templateType instanceof TemplateType) { + continue; + } + $templateTags[$templateType->getName()] = new TemplateTag( + $templateType->getName(), + $templateType->getBound(), + $templateType->getDefault(), + $templateType->getVariance(), + ); } if ($function !== null) { $assertions = $function->getAsserts(); @@ -963,7 +984,7 @@ public function createFirstClassCallable( $parameters, $returnType, $isVariadic, - $variant->getTemplateTypeMap(), + $templateTypeMap, $variant->getResolvedTemplateTypeMap(), $variant instanceof ExtendedParametersAcceptor ? $variant->getCallSiteVarianceMap() : TemplateTypeVarianceMap::createEmpty(), $templateTags, diff --git a/src/Reflection/PartialFunctionApplicationParameters.php b/src/Reflection/PartialFunctionApplicationParameters.php index 6a29db6aa69..1d773fb7f32 100644 --- a/src/Reflection/PartialFunctionApplicationParameters.php +++ b/src/Reflection/PartialFunctionApplicationParameters.php @@ -4,10 +4,17 @@ use PhpParser\Node\Arg; use PhpParser\Node\ArgPlaceholder; +use PhpParser\Node\Expr\CallLike; use PhpParser\Node\VariadicPlaceholder; +use PHPStan\Analyser\Scope; use PHPStan\Reflection\Php\DummyParameter; use PHPStan\Reflection\Php\ExtendedDummyParameter; use PHPStan\Turbo\ReferencedByTurboExtension; +use PHPStan\Type\Generic\TemplateType; +use PHPStan\Type\Generic\TemplateTypeMap; +use PHPStan\Type\Type; +use PHPStan\Type\TypeCombinator; +use PHPStan\Type\TypeTraverser; use function array_key_exists; use function count; @@ -32,13 +39,97 @@ final class PartialFunctionApplicationParameters { + /** + * The closure's parameters, whether it is variadic, its return type and its template types. + * + * Templates the bound arguments infer are resolved: in the return type, a template + * no closure parameter mentions becomes the inferred type, and one a closure parameter + * still mentions is joined with it, since a call unions what both bring to it. + * + * @param list $parameters + * @param array $args + * @param array $boundArgTypes the types of the bound arguments, keyed like $args + * @return array{list, bool, Type, TemplateTypeMap}|null null when creating the closure throws + */ + public static function apply(array $parameters, array $args, array $boundArgTypes, Type $returnType, TemplateTypeMap $templateTypeMap): ?array + { + $mapped = self::map($parameters, $args); + if ($mapped === null) { + return null; + } + [$closureParameters, $isVariadic, $bound] = $mapped; + if ($templateTypeMap->isEmpty()) { + return [$closureParameters, $isVariadic, $returnType, $templateTypeMap]; + } + + $inferred = TemplateTypeMap::createEmpty(); + foreach ($bound as [$parameter, $argIndex]) { + if (!isset($boundArgTypes[$argIndex])) { + continue; + } + $inferred = $inferred->union($parameter->getType()->inferTemplateTypes($boundArgTypes[$argIndex])); + } + if ($inferred->isEmpty()) { + return [$closureParameters, $isVariadic, $returnType, $templateTypeMap]; + } + + $inClosureParameters = []; + foreach ($closureParameters as $parameter) { + TypeTraverser::map($parameter->getType(), static function (Type $type, callable $traverse) use ($templateTypeMap, &$inClosureParameters): Type { + if (self::isOwnTemplate($type, $templateTypeMap)) { + $inClosureParameters[$type->getName()] = true; + } + + return $traverse($type); + }); + } + + $returnType = TypeTraverser::map($returnType, static function (Type $type, callable $traverse) use ($templateTypeMap, $inferred, $inClosureParameters): Type { + if (!self::isOwnTemplate($type, $templateTypeMap)) { + return $traverse($type); + } + $inferredType = $inferred->getType($type->getName()); + if ($inferredType === null) { + return $type; + } + if (isset($inClosureParameters[$type->getName()])) { + return TypeCombinator::union($type, $inferredType); + } + + return $inferredType; + }); + + $closureTemplateTypes = []; + foreach ($templateTypeMap->getTypes() as $name => $templateType) { + if (!isset($inClosureParameters[$name]) && $inferred->hasType($name)) { + continue; + } + $closureTemplateTypes[$name] = $templateType; + } + + return [$closureParameters, $isVariadic, $returnType, new TemplateTypeMap($closureTemplateTypes)]; + } + + /** + * @phpstan-assert-if-true TemplateType $type + */ + private static function isOwnTemplate(Type $type, TemplateTypeMap $templateTypeMap): bool + { + if (!$type instanceof TemplateType) { + return false; + } + $templateType = $templateTypeMap->getType($type->getName()); + + return $templateType instanceof TemplateType && $templateType->getScope()->equals($type->getScope()); + } + /** * @param list $parameters * @param array $args - * @return array{list, bool}|null the closure's parameters and whether it is variadic, - * null when creating the closure throws + * @return array{list, bool, list}|null the closure's parameters, + * whether it is variadic and the parameters the bound arguments go to, null when creating the closure throws */ - public static function apply(array $parameters, array $args): ?array + private static function map(array $parameters, array $args): ?array { $variadicParameter = null; $declared = $parameters; @@ -59,7 +150,8 @@ public static function apply(array $parameters, array $args): ?array $position = 0; $variadicPlaceholders = 0; $seenNamed = false; - foreach ($args as $arg) { + $bound = []; + foreach ($args as $argIndex => $arg) { if ($arg instanceof VariadicPlaceholder) { $hasVariadicPlaceholder = true; continue; @@ -85,11 +177,15 @@ public static function apply(array $parameters, array $args): ?array $covered[$position] = true; if ($isPlaceholder) { $positional[] = self::required($declared[$position], $declared[$position]->getName()); + } else { + $bound[] = [$declared[$position], $argIndex]; } } elseif ($variadicParameter !== null) { if ($isPlaceholder) { $positional[] = self::required($variadicParameter, $variadicParameter->getName() . $variadicPlaceholders); $variadicPlaceholders++; + } else { + $bound[] = [$variadicParameter, $argIndex]; } } else { // too many arguments @@ -107,6 +203,7 @@ public static function apply(array $parameters, array $args): ?array // or an unknown named argument without a variadic to collect it return null; } + $bound[] = [$variadicParameter, $argIndex]; continue; } @@ -117,6 +214,7 @@ public static function apply(array $parameters, array $args): ?array } $covered[$index] = true; if (!$isPlaceholder) { + $bound[] = [$declared[$index], $argIndex]; continue; } @@ -132,7 +230,7 @@ public static function apply(array $parameters, array $args): ?array } } - return [$closureParameters, false]; + return [$closureParameters, false, $bound]; } foreach ($declared as $i => $parameter) { @@ -145,7 +243,23 @@ public static function apply(array $parameters, array $args): ?array $closureParameters[] = $variadicParameter; } - return [$closureParameters, $variadicParameter !== null]; + return [$closureParameters, $variadicParameter !== null, $bound]; + } + + /** + * @return array the types of the bound arguments, keyed like the raw arguments + */ + public static function getBoundArgTypes(Scope $scope, CallLike $call): array + { + $types = []; + foreach ($call->getRawArgs() as $i => $arg) { + if (!$arg instanceof Arg) { + continue; + } + $types[$i] = $scope->getType($arg->value); + } + + return $types; } /** @@ -173,7 +287,7 @@ public static function selectVariant(array $args, array $variants, ?array $named $fitting = []; foreach ($variants as $variant) { - if (self::apply($variant->getParameters(), $args) === null) { + if (self::map($variant->getParameters(), $args) === null) { continue; } $fitting[] = $variant; diff --git a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php index d56afb066d8..eaac3b3eb3a 100644 --- a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php +++ b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php @@ -38,6 +38,27 @@ function identity($a) return $a; } +/** + * @template T + * @param T $value + * @param T $other + * @return list + */ +function pair($value, $other): array +{ + return [$value, $other]; +} + +/** + * @template T + * @param T $value + * @return list + */ +function repeat($value, int $times): array +{ + return []; +} + class Foo { @@ -68,6 +89,8 @@ class Constants const PARTIAL = doFoo(1, ?, ...); + const REPEATED = repeat('a', ?); + } function functions(): void @@ -120,6 +143,21 @@ function functions(): void // templates assertType('Closure(T): T', identity(?)); + assertType('Closure(int): list<\'a\'>', repeat('a', ?)); + assertType('Closure(T): list', repeat(?, 3)); + // a template a closure parameter still mentions gets what the bound arguments bring to it + assertType('Closure(T): list<\'x\'|T>', pair(?, 'x')); + $pair = pair(?, 'x'); + assertType('list<1|\'x\'>', $pair(1)); +} + +/** + * @param list $ints + */ +function templatesThroughCallbacks(array $ints): void +{ + assertType('list>', array_map(pair(?, 'x'), $ints)); + assertType('list>', array_map(repeat(?, 2), $ints)); } function methods(Foo $foo): void @@ -140,6 +178,7 @@ function closures(Invokable $i): void assertType('Closure(string): bool', $i(1, ?)); assertType('Closure(int): bool', $i->__invoke(?, 'x')); assertType('Closure(string, float, bool ...): string', Constants::PARTIAL); + assertType('Closure(int): list<\'a\'>', Constants::REPEATED); $c = fn (int $a, string $b, float $c = 1.0): int => 1; assertType('Closure(string): 1', $c(1, ?)); diff --git a/turbo-ext/src/FunctionCallableNodeHandler.cpp b/turbo-ext/src/FunctionCallableNodeHandler.cpp index bfb34cf140d..52f6a7ae974 100644 --- a/turbo-ext/src/FunctionCallableNodeHandler.cpp +++ b/turbo-ext/src/FunctionCallableNodeHandler.cpp @@ -298,14 +298,21 @@ class FunctionCallableNodeHandler partialApplicationArgs = pt_call_like_raw_args(Z_OBJ_P(originalNode), rawArgsHold); if (UNEXPECTED(partialApplicationArgs == NULL)) return zv::Val(); } - return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), &null, acceptors.raw(), nativeTypesPromoted, partialApplicationArgs); + zv::Val boundArgTypes; + if (UNEXPECTED(!ptveh::boundArgTypesOrNull(scope, originalNode, boundArgTypes))) return zv::Val(); + if (boundArgTypes.isNull()) { + boundArgTypes = zv::Val(zv::Arr::empty()); + } + return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), &null, acceptors.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes.raw()); } zv::Val initializerExprContext = ptveh::initializerExprContextFromScope(scope); if (UNEXPECTED(initializerExprContext.isUndef())) return zv::Val(); bool nativeTypesPromoted; if (UNEXPECTED(!pt_mutating_scope_native_types_promoted(Z_OBJ_P(scope), nativeTypesPromoted))) return zv::Val(); - return ptveh::getFirstClassCallableType(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), originalNode, initializerExprContext.raw(), nativeTypesPromoted); + zv::Val boundArgTypes; + if (UNEXPECTED(!ptveh::boundArgTypesOrNull(scope, originalNode, boundArgTypes))) return zv::Val(); + return ptveh::getFirstClassCallableType(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), originalNode, initializerExprContext.raw(), nativeTypesPromoted, boundArgTypes.raw()); } /* the handler entry (Engine.h) */ diff --git a/turbo-ext/src/InitializerExprTypeResolver.cpp b/turbo-ext/src/InitializerExprTypeResolver.cpp index 2d75a8316d8..81bdecde90c 100644 --- a/turbo-ext/src/InitializerExprTypeResolver.cpp +++ b/turbo-ext/src/InitializerExprTypeResolver.cpp @@ -1243,7 +1243,9 @@ class InitializerExprTypeResolver bool firstClassCallable; if (UNEXPECTED(!pt_call_like_is_partial_function_application(Z_OBJ_P(expr), firstClassCallable))) return zv::Val(); if (firstClassCallable) { - return getFirstClassCallableType(expr, context, false); + zval nullBoundArgTypes; + ZVAL_NULL(&nullBoundArgTypes); + return getFirstClassCallableType(expr, context, false, &nullBoundArgTypes); } break; } @@ -2164,8 +2166,8 @@ class InitializerExprTypeResolver return 0; } - /* Mirrors getFirstClassCallableType(). */ - zv::Val getFirstClassCallableType(zval *expr, zval *context, bool nativeTypesPromoted) const + /* Mirrors getFirstClassCallableType(); $boundArgTypes PHP null for null */ + zv::Val getFirstClassCallableType(zval *expr, zval *context, bool nativeTypesPromoted, zval *boundArgTypesIn) const { bool firstClassCallable; if (UNEXPECTED(!pt_call_like_is_first_class_callable(Z_OBJ_P(expr), firstClassCallable))) return zv::Val(); @@ -2173,9 +2175,38 @@ class InitializerExprTypeResolver ZVAL_NULL(&nullArgs); zval *partialApplicationArgs = &nullArgs; zv::Val rawArgsHold; + // $boundArgTypes ?? [] + zv::Val boundArgTypesHold = zv::Val(zv::Arr::empty()); + zval *boundArgTypes = boundArgTypesHold.raw(); if (!firstClassCallable) { partialApplicationArgs = pt_call_like_raw_args(Z_OBJ_P(expr), rawArgsHold); if (UNEXPECTED(partialApplicationArgs == NULL)) return zv::Val(); + if (Z_TYPE_P(boundArgTypesIn) != IS_NULL) { + boundArgTypes = boundArgTypesIn; + } else { + if (UNEXPECTED(!requireArray(partialApplicationArgs))) return zv::Val(); + zv::Arr resolved = zv::Arr::create(0); + for (zv::ArrayEntry entry : zv::ArrRef(partialApplicationArgs)) { + zval *arg = entry.value().deref().raw(); + int isArg = isAClass(arg, PT_CLASS_ARG); + if (UNEXPECTED(isArg < 0)) return zv::Val(); + if (!isArg) { + continue; + } + zval *value = nodeProp(pt_ietr_arg_value, arg); + if (UNEXPECTED(value == NULL)) return zv::Val(); + IETR_VAL(argType, getType(value, context)); + zval key; + if (entry.hasStringKey()) { + ZVAL_STR(&key, entry.stringKey()); + } else { + ZVAL_LONG(&key, (zend_long) entry.indexKey()); + } + if (UNEXPECTED(!arrayKeyUpdate(resolved, &key, std::move(argType)))) return zv::Val(); + } + boundArgTypesHold = zv::Val(std::move(resolved)); + boundArgTypes = boundArgTypesHold.raw(); + } } int isFuncCall = isAClass(expr, PT_CLASS_FUNC_CALL); @@ -2195,7 +2226,7 @@ class InitializerExprTypeResolver IETR_VAL(reflectionProvider, reflectionProviderOf(prop(slots::reflectionProviderProvider))); IETR_VAL(function, pt_reflection_provider_get_function(reflectionProvider.raw(), name, context)); IETR_VAL(variants, callOn(function.raw(), mGetVariants)); - return createFirstClassCallable(function.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs); + return createFirstClassCallable(function.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes); } return newObjectTypeLiteral(PT_LC("Closure")); @@ -2271,7 +2302,7 @@ class InitializerExprTypeResolver } IETR_VAL(variants, callOn(method.raw(), mGetVariants)); - return createFirstClassCallable(method.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs); + return createFirstClassCallable(method.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes); } int isNew = isAClass(expr, PT_CLASS_NEW); @@ -2338,7 +2369,7 @@ class InitializerExprTypeResolver } /* Mirrors createFirstClassCallable(); $function and $partialApplicationArgs PHP null for null */ - static zv::Val createFirstClassCallable(zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs) + static zv::Val createFirstClassCallable(zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes) { bool partialApplication = Z_TYPE_P(partialApplicationArgs) != IS_NULL; if (UNEXPECTED(Z_TYPE_P(variants) != IS_ARRAY)) { @@ -2388,27 +2419,6 @@ class InitializerExprTypeResolver returnType = std::move(nativeReturnType); } - zv::Arr templateTags = zv::Arr::create(0); - { - IETR_VAL(templateTypeMap, callOn(variant, mGetTemplateTypeMap)); - IETR_VAL(templateTypes, callOn(templateTypeMap.raw(), mGetTypes)); - if (UNEXPECTED(!requireArray(templateTypes.raw()))) return zv::Val(); - for (zv::ArrayEntry entry : zv::ArrRef(templateTypes.raw())) { - zval *templateType = entry.value().raw(); - if (!isA(templateType, templateTypeCe)) { - continue; - } - IETR_VAL(tagName, callOn(templateType, mGetName)); - IETR_VAL(name, callOn(templateType, mGetName)); - IETR_VAL(bound, callOn(templateType, mGetBound)); - IETR_VAL(defaultType, callOn(templateType, mGetDefault)); - IETR_VAL(variance, callOn(templateType, mGetVariance)); - zv::Args tagArgs{name.raw(), bound.raw(), defaultType.raw(), variance.raw()}; - IETR_VAL(tag, pt_type_new(PT_CLASS_TEMPLATE_TAG, 4, tagArgs)); - if (UNEXPECTED(!arrayKeyUpdate(templateTags, tagName.raw(), std::move(tag)))) return zv::Val(); - } - } - zv::Val throwPoints = zv::Val(zv::Arr::empty()); zv::Val impurePoints = zv::Val(zv::Arr::empty()); zv::Val acceptsNamedArguments = zv::Val::copyOf(zv::Ref(pt_trinary_singleton(PT_TRI_YES))); @@ -2487,10 +2497,12 @@ class InitializerExprTypeResolver } IETR_VAL(isVariadicHold, callOn(variant, mIsVariadic)); bool isVariadic = zend_is_true(isVariadicHold.raw()); + IETR_VAL(templateTypeMapInit, callOn(variant, mGetTemplateTypeMap)); + zv::Val templateTypeMap = std::move(templateTypeMapInit); if (partialApplication) { static pt_method_site applySite; - zv::Args applyArgv{parameters.raw(), partialApplicationArgs}; - IETR_VAL(applied, pt_call_static_cached(applySite, PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS, PT_LC("apply"), 2, applyArgv)); + zv::Args applyArgv{parameters.raw(), partialApplicationArgs, boundArgTypes, returnType.raw(), templateTypeMap.raw()}; + IETR_VAL(applied, pt_call_static_cached(applySite, PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS, PT_LC("apply"), 5, applyArgv)); if (Z_TYPE_P(applied.raw()) == IS_NULL) { // creating the closure from this variant throws continue; @@ -2498,12 +2510,36 @@ class InitializerExprTypeResolver if (UNEXPECTED(!requireArray(applied.raw()))) return zv::Val(); zval *appliedParameters = zend_hash_index_find(Z_ARRVAL_P(applied.raw()), 0); zval *appliedIsVariadic = zend_hash_index_find(Z_ARRVAL_P(applied.raw()), 1); - if (UNEXPECTED(appliedParameters == NULL || appliedIsVariadic == NULL)) { + zval *appliedReturnType = zend_hash_index_find(Z_ARRVAL_P(applied.raw()), 2); + zval *appliedTemplateTypeMap = zend_hash_index_find(Z_ARRVAL_P(applied.raw()), 3); + if (UNEXPECTED(appliedParameters == NULL || appliedIsVariadic == NULL || appliedReturnType == NULL || appliedTemplateTypeMap == NULL)) { pt_throw_should_not_happen(); return zv::Val(); } parameters = zv::Val::copyOf(zv::Ref(appliedParameters)); isVariadic = zend_is_true(appliedIsVariadic); + returnType = zv::Val::copyOf(zv::Ref(appliedReturnType)); + templateTypeMap = zv::Val::copyOf(zv::Ref(appliedTemplateTypeMap)); + } + + zv::Arr templateTags = zv::Arr::create(0); + { + IETR_VAL(templateTypes, callOn(templateTypeMap.raw(), mGetTypes)); + if (UNEXPECTED(!requireArray(templateTypes.raw()))) return zv::Val(); + for (zv::ArrayEntry entry : zv::ArrRef(templateTypes.raw())) { + zval *templateType = entry.value().raw(); + if (!isA(templateType, templateTypeCe)) { + continue; + } + IETR_VAL(tagName, callOn(templateType, mGetName)); + IETR_VAL(name, callOn(templateType, mGetName)); + IETR_VAL(bound, callOn(templateType, mGetBound)); + IETR_VAL(defaultType, callOn(templateType, mGetDefault)); + IETR_VAL(variance, callOn(templateType, mGetVariance)); + zv::Args tagArgs{name.raw(), bound.raw(), defaultType.raw(), variance.raw()}; + IETR_VAL(tag, pt_type_new(PT_CLASS_TEMPLATE_TAG, 4, tagArgs)); + if (UNEXPECTED(!arrayKeyUpdate(templateTags, tagName.raw(), std::move(tag)))) return zv::Val(); + } } zv::Val assertions; if (hasFunction) { @@ -2519,7 +2555,6 @@ class InitializerExprTypeResolver // like @return ($value is int ? true : false) on is_int(), // also becomes a type predicate of the resulting Closure IETR_VAL(predicateAssertions, withConditionalReturnPredicate(assertions.raw(), variant)); - IETR_VAL(templateTypeMap, callOn(variant, mGetTemplateTypeMap)); IETR_VAL(resolvedTemplateTypeMap, callOn(variant, mGetResolvedTemplateTypeMap)); zv::Val callSiteVarianceMap = extendedAcceptor ? callOn(variant, mGetCallSiteVarianceMap) @@ -3500,20 +3535,20 @@ zv::Val pt_initializer_expr_type_resolver_get_function_type(zval *resolver, zval return callResolverMethod(site, resolver, PT_LC("getfunctiontype"), 4, argv); } -zv::Val pt_initializer_expr_type_resolver_get_first_class_callable_type(zval *resolver, zval *expr, zval *context, bool nativeTypesPromoted) +zv::Val pt_initializer_expr_type_resolver_get_first_class_callable_type(zval *resolver, zval *expr, zval *context, bool nativeTypesPromoted, zval *boundArgTypes) { - if (EXPECTED(isNativeResolver(resolver))) return InitializerExprTypeResolver(Z_OBJ_P(resolver)).getFirstClassCallableType(expr, context, nativeTypesPromoted); + if (EXPECTED(isNativeResolver(resolver))) return InitializerExprTypeResolver(Z_OBJ_P(resolver)).getFirstClassCallableType(expr, context, nativeTypesPromoted, boundArgTypes); static pt_method_site site; - zv::Args argv{expr, context, nativeTypesPromoted}; - return callResolverMethod(site, resolver, PT_LC("getfirstclasscallabletype"), 3, argv); + zv::Args argv{expr, context, nativeTypesPromoted, boundArgTypes}; + return callResolverMethod(site, resolver, PT_LC("getfirstclasscallabletype"), 4, argv); } -zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs) +zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes) { - if (EXPECTED(isNativeResolver(resolver))) return InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted, partialApplicationArgs); + if (EXPECTED(isNativeResolver(resolver))) return InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes); static pt_method_site site; - zv::Args argv{function, variants, nativeTypesPromoted, partialApplicationArgs}; - return callResolverMethod(site, resolver, PT_LC("createfirstclasscallable"), 4, argv); + zv::Args argv{function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes}; + return callResolverMethod(site, resolver, PT_LC("createfirstclasscallable"), 5, argv); } zv::Val pt_initializer_expr_type_resolver_get_class_const_fetch_type_by_reflection(zval *resolver, zval *class_, zval *constantName, zval *classReflection, const pt_ietr_get_type &getTypeCallback, bool nativeTypesPromoted) @@ -3721,22 +3756,32 @@ PT_MINIT_REGISTRATION(pt_register_initializer_expr_type_resolver) }); cls.method(sigs::getFirstClassCallableType, [](INTERNAL_FUNCTION_PARAMETERS) { - zval *expr, *context; + zval *expr, *context, *boundArgTypes = NULL; bool nativeTypesPromoted; - if (!zp::parse(execute_data, expr, context, nativeTypesPromoted)) RETURN_THROWS(); + if (!zp::parse>(execute_data, expr, context, nativeTypesPromoted, boundArgTypes)) RETURN_THROWS(); if (UNEXPECTED(!ietrArgClass(expr, 1, PT_CLASS_CALL_LIKE, "PhpParser\\Node\\Expr\\CallLike") || !ietrArgContext(context, 2))) RETURN_THROWS(); - PT_RETURN_VAL(IETR_THIS.getFirstClassCallableType(expr, context, nativeTypesPromoted)); + zval nullBoundArgTypes; + if (boundArgTypes == NULL) { + ZVAL_NULL(&nullBoundArgTypes); + boundArgTypes = &nullBoundArgTypes; + } + PT_RETURN_VAL(IETR_THIS.getFirstClassCallableType(expr, context, nativeTypesPromoted, boundArgTypes)); }); cls.method(sigs::createFirstClassCallable, [](INTERNAL_FUNCTION_PARAMETERS) { - zval *function, *variants, *partialApplicationArgs = NULL; + zval *function, *variants, *partialApplicationArgs = NULL, *boundArgTypes = NULL; bool nativeTypesPromoted; - if (!zp::parse>(execute_data, function, variants, nativeTypesPromoted, partialApplicationArgs)) RETURN_THROWS(); + if (!zp::parse, zp::Opt>(execute_data, function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes)) RETURN_THROWS(); zval nullArgs; if (partialApplicationArgs == NULL) { ZVAL_NULL(&nullArgs); partialApplicationArgs = &nullArgs; } + zval emptyBoundArgTypes; + if (boundArgTypes == NULL) { + ZVAL_EMPTY_ARRAY(&emptyBoundArgTypes); + boundArgTypes = &emptyBoundArgTypes; + } zval nullFunction; if (function == NULL) { ZVAL_NULL(&nullFunction); @@ -3750,7 +3795,7 @@ PT_MINIT_REGISTRATION(pt_register_initializer_expr_type_resolver) RETURN_THROWS(); } } - PT_RETURN_VAL(InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted, partialApplicationArgs)); + PT_RETURN_VAL(InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes)); }); cls.method(sigs::getBitwiseAndType, IETR_OPERATOR_GLUE(self.getOperatorType(IETR_BITWISE_AND, left, right, getTypeCallback))); diff --git a/turbo-ext/src/InstantiationCallableNodeHandler.cpp b/turbo-ext/src/InstantiationCallableNodeHandler.cpp index f3254efbdb6..537ce308707 100644 --- a/turbo-ext/src/InstantiationCallableNodeHandler.cpp +++ b/turbo-ext/src/InstantiationCallableNodeHandler.cpp @@ -194,7 +194,9 @@ class InstantiationCallableNodeHandler if (UNEXPECTED(originalNode == NULL)) return; zv::Val initializerExprContext = ptveh::initializerExprContextFromScope(&captures[2]); if (UNEXPECTED(initializerExprContext.isUndef())) return; - type = ptveh::getFirstClassCallableType(OBJ_PROP_NUM(Z_OBJ(captures[0]), slots::initializerExprTypeResolver), originalNode, initializerExprContext.raw(), nativeTypesPromoted); + zval nullBoundArgTypes; + ZVAL_NULL(&nullBoundArgTypes); + type = ptveh::getFirstClassCallableType(OBJ_PROP_NUM(Z_OBJ(captures[0]), slots::initializerExprTypeResolver), originalNode, initializerExprContext.raw(), nativeTypesPromoted, &nullBoundArgTypes); }); if (UNEXPECTED(type.isUndef())) return; type.intoReturnValue(return_value); diff --git a/turbo-ext/src/MethodCallableNodeHandler.cpp b/turbo-ext/src/MethodCallableNodeHandler.cpp index cfa6c1ca145..22a394a4e26 100644 --- a/turbo-ext/src/MethodCallableNodeHandler.cpp +++ b/turbo-ext/src/MethodCallableNodeHandler.cpp @@ -269,7 +269,12 @@ class MethodCallableNodeHandler partialApplicationArgs = pt_call_like_raw_args(Z_OBJ_P(originalNode), rawArgsHold); if (UNEXPECTED(partialApplicationArgs == NULL)) return zv::Val(); } - return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), method.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs); + zv::Val boundArgTypes; + if (UNEXPECTED(!ptveh::boundArgTypesOrNull(scope, originalNode, boundArgTypes))) return zv::Val(); + if (boundArgTypes.isNull()) { + boundArgTypes = zv::Val(zv::Arr::empty()); + } + return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), method.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes.raw()); } /* the handler entry (Engine.h) */ diff --git a/turbo-ext/src/StaticMethodCallableNodeHandler.cpp b/turbo-ext/src/StaticMethodCallableNodeHandler.cpp index c33ff9fbb8b..c649c01ba3a 100644 --- a/turbo-ext/src/StaticMethodCallableNodeHandler.cpp +++ b/turbo-ext/src/StaticMethodCallableNodeHandler.cpp @@ -282,7 +282,10 @@ class StaticMethodCallableNodeHandler /* fn (bool $nativeTypesPromoted): Type => * $this->initializerExprTypeResolver->getFirstClassCallableType($expr->getOriginalNode(), - * InitializerExprContext::fromScope($beforeScope), $nativeTypesPromoted) — + * InitializerExprContext::fromScope($beforeScope), $nativeTypesPromoted, + * $expr->getOriginalNode()->isFirstClassCallable() ? null : + * PartialFunctionApplicationParameters::getBoundArgTypes($nativeTypesPromoted + * ? $beforeScope->doNotTreatPhpDocTypesAsCertain() : $beforeScope, $expr->getOriginalNode())) — * captures: $this, $expr, $beforeScope */ static void typeCallbackBody(zval *captures, uint32_t argc, zval *argv, zval *return_value) { @@ -295,7 +298,12 @@ class StaticMethodCallableNodeHandler if (UNEXPECTED(originalNode == NULL)) return; zv::Val initializerExprContext = ptveh::initializerExprContextFromScope(&captures[2]); if (UNEXPECTED(initializerExprContext.isUndef())) return; - type = ptveh::getFirstClassCallableType(OBJ_PROP_NUM(Z_OBJ(captures[0]), slots::initializerExprTypeResolver), originalNode, initializerExprContext.raw(), nativeTypesPromoted); + zv::Val scopeHold; + zval *boundArgTypesScope = ptveh::promotedScope(&captures[2], nativeTypesPromoted, scopeHold); + if (UNEXPECTED(boundArgTypesScope == NULL)) return; + zv::Val boundArgTypes; + if (UNEXPECTED(!ptveh::boundArgTypesOrNull(boundArgTypesScope, originalNode, boundArgTypes))) return; + type = ptveh::getFirstClassCallableType(OBJ_PROP_NUM(Z_OBJ(captures[0]), slots::initializerExprTypeResolver), originalNode, initializerExprContext.raw(), nativeTypesPromoted, boundArgTypes.raw()); }); if (UNEXPECTED(type.isUndef())) return; type.intoReturnValue(return_value); diff --git a/turbo-ext/src/VirtualExprHandlers.h b/turbo-ext/src/VirtualExprHandlers.h index 08f752759a7..97a96cd6537 100644 --- a/turbo-ext/src/VirtualExprHandlers.h +++ b/turbo-ext/src/VirtualExprHandlers.h @@ -141,16 +141,33 @@ inline zval *nodeRead(NodeProp &prop, zval *node) * once they are ported) */ -/* $initializerExprTypeResolver->createFirstClassCallable($function, $variants, $nativeTypesPromoted, $partialApplicationArgs) */ -inline zv::Val createFirstClassCallable(zval *initializerExprTypeResolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs) +/* $initializerExprTypeResolver->createFirstClassCallable($function, $variants, $nativeTypesPromoted, $partialApplicationArgs, $boundArgTypes) */ +inline zv::Val createFirstClassCallable(zval *initializerExprTypeResolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes) { - return pt_initializer_expr_type_resolver_create_first_class_callable(initializerExprTypeResolver, function, variants, nativeTypesPromoted, partialApplicationArgs); + return pt_initializer_expr_type_resolver_create_first_class_callable(initializerExprTypeResolver, function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes); } -/* $initializerExprTypeResolver->getFirstClassCallableType($expr, $context, $nativeTypesPromoted) */ -inline zv::Val getFirstClassCallableType(zval *initializerExprTypeResolver, zval *expr, zval *context, bool nativeTypesPromoted) +/* $initializerExprTypeResolver->getFirstClassCallableType($expr, $context, $nativeTypesPromoted, $boundArgTypes) */ +inline zv::Val getFirstClassCallableType(zval *initializerExprTypeResolver, zval *expr, zval *context, bool nativeTypesPromoted, zval *boundArgTypes) { - return pt_initializer_expr_type_resolver_get_first_class_callable_type(initializerExprTypeResolver, expr, context, nativeTypesPromoted); + return pt_initializer_expr_type_resolver_get_first_class_callable_type(initializerExprTypeResolver, expr, context, nativeTypesPromoted, boundArgTypes); +} + +/* PartialFunctionApplicationParameters::getBoundArgTypes($scope, $call) for a partial + * function application, PHP null for a first-class callable (written into out, + * which owns it); false = pending exception */ +inline bool boundArgTypesOrNull(zval *scope, zval *call, zv::Val &out) +{ + bool firstClassCallable; + if (UNEXPECTED(!pt_call_like_is_first_class_callable(Z_OBJ_P(call), firstClassCallable))) return false; + if (firstClassCallable) { + out = zv::Val::null(); + return true; + } + static pt_method_site site; + zv::Args argv{scope, call}; + out = pt_call_static_cached(site, PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS, PT_LC("getboundargtypes"), 2, argv); + return !out.isUndef(); } /* InitializerExprContext::fromScope($scope) */ diff --git a/turbo-ext/src/generated/InitializerExprTypeResolver.h b/turbo-ext/src/generated/InitializerExprTypeResolver.h index 239f7de0676..e4ecd71a20f 100644 --- a/turbo-ext/src/generated/InitializerExprTypeResolver.h +++ b/turbo-ext/src/generated/InitializerExprTypeResolver.h @@ -95,62 +95,64 @@ inline constexpr char strings[] = "isParameterValueNullable\0" /* 981 */ "PhpParser\\Node\\Expr\\CallLike\0" /* 1006 */ "nativeTypesPromoted\0" /* 1035 */ - "getFirstClassCallableType\0" /* 1055 */ - "function\0" /* 1081 */ - "PHPStan\\Reflection\\FunctionReflection|PHPStan\\Reflection\\ExtendedMethodReflection\0" /* 1090 */ - "variants\0" /* 1172 */ - "partialApplicationArgs\0" /* 1181 */ - "createFirstClassCallable\0" /* 1204 */ - "parameters\0" /* 1229 */ - "names\0" /* 1240 */ - "renameParameters\0" /* 1246 */ - "getBitwiseAndType\0" /* 1263 */ - "getBitwiseOrType\0" /* 1281 */ - "getBitwiseXorType\0" /* 1298 */ - "getSpaceshipType\0" /* 1316 */ - "getDivType\0" /* 1333 */ - "getModType\0" /* 1344 */ - "getPlusType\0" /* 1355 */ - "getMinusType\0" /* 1367 */ - "getMulType\0" /* 1380 */ - "getPowType\0" /* 1391 */ - "getShiftLeftType\0" /* 1402 */ - "getShiftRightType\0" /* 1419 */ - "leftType\0" /* 1437 */ - "rightType\0" /* 1446 */ - "PHPStan\\Type\\TypeResult\0" /* 1456 */ - "resolveIdenticalType\0" /* 1480 */ - "resolveEqualType\0" /* 1501 */ - "isNonNumericString\0" /* 1518 */ - "PHPStan\\Type\\Constant\\ConstantArrayType\0" /* 1537 */ - "valueComparisonCallback\0" /* 1577 */ - "resolveConstantArrayTypeComparison\0" /* 1601 */ - "class\0" /* 1636 */ - "PhpParser\\Node\\Name|PhpParser\\Node\\Expr\0" /* 1642 */ - "constantName\0" /* 1682 */ - "classReflection\0" /* 1695 */ - "PHPStan\\Reflection\\ClassReflection\0" /* 1711 */ - "false\0" /* 1746 */ - "getClassConstFetchTypeByReflection\0" /* 1752 */ - "fetchedOnType\0" /* 1787 */ - "transformStaticType\0" /* 1801 */ - "getClassConstFetchType\0" /* 1821 */ - "getUnaryPlusType\0" /* 1844 */ - "getUnaryMinusType\0" /* 1861 */ - "getBitwiseNotType\0" /* 1879 */ - "getBitwiseNotTypeFromType\0" /* 1897 */ - "name\0" /* 1923 */ - "PhpParser\\Node\\Name\0" /* 1928 */ - "resolveName\0" /* 1948 */ - "PHPStan\\Type\\TypeWithClassName\0" /* 1960 */ - "resolveTypeByName\0" /* 1991 */ - "classType\0" /* 2009 */ - "methodReflectionCandidate\0" /* 2019 */ - "PHPStan\\Reflection\\MethodReflection\0" /* 2045 */ - "resolveTypeByNameWithLateStaticBinding\0" /* 2081 */ - "PHPStan\\Reflection\\ReflectionProvider\0" /* 2120 */ - "getReflectionProvider\0" /* 2158 */ - "getNeverType"; /* 2180 */ + "boundArgTypes\0" /* 1055 */ + "getFirstClassCallableType\0" /* 1069 */ + "function\0" /* 1095 */ + "PHPStan\\Reflection\\FunctionReflection|PHPStan\\Reflection\\ExtendedMethodReflection\0" /* 1104 */ + "variants\0" /* 1186 */ + "partialApplicationArgs\0" /* 1195 */ + "[]\0" /* 1218 */ + "createFirstClassCallable\0" /* 1221 */ + "parameters\0" /* 1246 */ + "names\0" /* 1257 */ + "renameParameters\0" /* 1263 */ + "getBitwiseAndType\0" /* 1280 */ + "getBitwiseOrType\0" /* 1298 */ + "getBitwiseXorType\0" /* 1315 */ + "getSpaceshipType\0" /* 1333 */ + "getDivType\0" /* 1350 */ + "getModType\0" /* 1361 */ + "getPlusType\0" /* 1372 */ + "getMinusType\0" /* 1384 */ + "getMulType\0" /* 1397 */ + "getPowType\0" /* 1408 */ + "getShiftLeftType\0" /* 1419 */ + "getShiftRightType\0" /* 1436 */ + "leftType\0" /* 1454 */ + "rightType\0" /* 1463 */ + "PHPStan\\Type\\TypeResult\0" /* 1473 */ + "resolveIdenticalType\0" /* 1497 */ + "resolveEqualType\0" /* 1518 */ + "isNonNumericString\0" /* 1535 */ + "PHPStan\\Type\\Constant\\ConstantArrayType\0" /* 1554 */ + "valueComparisonCallback\0" /* 1594 */ + "resolveConstantArrayTypeComparison\0" /* 1618 */ + "class\0" /* 1653 */ + "PhpParser\\Node\\Name|PhpParser\\Node\\Expr\0" /* 1659 */ + "constantName\0" /* 1699 */ + "classReflection\0" /* 1712 */ + "PHPStan\\Reflection\\ClassReflection\0" /* 1728 */ + "false\0" /* 1763 */ + "getClassConstFetchTypeByReflection\0" /* 1769 */ + "fetchedOnType\0" /* 1804 */ + "transformStaticType\0" /* 1818 */ + "getClassConstFetchType\0" /* 1838 */ + "getUnaryPlusType\0" /* 1861 */ + "getUnaryMinusType\0" /* 1878 */ + "getBitwiseNotType\0" /* 1896 */ + "getBitwiseNotTypeFromType\0" /* 1914 */ + "name\0" /* 1940 */ + "PhpParser\\Node\\Name\0" /* 1945 */ + "resolveName\0" /* 1965 */ + "PHPStan\\Type\\TypeWithClassName\0" /* 1977 */ + "resolveTypeByName\0" /* 2008 */ + "classType\0" /* 2026 */ + "methodReflectionCandidate\0" /* 2036 */ + "PHPStan\\Reflection\\MethodReflection\0" /* 2062 */ + "resolveTypeByNameWithLateStaticBinding\0" /* 2098 */ + "PHPStan\\Reflection\\ReflectionProvider\0" /* 2137 */ + "getReflectionProvider\0" /* 2175 */ + "getNeverType"; /* 2197 */ inline constexpr reg::PackedArg args[] = { reg::packed(0, 0, 17), /* __construct $constantResolver */ reg::packed(51, 0, 78), /* __construct $reflectionProviderProvider */ @@ -194,14 +196,16 @@ inline constexpr reg::PackedArg args[] = { reg::packed(551, 0, 1006), /* getFirstClassCallableType $expr */ reg::packed(576, 0, 584), /* getFirstClassCallableType $context */ reg::packed(1035, MAY_BE_BOOL), /* getFirstClassCallableType $nativeTypesPromoted */ + reg::packed(1055, MAY_BE_NULL | MAY_BE_ARRAY, reg::NoString, false, false, 825), /* getFirstClassCallableType $boundArgTypes */ reg::packed(626, 0, 627), /* getFirstClassCallableType return */ - reg::packed(1081, MAY_BE_NULL, 1090), /* createFirstClassCallable $function */ - reg::packed(1172, MAY_BE_ARRAY), /* createFirstClassCallable $variants */ + reg::packed(1095, MAY_BE_NULL, 1104), /* createFirstClassCallable $function */ + reg::packed(1186, MAY_BE_ARRAY), /* createFirstClassCallable $variants */ reg::packed(1035, MAY_BE_BOOL), /* createFirstClassCallable $nativeTypesPromoted */ - reg::packed(1181, MAY_BE_NULL | MAY_BE_ARRAY, reg::NoString, false, false, 825), /* createFirstClassCallable $partialApplicationArgs */ + reg::packed(1195, MAY_BE_NULL | MAY_BE_ARRAY, reg::NoString, false, false, 825), /* createFirstClassCallable $partialApplicationArgs */ + reg::packed(1055, MAY_BE_ARRAY, reg::NoString, false, false, 1218), /* createFirstClassCallable $boundArgTypes */ reg::packed(626, 0, 627), /* createFirstClassCallable return */ - reg::packed(1229, MAY_BE_ARRAY), /* renameParameters $parameters */ - reg::packed(1240, MAY_BE_ARRAY), /* renameParameters $names */ + reg::packed(1246, MAY_BE_ARRAY), /* renameParameters $parameters */ + reg::packed(1257, MAY_BE_ARRAY), /* renameParameters $names */ reg::packed(626, MAY_BE_ARRAY), /* renameParameters return */ reg::packed(703, 0, 556), /* getBitwiseAndType $left */ reg::packed(708, 0, 556), /* getBitwiseAndType $right */ @@ -251,31 +255,31 @@ inline constexpr reg::PackedArg args[] = { reg::packed(708, 0, 556), /* getShiftRightType $right */ reg::packed(714, MAY_BE_CALLABLE), /* getShiftRightType $getTypeCallback */ reg::packed(626, 0, 627), /* getShiftRightType return */ - reg::packed(1437, 0, 627), /* resolveIdenticalType $leftType */ - reg::packed(1446, 0, 627), /* resolveIdenticalType $rightType */ - reg::packed(626, 0, 1456), /* resolveIdenticalType return */ - reg::packed(1437, 0, 627), /* resolveEqualType $leftType */ - reg::packed(1446, 0, 627), /* resolveEqualType $rightType */ + reg::packed(1454, 0, 627), /* resolveIdenticalType $leftType */ + reg::packed(1463, 0, 627), /* resolveIdenticalType $rightType */ + reg::packed(626, 0, 1473), /* resolveIdenticalType return */ + reg::packed(1454, 0, 627), /* resolveEqualType $leftType */ + reg::packed(1463, 0, 627), /* resolveEqualType $rightType */ reg::packed(789, MAY_BE_NULL, 801, false, false, 825), /* resolveEqualType $phpVersions */ - reg::packed(626, 0, 1456), /* resolveEqualType return */ + reg::packed(626, 0, 1473), /* resolveEqualType return */ reg::packed(907, 0, 627), /* isNonNumericString $type */ reg::packed(789, MAY_BE_ARRAY), /* isNonNumericString $phpVersions */ reg::packed(626, MAY_BE_BOOL), /* isNonNumericString return */ - reg::packed(1437, 0, 1537), /* resolveConstantArrayTypeComparison $leftType */ - reg::packed(1446, 0, 1537), /* resolveConstantArrayTypeComparison $rightType */ - reg::packed(1577, MAY_BE_CALLABLE), /* resolveConstantArrayTypeComparison $valueComparisonCallback */ - reg::packed(626, 0, 1456), /* resolveConstantArrayTypeComparison return */ - reg::packed(1636, 0, 1642), /* getClassConstFetchTypeByReflection $class */ - reg::packed(1682, MAY_BE_STRING), /* getClassConstFetchTypeByReflection $constantName */ - reg::packed(1695, MAY_BE_NULL, 1711), /* getClassConstFetchTypeByReflection $classReflection */ + reg::packed(1454, 0, 1554), /* resolveConstantArrayTypeComparison $leftType */ + reg::packed(1463, 0, 1554), /* resolveConstantArrayTypeComparison $rightType */ + reg::packed(1594, MAY_BE_CALLABLE), /* resolveConstantArrayTypeComparison $valueComparisonCallback */ + reg::packed(626, 0, 1473), /* resolveConstantArrayTypeComparison return */ + reg::packed(1653, 0, 1659), /* getClassConstFetchTypeByReflection $class */ + reg::packed(1699, MAY_BE_STRING), /* getClassConstFetchTypeByReflection $constantName */ + reg::packed(1712, MAY_BE_NULL, 1728), /* getClassConstFetchTypeByReflection $classReflection */ reg::packed(714, MAY_BE_CALLABLE), /* getClassConstFetchTypeByReflection $getTypeCallback */ - reg::packed(1035, MAY_BE_BOOL, reg::NoString, false, false, 1746), /* getClassConstFetchTypeByReflection $nativeTypesPromoted */ + reg::packed(1035, MAY_BE_BOOL, reg::NoString, false, false, 1763), /* getClassConstFetchTypeByReflection $nativeTypesPromoted */ reg::packed(626, 0, 627), /* getClassConstFetchTypeByReflection return */ reg::packed(907, 0, 627), /* transformStaticType $type */ - reg::packed(1787, 0, 627), /* transformStaticType $fetchedOnType */ + reg::packed(1804, 0, 627), /* transformStaticType $fetchedOnType */ reg::packed(626, 0, 627), /* transformStaticType return */ - reg::packed(1636, 0, 1642), /* getClassConstFetchType $class */ - reg::packed(1682, MAY_BE_STRING), /* getClassConstFetchType $constantName */ + reg::packed(1653, 0, 1659), /* getClassConstFetchType $class */ + reg::packed(1699, MAY_BE_STRING), /* getClassConstFetchType $constantName */ reg::packed(653, MAY_BE_NULL | MAY_BE_STRING), /* getClassConstFetchType $className */ reg::packed(714, MAY_BE_CALLABLE), /* getClassConstFetchType $getTypeCallback */ reg::packed(626, 0, 627), /* getClassConstFetchType return */ @@ -290,19 +294,19 @@ inline constexpr reg::PackedArg args[] = { reg::packed(626, 0, 627), /* getBitwiseNotType return */ reg::packed(880, 0, 627), /* getBitwiseNotTypeFromType $exprType */ reg::packed(626, 0, 627), /* getBitwiseNotTypeFromType return */ - reg::packed(1923, 0, 1928), /* resolveName $name */ - reg::packed(1695, MAY_BE_NULL, 1711), /* resolveName $classReflection */ + reg::packed(1940, 0, 1945), /* resolveName $name */ + reg::packed(1712, MAY_BE_NULL, 1728), /* resolveName $classReflection */ reg::packed(626, MAY_BE_STRING), /* resolveName return */ - reg::packed(1923, 0, 1928), /* resolveTypeByName $name */ - reg::packed(1695, MAY_BE_NULL, 1711), /* resolveTypeByName $classReflection */ - reg::packed(626, 0, 1960), /* resolveTypeByName return */ - reg::packed(1636, 0, 1928), /* resolveTypeByNameWithLateStaticBinding $class */ - reg::packed(2009, 0, 627), /* resolveTypeByNameWithLateStaticBinding $classType */ - reg::packed(2019, 0, 2045), /* resolveTypeByNameWithLateStaticBinding $methodReflectionCandidate */ + reg::packed(1940, 0, 1945), /* resolveTypeByName $name */ + reg::packed(1712, MAY_BE_NULL, 1728), /* resolveTypeByName $classReflection */ + reg::packed(626, 0, 1977), /* resolveTypeByName return */ + reg::packed(1653, 0, 1945), /* resolveTypeByNameWithLateStaticBinding $class */ + reg::packed(2026, 0, 627), /* resolveTypeByNameWithLateStaticBinding $classType */ + reg::packed(2036, 0, 2062), /* resolveTypeByNameWithLateStaticBinding $methodReflectionCandidate */ reg::packed(626, 0, 627), /* resolveTypeByNameWithLateStaticBinding return */ - reg::packed(626, 0, 2120), /* getReflectionProvider return */ - reg::packed(1437, 0, 627), /* getNeverType $leftType */ - reg::packed(1446, 0, 627), /* getNeverType $rightType */ + reg::packed(626, 0, 2137), /* getReflectionProvider return */ + reg::packed(1454, 0, 627), /* getNeverType $leftType */ + reg::packed(1463, 0, 627), /* getNeverType $rightType */ reg::packed(626, 0, 627), /* getNeverType return */ }; using Sig = reg::Sig; @@ -320,37 +324,37 @@ inline constexpr sigtab::Sig getCastType = { { 868 /* getCastType */, 2, 27, 2, inline constexpr sigtab::Sig getCastObjectType = { { 889 /* getCastObjectType */, 1, 30, 1, 31, ZEND_ACC_PUBLIC } }; inline constexpr sigtab::Sig getFunctionType = { { 934 /* getFunctionType */, 4, 32, 4, 36, ZEND_ACC_PUBLIC } }; inline constexpr sigtab::Sig isParameterValueNullable = { { 981 /* isParameterValueNullable */, 1, 37, 1, 38, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getFirstClassCallableType = { { 1055 /* getFirstClassCallableType */, 3, 39, 3, 42, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig createFirstClassCallable = { { 1204 /* createFirstClassCallable */, 3, 43, 4, 47, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig renameParameters = { { 1246 /* renameParameters */, 2, 48, 2, 50, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; -inline constexpr sigtab::Sig getBitwiseAndType = { { 1263 /* getBitwiseAndType */, 3, 51, 3, 54, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseOrType = { { 1281 /* getBitwiseOrType */, 3, 55, 3, 58, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseXorType = { { 1298 /* getBitwiseXorType */, 3, 59, 3, 62, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getSpaceshipType = { { 1316 /* getSpaceshipType */, 3, 63, 3, 66, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getDivType = { { 1333 /* getDivType */, 3, 67, 3, 70, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getModType = { { 1344 /* getModType */, 3, 71, 3, 74, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getPlusType = { { 1355 /* getPlusType */, 3, 75, 3, 78, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getMinusType = { { 1367 /* getMinusType */, 3, 79, 3, 82, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getMulType = { { 1380 /* getMulType */, 3, 83, 3, 86, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getPowType = { { 1391 /* getPowType */, 3, 87, 3, 90, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getShiftLeftType = { { 1402 /* getShiftLeftType */, 3, 91, 3, 94, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getShiftRightType = { { 1419 /* getShiftRightType */, 3, 95, 3, 98, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig resolveIdenticalType = { { 1480 /* resolveIdenticalType */, 2, 99, 2, 101, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig resolveEqualType = { { 1501 /* resolveEqualType */, 2, 102, 3, 105, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNonNumericString = { { 1518 /* isNonNumericString */, 2, 106, 2, 108, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; -inline constexpr sigtab::Sig resolveConstantArrayTypeComparison = { { 1601 /* resolveConstantArrayTypeComparison */, 3, 109, 3, 112, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getClassConstFetchTypeByReflection = { { 1752 /* getClassConstFetchTypeByReflection */, 4, 113, 5, 118, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig transformStaticType = { { 1801 /* transformStaticType */, 2, 119, 2, 121, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getClassConstFetchType = { { 1821 /* getClassConstFetchType */, 4, 122, 4, 126, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnaryPlusType = { { 1844 /* getUnaryPlusType */, 2, 127, 2, 129, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnaryMinusType = { { 1861 /* getUnaryMinusType */, 2, 130, 2, 132, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseNotType = { { 1879 /* getBitwiseNotType */, 2, 133, 2, 135, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseNotTypeFromType = { { 1897 /* getBitwiseNotTypeFromType */, 1, 136, 1, 137, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig resolveName = { { 1948 /* resolveName */, 2, 138, 2, 140, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig resolveTypeByName = { { 1991 /* resolveTypeByName */, 2, 141, 2, 143, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig resolveTypeByNameWithLateStaticBinding = { { 2081 /* resolveTypeByNameWithLateStaticBinding */, 3, 144, 3, 147, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getReflectionProvider = { { 2158 /* getReflectionProvider */, 0, 148, 0, 148, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getNeverType = { { 2180 /* getNeverType */, 2, 149, 2, 151, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getFirstClassCallableType = { { 1069 /* getFirstClassCallableType */, 3, 39, 4, 43, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig createFirstClassCallable = { { 1221 /* createFirstClassCallable */, 3, 44, 5, 49, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig renameParameters = { { 1263 /* renameParameters */, 2, 50, 2, 52, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; +inline constexpr sigtab::Sig getBitwiseAndType = { { 1280 /* getBitwiseAndType */, 3, 53, 3, 56, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseOrType = { { 1298 /* getBitwiseOrType */, 3, 57, 3, 60, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseXorType = { { 1315 /* getBitwiseXorType */, 3, 61, 3, 64, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getSpaceshipType = { { 1333 /* getSpaceshipType */, 3, 65, 3, 68, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getDivType = { { 1350 /* getDivType */, 3, 69, 3, 72, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getModType = { { 1361 /* getModType */, 3, 73, 3, 76, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getPlusType = { { 1372 /* getPlusType */, 3, 77, 3, 80, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getMinusType = { { 1384 /* getMinusType */, 3, 81, 3, 84, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getMulType = { { 1397 /* getMulType */, 3, 85, 3, 88, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getPowType = { { 1408 /* getPowType */, 3, 89, 3, 92, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getShiftLeftType = { { 1419 /* getShiftLeftType */, 3, 93, 3, 96, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getShiftRightType = { { 1436 /* getShiftRightType */, 3, 97, 3, 100, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig resolveIdenticalType = { { 1497 /* resolveIdenticalType */, 2, 101, 2, 103, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig resolveEqualType = { { 1518 /* resolveEqualType */, 2, 104, 3, 107, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNonNumericString = { { 1535 /* isNonNumericString */, 2, 108, 2, 110, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; +inline constexpr sigtab::Sig resolveConstantArrayTypeComparison = { { 1618 /* resolveConstantArrayTypeComparison */, 3, 111, 3, 114, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getClassConstFetchTypeByReflection = { { 1769 /* getClassConstFetchTypeByReflection */, 4, 115, 5, 120, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig transformStaticType = { { 1818 /* transformStaticType */, 2, 121, 2, 123, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getClassConstFetchType = { { 1838 /* getClassConstFetchType */, 4, 124, 4, 128, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnaryPlusType = { { 1861 /* getUnaryPlusType */, 2, 129, 2, 131, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnaryMinusType = { { 1878 /* getUnaryMinusType */, 2, 132, 2, 134, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseNotType = { { 1896 /* getBitwiseNotType */, 2, 135, 2, 137, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseNotTypeFromType = { { 1914 /* getBitwiseNotTypeFromType */, 1, 138, 1, 139, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig resolveName = { { 1965 /* resolveName */, 2, 140, 2, 142, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig resolveTypeByName = { { 2008 /* resolveTypeByName */, 2, 143, 2, 145, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig resolveTypeByNameWithLateStaticBinding = { { 2098 /* resolveTypeByNameWithLateStaticBinding */, 3, 146, 3, 149, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getReflectionProvider = { { 2175 /* getReflectionProvider */, 0, 150, 0, 150, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getNeverType = { { 2197 /* getNeverType */, 2, 151, 2, 153, ZEND_ACC_PRIVATE } }; } // namespace sig } // namespace ptdecl::InitializerExprTypeResolver diff --git a/turbo-ext/src/support.h b/turbo-ext/src/support.h index a538ddf1adc..3c887159c17 100644 --- a/turbo-ext/src/support.h +++ b/turbo-ext/src/support.h @@ -4084,9 +4084,10 @@ enum pt_ietr_binary_operator : uint8_t * (a TypeResult) / ->getArrayType($expr, $getTypeCallback) / * ->getCastType($expr, $getTypeCallback) / ->getCastObjectType($exprType) / * ->getFunctionType($type, $isNullable, $isVariadic, $context) / - * ->getFirstClassCallableType($expr, $context, $nativeTypesPromoted) / + * ->getFirstClassCallableType($expr, $context, $nativeTypesPromoted, + * $boundArgTypes) / * ->createFirstClassCallable($function, $variants, $nativeTypesPromoted, - * $partialApplicationArgs) / + * $partialApplicationArgs, $boundArgTypes) / * ->getClassConstFetchTypeByReflection($class, $constantName, * $classReflection, $getTypeCallback) / ->getUnaryPlusType($expr, * $getTypeCallback) / ->getUnaryMinusType(...) / ->getBitwiseNotType(...): @@ -4105,8 +4106,8 @@ zv::Val pt_initializer_expr_type_resolver_get_array_type(zval *resolver, zval *e zv::Val pt_initializer_expr_type_resolver_get_cast_type(zval *resolver, zval *expr, const pt_ietr_get_type &getTypeCallback); zv::Val pt_initializer_expr_type_resolver_get_cast_object_type(zval *resolver, zval *exprType); zv::Val pt_initializer_expr_type_resolver_get_function_type(zval *resolver, zval *type, bool isNullable, bool isVariadic, zval *context); -zv::Val pt_initializer_expr_type_resolver_get_first_class_callable_type(zval *resolver, zval *expr, zval *context, bool nativeTypesPromoted); -zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs); +zv::Val pt_initializer_expr_type_resolver_get_first_class_callable_type(zval *resolver, zval *expr, zval *context, bool nativeTypesPromoted, zval *boundArgTypes); +zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes); zv::Val pt_initializer_expr_type_resolver_get_class_const_fetch_type_by_reflection(zval *resolver, zval *class_, zval *constantName, zval *classReflection, const pt_ietr_get_type &getTypeCallback, bool nativeTypesPromoted = false); zv::Val pt_initializer_expr_type_resolver_get_unary_plus_type(zval *resolver, zval *expr, const pt_ietr_get_type &getTypeCallback); zv::Val pt_initializer_expr_type_resolver_get_unary_minus_type(zval *resolver, zval *expr, const pt_ietr_get_type &getTypeCallback); From 1194ccdcbc34c1e40c15e687744adce519d216de Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Tue, 10 Nov 2026 18:41:18 +0000 Subject: [PATCH 05/20] Test partial function applications passed as callbacks Incompatible partial applications passed to array_map(), array_filter(), usort() and a userland generic callable parameter are reported, the compatible ones, generic ones included, are not, and the templates they carry flow into the result of userland generic callables. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- build/collision-detector.json | 3 +- ...partial-function-application-signature.php | 16 ++++ .../CallToFunctionParametersRuleTest.php | 32 ++++++++ ...partial-function-application-callbacks.php | 79 +++++++++++++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Rules/Functions/data/partial-function-application-callbacks.php diff --git a/build/collision-detector.json b/build/collision-detector.json index d92f317fc2a..2f92b9e909c 100644 --- a/build/collision-detector.json +++ b/build/collision-detector.json @@ -33,6 +33,7 @@ "../tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php", "../tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php", "../tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php", - "../tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php" + "../tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php", + "../tests/PHPStan/Rules/Functions/data/partial-function-application-callbacks.php" ] } diff --git a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php index eaac3b3eb3a..7a3aa178c46 100644 --- a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php +++ b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php @@ -59,6 +59,18 @@ function repeat($value, int $times): array return []; } +/** + * @template T + * @template U + * @param list $items + * @param callable(T): U $fn + * @return list + */ +function mapList(array $items, callable $fn): array +{ + return []; +} + class Foo { @@ -158,6 +170,10 @@ function templatesThroughCallbacks(array $ints): void { assertType('list>', array_map(pair(?, 'x'), $ints)); assertType('list>', array_map(repeat(?, 2), $ints)); + assertType('list>', mapList($ints, pair(?, 'x'))); + assertType('list>', mapList($ints, repeat(?, 2))); + assertType('list', mapList($ints, identity(...))); + assertType('list', mapList($ints, identity(?))); } function methods(Foo $foo): void diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 9940ef555b5..3fc642a997c 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -3539,4 +3539,36 @@ public function testBug15700(): void ]); } + #[RequiresPhp('>= 8.6.0-dev')] + public function testPartialFunctionApplicationCallbacks(): void + { + $this->analyse([__DIR__ . '/data/partial-function-application-callbacks.php'], [ + [ + 'Parameter #1 $callback of function array_map expects (callable(string): mixed)|null, Closure(int): string given.', + 73, + ], + [ + 'Parameter #1 $callback of function array_map expects (callable(int): mixed)|null, Closure(int, string): string given.', + 74, + 'Type #1 from the union: Parameter #2 $prefix of passed callable is required but accepting callable does not have that parameter. It will be called without it.', + ], + [ + 'Parameter #2 $callback of function array_filter expects (callable(int): bool)|null, Closure(string): bool given.', + 75, + ], + [ + 'Parameter #2 $callback of function usort expects callable(string, string): int, Closure(int, int): int given.', + 76, + ], + [ + 'Parameter #2 $callback of function usort expects callable(int, int): int, Closure(int, bool): int given.', + 77, + ], + [ + 'Parameter #2 $fn of function PartialFunctionApplicationCallbacks\\mapList expects callable(string): string, Closure(int): string given.', + 78, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/partial-function-application-callbacks.php b/tests/PHPStan/Rules/Functions/data/partial-function-application-callbacks.php new file mode 100644 index 00000000000..8cfd6b591f1 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/partial-function-application-callbacks.php @@ -0,0 +1,79 @@ += 8.6 + +declare(strict_types = 1); + +namespace PartialFunctionApplicationCallbacks; + +function intToString(int $i, string $prefix): string +{ + return $prefix . $i; +} + +function compareInts(int $a, int $b, bool $reverse): int +{ + return $reverse ? $b <=> $a : $a <=> $b; +} + +/** + * @template T + * @template U + * @param list $items + * @param callable(T): U $fn + * @return list + */ +function mapList(array $items, callable $fn): array +{ + return []; +} + +/** + * @template T + * @param T $value + * @return list + */ +function repeat($value, int $times): array +{ + return []; +} + +/** + * @template T + * @param T $value + * @param T $other + * @return list + */ +function pair($value, $other): array +{ + return [$value, $other]; +} + +/** + * @param list $ints + * @param list $strings + */ +function compatible(array $ints, array $strings): void +{ + array_map(intToString(?, 'n'), $ints); + array_map(intToString(prefix: 'n', i: ?), $ints); + array_filter($strings, str_contains(?, 'x')); + usort($ints, compareInts(?, ?, true)); + mapList($ints, intToString(?, 'n')); + mapList($ints, repeat(?, 2)); + mapList($strings, pair(?, 'x')); + mapList($ints, pair(?, 'x')); + array_map(repeat(...), $ints, $ints); +} + +/** + * @param list $ints + * @param list $strings + */ +function incompatible(array $ints, array $strings): void +{ + array_map(intToString(?, 'n'), $strings); + array_map(intToString(?, ?), $ints); + array_filter($ints, str_contains(?, 'x')); + usort($strings, compareInts(?, ?, true)); + usort($ints, compareInts(?, true, ...)); + mapList($strings, intToString(?, 'n')); +} From 0e1ee9c49d76cdfecafa0383c66a3b5f350a19a8 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Tue, 10 Nov 2026 20:45:58 +0000 Subject: [PATCH 06/20] Replay calls of closures created from callables on their callee A first-class callable or a partial function application now remembers its callee (ClosureOrigin): the function, or the method and the type it is called on, and the arguments a partial application bound. Calling such a closure replays the call as the callee's call, so the callee's dynamic return type extensions, type-specifying extensions, by-ref effects and parameter out types apply as if it had been called directly. A union of such closures replays each callee: the call returns what any of them returns, narrows only what all of them narrow and has the effects of any of them. A member without an origin keeps the call on the closure signature. Closures with different origins are not equal and are not subtypes of each other, so a union keeps each origin. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- build/collision-detector.json | 3 +- src/Analyser/ExprHandler/FuncCallHandler.php | 14 +- .../Helper/ClosureOriginCallReplay.php | 126 +++ .../Virtual/MethodCallableNodeHandler.php | 2 + .../InitializerExprTypeResolver.php | 10 + src/Type/ClosureOrigin.php | 307 ++++++ src/Type/ClosureType.php | 38 +- .../nsrt/first-class-callable-replay.php | 86 ++ .../partial-function-application-replay.php | 69 ++ .../Analyser/nsrt/static-late-binding.php | 2 +- turbo-ext/src/ClosureType.cpp | 95 +- turbo-ext/src/FuncCallHandler.cpp | 23 +- turbo-ext/src/FunctionCallableNodeHandler.cpp | 2 +- turbo-ext/src/InitializerExprTypeResolver.cpp | 47 +- turbo-ext/src/MethodCallableNodeHandler.cpp | 4 +- turbo-ext/src/VirtualExprHandlers.h | 6 +- turbo-ext/src/generated/ClosureType.h | 881 +++++++++--------- .../generated/InitializerExprTypeResolver.h | 225 ++--- turbo-ext/src/support.cpp | 2 + turbo-ext/src/support.h | 13 +- turbo-ext/tests/type-family.php | 7 + 21 files changed, 1364 insertions(+), 598 deletions(-) create mode 100644 src/Analyser/ExprHandler/Helper/ClosureOriginCallReplay.php create mode 100644 src/Type/ClosureOrigin.php create mode 100644 tests/PHPStan/Analyser/nsrt/first-class-callable-replay.php create mode 100644 tests/PHPStan/Analyser/nsrt/partial-function-application-replay.php diff --git a/build/collision-detector.json b/build/collision-detector.json index 2f92b9e909c..00effcc7aaa 100644 --- a/build/collision-detector.json +++ b/build/collision-detector.json @@ -34,6 +34,7 @@ "../tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php", "../tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php", "../tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php", - "../tests/PHPStan/Rules/Functions/data/partial-function-application-callbacks.php" + "../tests/PHPStan/Rules/Functions/data/partial-function-application-callbacks.php", + "../tests/PHPStan/Analyser/nsrt/partial-function-application-replay.php" ] } diff --git a/src/Analyser/ExprHandler/FuncCallHandler.php b/src/Analyser/ExprHandler/FuncCallHandler.php index 008e549a016..dcf333e6a4c 100644 --- a/src/Analyser/ExprHandler/FuncCallHandler.php +++ b/src/Analyser/ExprHandler/FuncCallHandler.php @@ -22,6 +22,7 @@ use PHPStan\Analyser\ExpressionResultFactory; use PHPStan\Analyser\ExpressionResultStorage; use PHPStan\Analyser\ExprHandler; +use PHPStan\Analyser\ExprHandler\Helper\ClosureOriginCallReplay; use PHPStan\Analyser\ExprHandler\Helper\ClosureTypeResolver; use PHPStan\Analyser\ExprHandler\Helper\DefaultNarrowingHelper; use PHPStan\Analyser\ExprHandler\Helper\DynamicReturnTypeStoragePrimer; @@ -600,7 +601,12 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex $argsResult->getDependencies(), $this->getDependencies($beforeScope, $functionReflection, $nameResult, $preliminaryResult), ); - return $preliminaryResult->finalize($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints, $variableFlow, $dependencies); + $result = $preliminaryResult->finalize($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints, $variableFlow, $dependencies); + if ($nameType === null) { + return $result; + } + + return ClosureOriginCallReplay::replay($nodeScopeResolver, $this->expressionResultFactory, $expr, $nameType, $scopeBeforeArgs, $storage, $result); } /** @@ -863,12 +869,6 @@ private function resolveReturnType(NodeScopeResolver $nodeScopeResolver, Mutatin /** @var non-empty-string $name */ $name = $expr->name->value; $functionName = new Name($name); - } elseif ( - $expr->name instanceof FuncCall - && $expr->name->name instanceof Name - && $expr->name->isFirstClassCallable() - ) { - $functionName = $expr->name->name; } $normalizedNode = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $expr); diff --git a/src/Analyser/ExprHandler/Helper/ClosureOriginCallReplay.php b/src/Analyser/ExprHandler/Helper/ClosureOriginCallReplay.php new file mode 100644 index 00000000000..f885735ab9f --- /dev/null +++ b/src/Analyser/ExprHandler/Helper/ClosureOriginCallReplay.php @@ -0,0 +1,126 @@ +getTypes() : [$calleeType]; + /** @var list $origins */ + $origins = []; + $calls = []; + foreach ($members as $member) { + if (!$member instanceof ClosureType) { + return $result; + } + $origin = $member->getOrigin(); + if ($origin === null) { + return $result; + } + foreach ($origins as $seen) { + if ($seen->equals($origin)) { + continue 2; + } + } + $call = $origin->createCall($expr, $member); + if ($call === null) { + return $result; + } + $origins[] = $origin; + $calls[] = $call; + } + if ($calls === []) { + return $result; + } + + // the arguments are already processed: the replayed calls read their + // stored results, walking from the same position + $replayed = []; + foreach ($calls as $call) { + $replayed[] = $nodeScopeResolver->processExprOnDemand($call, $scopeBeforeArgs, $storage->duplicate()); + } + + $scope = $replayed[0]->getScope(); + $isAlwaysTerminating = $replayed[0]->isAlwaysTerminating(); + foreach (array_slice($replayed, 1) as $replayedResult) { + $scope = $scope->mergeWith($replayedResult->getScope()); + $isAlwaysTerminating = $isAlwaysTerminating && $replayedResult->isAlwaysTerminating(); + } + + // positional: simple-downgrader resolves named arguments only on $this->property->method() calls + return $expressionResultFactory->create( + $scope, + $result->getBeforeScope(), + $expr, + $result->hasYield(), + $result->isAlwaysTerminating() || $isAlwaysTerminating, + $result->getThrowPoints(), + $result->getImpurePoints(), + static fn (bool $nativeTypesPromoted): Type => TypeCombinator::union(...array_map( + static fn (ExpressionResult $replayedResult): Type => $replayedResult->getKeepVoidType($nativeTypesPromoted), + $replayed, + )), + static function (TypeSpecifierContext $context, bool $nativeTypesPromoted) use ($replayed): SpecifiedTypes { + $specifiedTypes = $replayed[0]->getSpecifiedTypes($context, $nativeTypesPromoted); + foreach (array_slice($replayed, 1) as $replayedResult) { + $specifiedTypes = $specifiedTypes->intersectWith($replayedResult->getSpecifiedTypes($context, $nativeTypesPromoted)); + } + + return $specifiedTypes; + }, + false, + null, + null, + null, + static fn (Type $type, TypeSpecifierContext $context, bool $nativeTypesPromoted): SpecifiedTypes => $result->getCreatedTypes($type, $context, $nativeTypesPromoted) ?? new SpecifiedTypes(), + null, + null, + $result->getArgsResult(), + $result->getVariableFlow(), + $result->getDependencies(), + ); + } + +} diff --git a/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php b/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php index 8e561f436f4..a6d9a5f3faa 100644 --- a/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php +++ b/src/Analyser/ExprHandler/Virtual/MethodCallableNodeHandler.php @@ -25,6 +25,7 @@ use PHPStan\Reflection\InitializerExprTypeResolver; use PHPStan\Reflection\PartialFunctionApplicationParameters; use PHPStan\Turbo\ShadowedByTurboExtension; +use PHPStan\Type\ClosureOrigin; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use function array_merge; @@ -161,6 +162,7 @@ private function resolveType(MutatingScope $scope, MethodCallableNode $expr, Exp $scope->nativeTypesPromoted, $originalNode->isFirstClassCallable() ? null : $originalNode->getRawArgs(), $originalNode->isFirstClassCallable() ? [] : PartialFunctionApplicationParameters::getBoundArgTypes($scope, $originalNode), + ClosureOrigin::forMethod($varType, $originalNode->name->toString(), false), ); } diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index 8c5b14c00af..da55dd5b329 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -54,6 +54,7 @@ use PHPStan\Type\BooleanType; use PHPStan\Type\CallableAssertionsHelper; use PHPStan\Type\ClassStringType; +use PHPStan\Type\ClosureOrigin; use PHPStan\Type\ClosureType; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantArrayTypeBuilder; @@ -820,6 +821,7 @@ public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprCo $nativeTypesPromoted, $partialApplicationArgs, $boundArgTypes ?? [], + ClosureOrigin::forFunction($function->getName()), ); } @@ -860,6 +862,7 @@ public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprCo $nativeTypesPromoted, $partialApplicationArgs, $boundArgTypes ?? [], + ClosureOrigin::forMethod($classType, $methodName, true), ); } @@ -874,6 +877,7 @@ public function getFirstClassCallableType(Expr\CallLike $expr, InitializerExprCo * @param ParametersAcceptor[] $variants * @param array|null $partialApplicationArgs the arguments of a partial function application, null for a first-class callable * @param array $boundArgTypes the types of the bound arguments of a partial function application, keyed like $partialApplicationArgs + * @param ClosureOrigin|null $origin the callee, whose call a call of the closure replays */ public function createFirstClassCallable( FunctionReflection|ExtendedMethodReflection|null $function, @@ -881,8 +885,13 @@ public function createFirstClassCallable( bool $nativeTypesPromoted, ?array $partialApplicationArgs = null, array $boundArgTypes = [], + ?ClosureOrigin $origin = null, ): Type { + if ($origin !== null && $partialApplicationArgs !== null) { + $origin = $origin->withPartialApplication($partialApplicationArgs, $boundArgTypes); + } + // variants of multi-variant built-ins carry functionMap parameter names, // but the closure accepts the native names as named arguments $namedArgumentNames = []; @@ -994,6 +1003,7 @@ public function createFirstClassCallable( mustUseReturnValue: $mustUseReturnValue, assertions: $assertions, isStatic: $isStaticClosure, + origin: $origin, ); } diff --git a/src/Type/ClosureOrigin.php b/src/Type/ClosureOrigin.php new file mode 100644 index 00000000000..eaa04c4ab10 --- /dev/null +++ b/src/Type/ClosureOrigin.php @@ -0,0 +1,307 @@ +|null $partialApplicationArgs the name and the bound type (null for `?`) of each + * argument of a partial function application before `...`, + * null for a first-class callable + */ + private function __construct( + private ?string $functionName, + private ?Type $calledOnType, + private ?string $methodName, + private bool $isStaticCall, + private ?array $partialApplicationArgs, + private bool $hasVariadicPlaceholder, + ) + { + } + + public static function forFunction(string $functionName): self + { + return new self($functionName, null, null, false, null, true); + } + + public static function forMethod(Type $calledOnType, string $methodName, bool $isStaticCall): self + { + return new self(null, $calledOnType, $methodName, $isStaticCall, null, true); + } + + /** + * @param array $args + * @param array $boundArgTypes keyed like $args + */ + public function withPartialApplication(array $args, array $boundArgTypes): self + { + $partialApplicationArgs = []; + $hasVariadicPlaceholder = false; + foreach ($args as $i => $arg) { + if ($arg instanceof VariadicPlaceholder) { + $hasVariadicPlaceholder = true; + continue; + } + $partialApplicationArgs[] = [ + $arg->name?->toString(), + $arg instanceof Arg ? $boundArgTypes[$i] ?? new MixedType() : null, + ]; + } + + return new self($this->functionName, $this->calledOnType, $this->methodName, $this->isStaticCall, $partialApplicationArgs, $hasVariadicPlaceholder); + } + + public function equals(self $other): bool + { + if ( + $this->functionName !== $other->functionName + || $this->methodName !== $other->methodName + || $this->isStaticCall !== $other->isStaticCall + || $this->hasVariadicPlaceholder !== $other->hasVariadicPlaceholder + ) { + return false; + } + if ($this->calledOnType !== null && ($other->calledOnType === null || !$this->calledOnType->equals($other->calledOnType))) { + return false; + } + if ($this->partialApplicationArgs === null || $other->partialApplicationArgs === null) { + return $this->partialApplicationArgs === $other->partialApplicationArgs; + } + if (count($this->partialApplicationArgs) !== count($other->partialApplicationArgs)) { + return false; + } + foreach ($this->partialApplicationArgs as $i => [$name, $type]) { + [$otherName, $otherType] = $other->partialApplicationArgs[$i]; + if ($name !== $otherName) { + return false; + } + if ($type === null || $otherType === null) { + if ($type !== $otherType) { + return false; + } + continue; + } + if (!$type->equals($otherType)) { + return false; + } + } + + return true; + } + + public function describe(): string + { + if ($this->functionName !== null) { + $callee = $this->functionName; + } elseif ($this->calledOnType !== null) { + $callee = sprintf('%s%s%s', $this->calledOnType->describe(VerbosityLevel::cache()), $this->isStaticCall ? '::' : '->', $this->methodName); + } else { + $callee = ''; + } + if ($this->partialApplicationArgs === null) { + return $callee . '(...)'; + } + + $args = []; + foreach ($this->partialApplicationArgs as [$name, $type]) { + $args[] = ($name !== null ? $name . ': ' : '') . ($type !== null ? $type->describe(VerbosityLevel::cache()) : '?'); + } + if ($this->hasVariadicPlaceholder) { + $args[] = '...'; + } + + return sprintf('%s(%s)', $callee, implode(', ', $args)); + } + + /** + * @param callable(Type): Type $cb + */ + public function traverse(callable $cb): self + { + $changed = false; + $calledOnType = $this->calledOnType; + if ($calledOnType !== null) { + $calledOnType = $cb($calledOnType); + $changed = $calledOnType !== $this->calledOnType; + } + $partialApplicationArgs = $this->partialApplicationArgs; + if ($partialApplicationArgs !== null) { + foreach ($partialApplicationArgs as $i => [$name, $type]) { + if ($type === null) { + continue; + } + $newType = $cb($type); + if ($newType === $type) { + continue; + } + $partialApplicationArgs[$i] = [$name, $newType]; + $changed = true; + } + } + if (!$changed) { + return $this; + } + + return new self($this->functionName, $calledOnType, $this->methodName, $this->isStaticCall, $partialApplicationArgs, $this->hasVariadicPlaceholder); + } + + /** + * The call of the callee that calling the closure as $call makes, null when its + * arguments do not map onto the callee - the call is then analysed on the closure's + * signature alone. + */ + public function createCall(FuncCall $call, ClosureType $closure): ?CallLike + { + $args = $this->createArgs($call, $closure); + if ($args === null) { + return null; + } + + $attributes = $call->getAttributes(); + unset($attributes[ExprPrinter::ATTRIBUTE_CACHE_KEY]); + if ($this->functionName !== null && $this->functionName !== '') { + return new FuncCall(new FullyQualified($this->functionName), $args, $attributes); + } + if ($this->calledOnType === null || $this->methodName === null || $this->methodName === '') { + return null; + } + if ($this->isStaticCall) { + return new StaticCall(new TypeExpr($this->calledOnType), new Identifier($this->methodName), $args, $attributes); + } + + return new MethodCall(new TypeExpr($this->calledOnType), new Identifier($this->methodName), $args, $attributes); + } + + /** + * @return list|null + */ + private function createArgs(FuncCall $call, ClosureType $closure): ?array + { + $callArgs = $call->getArgs(); + if ($this->partialApplicationArgs === null) { + return $callArgs; + } + + // the closure's parameters are the positional placeholders, the named + // placeholders and, with `...`, the callee's unbound parameters and its variadic + $parameters = $closure->getParameters(); + $declaredCount = count($parameters); + if ($closure->isVariadic() && $declaredCount > 0 && $parameters[$declaredCount - 1]->isVariadic()) { + $declaredCount--; + } + $indexesByName = []; + foreach (array_slice($parameters, 0, $declaredCount) as $i => $parameter) { + $indexesByName[$parameter->getName()] = $i; + } + + $argsByParameter = []; + $extraPositional = []; + $extraNamed = []; + $position = 0; + foreach ($callArgs as $arg) { + if ($arg->unpack) { + return null; + } + if ($arg->name === null) { + if ($position < $declaredCount) { + $argsByParameter[$position++] = $arg; + continue; + } + $extraPositional[] = $arg; + continue; + } + $index = $indexesByName[$arg->name->toString()] ?? null; + if ($index === null) { + $extraNamed[] = $arg; + continue; + } + $argsByParameter[$index] = $arg; + } + if (!$closure->isVariadic() && ($extraPositional !== [] || $extraNamed !== [])) { + return null; + } + + $calleeArgs = []; + $parameterIndex = 0; + // past a named argument, the remaining parameters go by name too + $named = $this->hasNamedArgs(); + foreach ([false, true] as $namedPass) { + foreach ($this->partialApplicationArgs as [$name, $type]) { + if (($name !== null) !== $namedPass) { + continue; + } + $nameIdentifier = $name !== null ? new Identifier($name) : null; + if ($type !== null) { + $calleeArgs[] = new Arg(new TypeExpr($type), name: $nameIdentifier); + continue; + } + $arg = $argsByParameter[$parameterIndex++] ?? null; + if ($arg === null) { + return null; + } + $calleeArgs[] = new Arg($arg->value, attributes: $arg->getAttributes(), name: $nameIdentifier); + } + } + + if ($this->hasVariadicPlaceholder) { + for (; $parameterIndex < $declaredCount; $parameterIndex++) { + $arg = $argsByParameter[$parameterIndex] ?? null; + if ($arg === null) { + // an optional parameter left out: the ones after it go by name + $named = true; + continue; + } + $parameterName = $parameters[$parameterIndex]->getName(); + if ($named && $parameterName === '') { + return null; + } + $calleeArgs[] = new Arg($arg->value, attributes: $arg->getAttributes(), name: $named ? new Identifier($parameterName) : null); + } + } + if ($extraPositional !== [] && $named) { + return null; + } + + return [...$calleeArgs, ...$extraPositional, ...$extraNamed]; + } + + private function hasNamedArgs(): bool + { + foreach ($this->partialApplicationArgs ?? [] as [$name]) { + if ($name !== null) { + return true; + } + } + + return false; + } + +} diff --git a/src/Type/ClosureType.php b/src/Type/ClosureType.php index 4d29a0c6724..70e8f5f203d 100644 --- a/src/Type/ClosureType.php +++ b/src/Type/ClosureType.php @@ -111,6 +111,7 @@ class ClosureType implements TypeWithClassName, CallableParametersAcceptor * @param InvalidateExprNode[] $invalidateExpressions * @param string[] $usedVariables * @param array $byRefUseTypes per by-ref use of a closure whose effects apply where it is invoked, the marker of its site (see ClosureSignatureInference) + * @param ClosureOrigin|null $origin the callee of a first-class callable or a partial function application, whose call a call of the closure replays */ public function __construct( ?array $parameters = null, @@ -129,6 +130,7 @@ public function __construct( ?Assertions $assertions = null, ?TrinaryLogic $isStatic = null, private array $byRefUseTypes = [], + private ?ClosureOrigin $origin = null, ) { if ($acceptsNamedArguments === null) { @@ -267,12 +269,19 @@ private function isSuperTypeOfInternal(Type $type, bool $treatMixedAsAny, bool $ if (!$variant instanceof CallableParametersAcceptor) { return IsSuperTypeOfResult::createNo([]); } - return CallableTypeHelper::isParametersAcceptorSuperTypeOf( + $result = CallableTypeHelper::isParametersAcceptorSuperTypeOf( $this, $variant, $treatMixedAsAny, $strictTypes, ); + if (!$treatMixedAsAny && $this->origin !== null && !self::hasEqualOrigins($this, $type)) { + // a closure created from another callee, or from an unknown one, + // is not known to be created from this one + return $result->and(IsSuperTypeOfResult::createMaybe()); + } + + return $result; } if ($type->getObjectClassNames() === [Closure::class]) { @@ -291,7 +300,17 @@ public function equals(Type $type): bool return $this->describe(VerbosityLevel::precise()) === $type->describe(VerbosityLevel::precise()) && $this->isPure()->equals($type->isPure()) && $this->isStatic->equals($type->isStatic) - && $this->hasEqualUnresolvedSignature($type); + && $this->hasEqualUnresolvedSignature($type) + && self::hasEqualOrigins($this, $type); + } + + private static function hasEqualOrigins(self $a, self $b): bool + { + if ($a->origin === null || $b->origin === null) { + return $a->origin === $b->origin; + } + + return $a->origin->equals($b->origin); } /** @@ -351,6 +370,14 @@ function (): string { return $prefix . $this->describeCallable(); }, + function (): string { + $description = $this->describe(VerbosityLevel::precise()); + if ($this->origin === null) { + return $description; + } + + return $description . ' from ' . $this->origin->describe(); + }, ); } @@ -571,6 +598,11 @@ public function getByRefUseTypes(): array return $this->byRefUseTypes; } + public function getOrigin(): ?ClosureOrigin + { + return $this->origin; + } + /** * Whether an UnresolvedTemplateArgumentType occurs anywhere in the * closure's signature - it is still being inferred (see @@ -836,6 +868,7 @@ public function traverse(callable $cb): Type $this->assertions->mapTypes($cb), $this->isStatic, $this->byRefUseTypes, + $this->origin?->traverse($cb), ); } @@ -890,6 +923,7 @@ public function traverseSimultaneously(Type $right, callable $cb): Type $this->assertions, $this->isStatic, $this->byRefUseTypes, + $this->origin, ); } diff --git a/tests/PHPStan/Analyser/nsrt/first-class-callable-replay.php b/tests/PHPStan/Analyser/nsrt/first-class-callable-replay.php new file mode 100644 index 00000000000..18a28061987 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/first-class-callable-replay.php @@ -0,0 +1,86 @@ += 8.1 + +declare(strict_types = 1); + +namespace FirstClassCallableReplay; + +use function PHPStan\Testing\assertType; + +class Foo +{ + + /** + * @param-out int $out + */ + public static function out(mixed &$out): void + { + $out = 1; + } + +} + +/** + * @param array $arr + */ +function problems(\DateTimeImmutable $d, array $arr, string $s, mixed $x): void +{ + $r = str_replace(...); + assertType('lowercase-string&non-falsy-string', $r(' ', '-', 'a b')); + assertType('lowercase-string&non-falsy-string', $r(subject: 'a b', search: ' ', replace: '-')); + assertType('3', strlen(...)('abc')); + + $a = [3, 1, 2]; + $sort = sort(...); + $sort($a); + assertType('non-empty-list<1|2|3>', $a); + + $pm = preg_match(...); + $pm('/(a)(b)?/', 'ab', $mm); + assertType("array{}|array{0: non-falsy-string, 1: 'a', 2?: 'b'}", $mm); + + $ake = array_key_exists(...); + if ($ake('a', $arr)) { + assertType("non-empty-array&hasOffset('a')", $arr); + } + + $isInt = is_int(...); + if ($isInt($x)) { + assertType('int', $x); + } + + $out = Foo::out(...); + $o = null; + $out($o); + assertType('int', $o); + + $m = $d->modify(...); + assertType('DateTimeImmutable', $m('+1 day')); +} + +function unions(bool $b, string $s): void +{ + $f = $b ? strtoupper(...) : strtoupper(...); + assertType("'A'", $f('a')); + + $g = $b ? strtoupper(...) : strtolower(...); + assertType("'A'|'a'", $g('a')); + + $plain = static fn (string $string): string => $string; + $h1 = $b ? strtoupper(...) : $plain; + $h2 = $b ? $plain : strtoupper(...); + assertType("'a'|uppercase-string", $h1('a')); + assertType("'a'|uppercase-string", $h2('a')); + + if ($b) { + $i = strtoupper(...); + } else { + $i = strtolower(...); + } + assertType("'A'|'a'", $i('a')); + + $n = $b ? is_int(...) : is_numeric(...); + $x = $s; + if ($n($x)) { + assertType('numeric-string', $x); + } +} diff --git a/tests/PHPStan/Analyser/nsrt/partial-function-application-replay.php b/tests/PHPStan/Analyser/nsrt/partial-function-application-replay.php new file mode 100644 index 00000000000..7bf8f3893b3 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/partial-function-application-replay.php @@ -0,0 +1,69 @@ += 8.6 + +declare(strict_types = 1); + +namespace PartialFunctionApplicationReplay; + +use function PHPStan\Testing\assertType; + +/** + * @template T + * @param T $a + * @param T $b + * @return T + */ +function pick(mixed $a, mixed $b): mixed +{ + return $a; +} + +/** + * @param array $arr + */ +function bound(\DateTimeImmutable $d, array $arr, string $s): void +{ + $rp = str_replace(' ', '-', ?); + assertType('lowercase-string&non-falsy-string', $rp('a b')); + assertType('lowercase-string&non-falsy-string', $rp(subject: 'a b')); + + $rn = str_replace(search: ' ', replace: '-', ...); + assertType('lowercase-string&non-falsy-string', $rn('a b')); + + $fmt = sprintf('%s-%s', ?, ...); + assertType("'a-b'", $fmt('a', 'b')); + + $pm = preg_match('/(a)(b)?/', ?, ...); + $pm('ab', $mm); + assertType("array{}|array{0: non-falsy-string, 1: 'a', 2?: 'b'}", $mm); + + $has = array_key_exists('a', ?); + if ($has($arr)) { + assertType("non-empty-array&hasOffset('a')", $arr); + } + + $in = in_array(?, ['a', 'b'], true); + if ($in($s)) { + assertType("'a'|'b'", $s); + } + + $p = pick(1, ?); + assertType("1|'x'", $p('x')); + + $mod = $d->modify(?); + assertType('DateTimeImmutable', $mod('+1 day')); +} + +/** + * @param list<1|2> $ints + */ +function unions(bool $b, array $ints): void +{ + $p = $b ? str_replace(' ', '-', ?) : str_replace(' ', '_', ?); + assertType('lowercase-string&non-falsy-string', $p('a b')); + + $q = str_repeat('a', ?); + foreach ($ints as $i) { + $q = str_repeat((string) $i, ?); + } + assertType("'11'|'22'|'aa'", $q(2)); +} diff --git a/tests/PHPStan/Analyser/nsrt/static-late-binding.php b/tests/PHPStan/Analyser/nsrt/static-late-binding.php index ea3c3a44bdc..ebe06ad9c60 100644 --- a/tests/PHPStan/Analyser/nsrt/static-late-binding.php +++ b/tests/PHPStan/Analyser/nsrt/static-late-binding.php @@ -90,7 +90,7 @@ public function foo(): void assertType('StaticLateBinding\B', B::retStatic(...)()); assertType('static(StaticLateBinding\B)', self::retStatic(...)()); assertType('static(StaticLateBinding\B)', static::retStatic(...)()); - assertType('static(StaticLateBinding\A)', parent::retStatic(...)()); // could be static(StaticLateBinding\B) + assertType('static(StaticLateBinding\B)', parent::retStatic(...)()); assertType('static(StaticLateBinding\B)', $this->retStatic(...)()); assertType('bool', X::retStatic(...)()); assertType('mixed', $clUnioned::retStatic(...)()); // should be bool|StaticLateBinding\A https://github.com/phpstan/phpstan/issues/11687 diff --git a/turbo-ext/src/ClosureType.cpp b/turbo-ext/src/ClosureType.cpp index b0a2d83154d..2744a9474fe 100644 --- a/turbo-ext/src/ClosureType.cpp +++ b/turbo-ext/src/ClosureType.cpp @@ -29,6 +29,7 @@ #include "TypeTraits.h" #include "AnalyserValues.h" #include "generated/ClosureType.h" +#include "Engine.h" namespace slots = ptdecl::ClosureType::slot; namespace sigs = ptdecl::ClosureType::sig; @@ -89,6 +90,7 @@ struct ClosureTypeArguments zval *assertions; zval *isStatic; zval *byRefUseTypes; + zval *origin; }; /* Mirrors PHPStan\Type\ClosureType. State lives in the PHP object's slots. */ @@ -118,6 +120,9 @@ class ClosureType writeSlot(slots::invalidateExpressions, a.invalidateExpressions != NULL ? a.invalidateExpressions : &emptyArray); writeSlot(slots::usedVariables, a.usedVariables != NULL ? a.usedVariables : &emptyArray); writeSlot(slots::byRefUseTypes, a.byRefUseTypes != NULL ? a.byRefUseTypes : &emptyArray); + zval null = {}; + ZVAL_NULL(&null); + writeSlot(slots::origin, a.origin != NULL ? a.origin : &null); writeSlot(slots::acceptsNamedArguments, a.acceptsNamedArguments != NULL ? a.acceptsNamedArguments : pt_trinary_singleton(PT_TRI_YES)); writeSlot(slots::mustUseReturnValue, a.mustUseReturnValue != NULL ? a.mustUseReturnValue : pt_trinary_singleton(PT_TRI_MAYBE)); @@ -206,6 +211,7 @@ class ClosureType zval *invalidateExpressions() const { return slot(self, slots::invalidateExpressions, "invalidateExpressions"); } zval *usedVariables() const { return slot(self, slots::usedVariables, "usedVariables"); } zval *byRefUseTypes() const { return slot(self, slots::byRefUseTypes, "byRefUseTypes"); } + zval *origin() const { return slot(self, slots::origin, "origin"); } static zval *slot(zend_object *object, uint32_t index, const char *name) { return pt_typed_slot(object, index, pt_ce_closure_type, name); } @@ -346,7 +352,19 @@ class ClosureType if (!isCallableAcceptor) return pt_type_is_super_type_of_result(PT_TRI_NO); zval selfZv; ZVAL_OBJ(&selfZv, self); - return pt_callable_type_helper_is_parameters_acceptor_super_type_of(&selfZv, variant.raw(), treatMixedAsAny, strictTypes); + zv::Val result = pt_callable_type_helper_is_parameters_acceptor_super_type_of(&selfZv, variant.raw(), treatMixedAsAny, strictTypes); + if (UNEXPECTED(result.isUndef()) || treatMixedAsAny) return result; + zval *ownOrigin = origin(); + if (UNEXPECTED(ownOrigin == NULL)) return zv::Val(); + if (Z_TYPE_P(ownOrigin) != IS_OBJECT) return result; + bool equalOrigins; + if (UNEXPECTED(!hasEqualOrigins(Z_OBJ_P(type), equalOrigins))) return zv::Val(); + if (equalOrigins) return result; + /* a closure created from another callee, or from an unknown one, + * is not known to be created from this one */ + zv::Val maybe = pt_type_is_super_type_of_result(PT_TRI_MAYBE); + if (UNEXPECTED(maybe.isUndef())) return zv::Val(); + return pt_type_call(Z_OBJ_P(result.raw()), PT_LC("and"), 1, maybe.raw()); } /* $type->getObjectClassNames() === [Closure::class] */ zv::Val classNames = pt_type_op(Z_OBJ_P(type), PT_OP_GET_OBJECT_CLASS_NAMES, 0, NULL); @@ -394,7 +412,26 @@ class ClosureType out = false; return true; } - return hasEqualUnresolvedSignature(Z_OBJ_P(type), out); + if (UNEXPECTED(!hasEqualUnresolvedSignature(Z_OBJ_P(type), out))) return false; + if (!out) return true; + return hasEqualOrigins(Z_OBJ_P(type), out); + } + + /* Mirrors the private static hasEqualOrigins(): both without an origin, + * or with equal ones; false with an exception pending */ + [[nodiscard]] bool hasEqualOrigins(zend_object *other, bool &out) const + { + zval *ownOrigin = origin(); + zval *theirOrigin = ownOrigin != NULL ? slot(other, slots::origin, "origin") : NULL; + if (UNEXPECTED(theirOrigin == NULL)) return false; + if (Z_TYPE_P(ownOrigin) != IS_OBJECT || Z_TYPE_P(theirOrigin) != IS_OBJECT) { + out = Z_TYPE_P(ownOrigin) != IS_OBJECT && Z_TYPE_P(theirOrigin) != IS_OBJECT; + return true; + } + int equal = pt_type_call_is_true(Z_OBJ_P(ownOrigin), PT_LC("equals"), 1, theirOrigin); + if (UNEXPECTED(equal < 0)) return false; + out = equal == 1; + return true; } /* Mirrors the private hasEqualUnresolvedSignature(): the markers of a @@ -504,7 +541,24 @@ class ClosureType if (common == 1) return prefixedName(); return describeCallable(); } - /* the precise and cache levels */ + if (which == PT_VERBOSITY_CACHE) { + /* the precise description and the origin */ + zv::Val precise = pt_type_verbosity_level(PT_VERBOSITY_LEVEL_PRECISE); + if (UNEXPECTED(precise.isUndef())) return zv::Val(); + zv::Val description = thisDescribe(precise.raw()); + if (UNEXPECTED(description.isUndef())) return zv::Val(); + zval *ownOrigin = origin(); + if (UNEXPECTED(ownOrigin == NULL)) return zv::Val(); + if (Z_TYPE_P(ownOrigin) != IS_OBJECT) return description; + zv::Val originDescription = pt_type_call(Z_OBJ_P(ownOrigin), PT_LC("describe"), 0, NULL); + if (UNEXPECTED(originDescription.isUndef())) return zv::Val(); + if (UNEXPECTED(Z_TYPE_P(description.raw()) != IS_STRING || Z_TYPE_P(originDescription.raw()) != IS_STRING)) { + zend_type_error("phpstan_turbo: describe() must return a string"); + return zv::Val(); + } + return zv::Val::adoptString(zend_strpprintf(0, "%s from %s", ZSTR_VAL(Z_STR_P(description.raw())), ZSTR_VAL(Z_STR_P(originDescription.raw())))); + } + /* the precise level */ zval *isStaticSlot = isStatic(); if (UNEXPECTED(isStaticSlot == NULL)) return zv::Val(); zend_long staticValue = pt_type_trinary_value(isStaticSlot); @@ -645,6 +699,13 @@ class ClosureType } zv::Val mappedAssertions = pt_assertions_map_types(args.assertions, &fci->function_name); if (UNEXPECTED(mappedAssertions.isUndef())) return zv::Val(); + /* $this->origin !== null ? $this->origin->traverse($cb) : null */ + zv::Val traversedOrigin; + if (Z_TYPE_P(args.origin) == IS_OBJECT) { + traversedOrigin = pt_type_call(Z_OBJ_P(args.origin), PT_LC("traverse"), 1, &fci->function_name); + if (UNEXPECTED(traversedOrigin.isUndef())) return zv::Val(); + args.origin = traversedOrigin.raw(); + } args.parameters = traversedParameters.raw(); args.returnType = traversedReturnType.raw(); args.variadic = variadic == 1; @@ -860,7 +921,8 @@ class ClosureType a.assertions = a.mustUseReturnValue != NULL ? assertions() : NULL; a.isStatic = a.assertions != NULL ? isStatic() : NULL; a.byRefUseTypes = a.isStatic != NULL ? byRefUseTypes() : NULL; - if (UNEXPECTED(a.byRefUseTypes == NULL)) return false; + a.origin = a.byRefUseTypes != NULL ? origin() : NULL; + if (UNEXPECTED(a.origin == NULL)) return false; a.variadic = zend_is_true(variadic); return true; } @@ -871,12 +933,25 @@ class ClosureType using phpstanturbo::ClosureType; using phpstanturbo::ClosureTypeArguments; -bool pt_closure_type_new(zval *out, zval *parameters, zval *returnType, bool variadic, zval *templateTypeMap, zval *resolvedTemplateTypeMap, zval *callSiteVarianceMap, zval *templateTags, zval *throwPoints, zval *impurePoints, zval *invalidateExpressions, zval *usedVariables, zval *acceptsNamedArguments, zval *mustUseReturnValue, zval *assertions, zval *isStatic, zval *byRefUseTypes) +bool pt_closure_type_new(zval *out, zval *parameters, zval *returnType, bool variadic, zval *templateTypeMap, zval *resolvedTemplateTypeMap, zval *callSiteVarianceMap, zval *templateTags, zval *throwPoints, zval *impurePoints, zval *invalidateExpressions, zval *usedVariables, zval *acceptsNamedArguments, zval *mustUseReturnValue, zval *assertions, zval *isStatic, zval *byRefUseTypes, zval *origin) { - ClosureTypeArguments a = { parameters, returnType, variadic, templateTypeMap, resolvedTemplateTypeMap, callSiteVarianceMap, templateTags, throwPoints, impurePoints, invalidateExpressions, usedVariables, acceptsNamedArguments, mustUseReturnValue, assertions, isStatic, byRefUseTypes }; + ClosureTypeArguments a = { parameters, returnType, variadic, templateTypeMap, resolvedTemplateTypeMap, callSiteVarianceMap, templateTags, throwPoints, impurePoints, invalidateExpressions, usedVariables, acceptsNamedArguments, mustUseReturnValue, assertions, isStatic, byRefUseTypes, origin }; return pt_val_into(ClosureType::create(a), out); } +zv::Val pt_closure_origin_for_function(zval *functionName) +{ + static pt_method_site site; + return pt_call_static_cached(site, PT_CLASS_CLOSURE_ORIGIN, PT_LC("forfunction"), 1, functionName); +} + +zv::Val pt_closure_origin_for_method(zval *calledOnType, zval *methodName, bool isStaticCall) +{ + static pt_method_site site; + zv::Args argv{calledOnType, methodName, isStaticCall}; + return pt_call_static_cached(site, PT_CLASS_CLOSURE_ORIGIN, PT_LC("formethod"), 3, argv); +} + zv::Val pt_closure_type_get_by_ref_use_types(zval *closureType) { if (EXPECTED(Z_OBJCE_P(closureType) == pt_ce_closure_type)) { @@ -1024,10 +1099,11 @@ PT_MINIT_REGISTRATION(pt_register_closure_type) reg::withDefault(reg::obj("assertions", "PHPStan\\Reflection\\Assertions", true), "null"), reg::withDefault(reg::obj("isStatic", ptcls::trinaryLogic, true), "null"), reg::withDefault(reg::arrayArg("byRefUseTypes"), "[]"), + reg::withDefault(reg::obj("origin", "PHPStan\\Type\\ClosureOrigin", true), "null"), }, [](INTERNAL_FUNCTION_PARAMETERS) { ClosureTypeArguments a = {}; a.variadic = true; - ZEND_PARSE_PARAMETERS_START(0, 16) + ZEND_PARSE_PARAMETERS_START(0, 17) Z_PARAM_OPTIONAL Z_PARAM_ARRAY_OR_NULL(a.parameters) Z_PARAM_OBJECT_OR_NULL(a.returnType) @@ -1045,6 +1121,7 @@ PT_MINIT_REGISTRATION(pt_register_closure_type) Z_PARAM_OBJECT_OR_NULL(a.assertions) Z_PARAM_OBJECT_OR_NULL(a.isStatic) Z_PARAM_ARRAY(a.byRefUseTypes) + Z_PARAM_OBJECT_OR_NULL(a.origin) ZEND_PARSE_PARAMETERS_END(); PT_THIS.construct(a); }); @@ -1057,6 +1134,10 @@ PT_MINIT_REGISTRATION(pt_register_closure_type) ZEND_PARSE_PARAMETERS_NONE(); cltReturnSlot(INTERNAL_FUNCTION_PARAM_PASSTHRU, PT_THIS.byRefUseTypes()); }); + cls.method(sigs::getOrigin, [](INTERNAL_FUNCTION_PARAMETERS) { + ZEND_PARSE_PARAMETERS_NONE(); + cltReturnSlot(INTERNAL_FUNCTION_PARAM_PASSTHRU, PT_THIS.origin()); + }); cls.method(sigs::containsUnresolvedTemplateArgument, [](INTERNAL_FUNCTION_PARAMETERS) { ZEND_PARSE_PARAMETERS_NONE(); bool contains; diff --git a/turbo-ext/src/FuncCallHandler.cpp b/turbo-ext/src/FuncCallHandler.cpp index 4516d4d303b..1ca0ffae19c 100644 --- a/turbo-ext/src/FuncCallHandler.cpp +++ b/turbo-ext/src/FuncCallHandler.cpp @@ -252,7 +252,6 @@ pt_property_site pt_fch_param_by_ref_site; pt_property_site pt_fch_param_var_site; pt_property_site pt_fch_variable_name_site; pt_property_site pt_fch_string_value_site; -pt_property_site pt_fch_inner_name_site; pt_property_site pt_fch_attributes_site; pt_property_site pt_fch_closure_uses_site; pt_property_site pt_fch_use_by_ref_site; @@ -303,12 +302,6 @@ zv::Val callArgs(zval *call) return hold.isUndef() ? zv::Val::copyOf(zv::Ref(args)) : std::move(hold); } -/* $call->isFirstClassCallable(); false = pending exception */ -[[nodiscard]] inline bool isFirstClassCallable(zval *call, bool &out) -{ - return pt_call_like_is_first_class_callable(Z_OBJ_P(call), out); -} - /* $call->isPartialFunctionApplication(); false = pending exception */ [[nodiscard]] inline bool isPartialFunctionApplication(zval *call, bool &out) { @@ -1288,7 +1281,13 @@ class FuncCallHandler dependencies = pt_dependencies_merge({nameDependencies, argsDependencies, ownDependencies.raw()}); if (UNEXPECTED(dependencies.isUndef())) return zv::Val(); } - return pt_expression_result_finalize(preliminaryResult.raw(), scope.raw(), hasYield, isAlwaysTerminating, throwPoints.raw(), impurePoints.raw(), variableFlow.raw(), dependencies.raw()); + zv::Val result = pt_expression_result_finalize(preliminaryResult.raw(), scope.raw(), hasYield, isAlwaysTerminating, throwPoints.raw(), impurePoints.raw(), variableFlow.raw(), dependencies.raw()); + if (UNEXPECTED(result.isUndef()) || calleeNameType.isNull()) return result; + + /* ClosureOriginCallReplay::replay($nodeScopeResolver, $this->expressionResultFactory, $expr, $nameType, $scopeBeforeArgs, $storage, $result) */ + static pt_method_site replaySite; + zv::Args replayArgv{nodeScopeResolver, slot(slots::expressionResultFactory), expr, calleeNameType.raw(), scopeBeforeArgs, storage, result.raw()}; + return pt_call_static_cached(replaySite, PT_CLASS_CLOSURE_ORIGIN_CALL_REPLAY, PT_LC("replay"), 7, replayArgv); } /* the handler entry (Engine.h) */ @@ -2102,14 +2101,6 @@ class FuncCallHandler if (UNEXPECTED(value == NULL)) return zv::Val(); functionName = pt_name_node_new(PT_CLASS_NAME, value); if (UNEXPECTED(functionName.isUndef())) return zv::Val(); - } else if (isA(name, PT_CLASS_FUNC_CALL)) { - zval *innerName = nodeProp(pt_fch_inner_name_site, name, PT_LC("name")); - if (UNEXPECTED(innerName == NULL)) return zv::Val(); - if (isA(innerName, PT_CLASS_NAME)) { - bool firstClassCallable; - if (UNEXPECTED(!isFirstClassCallable(name, firstClassCallable))) return zv::Val(); - if (firstClassCallable) functionName = zv::Val::copyOf(zv::Ref(innerName)); - } } if (UNEXPECTED(EG(exception))) return zv::Val(); diff --git a/turbo-ext/src/FunctionCallableNodeHandler.cpp b/turbo-ext/src/FunctionCallableNodeHandler.cpp index 52f6a7ae974..2fc3a164771 100644 --- a/turbo-ext/src/FunctionCallableNodeHandler.cpp +++ b/turbo-ext/src/FunctionCallableNodeHandler.cpp @@ -303,7 +303,7 @@ class FunctionCallableNodeHandler if (boundArgTypes.isNull()) { boundArgTypes = zv::Val(zv::Arr::empty()); } - return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), &null, acceptors.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes.raw()); + return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), &null, acceptors.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes.raw(), &null); } zv::Val initializerExprContext = ptveh::initializerExprContextFromScope(scope); diff --git a/turbo-ext/src/InitializerExprTypeResolver.cpp b/turbo-ext/src/InitializerExprTypeResolver.cpp index 81bdecde90c..8191ccfa985 100644 --- a/turbo-ext/src/InitializerExprTypeResolver.cpp +++ b/turbo-ext/src/InitializerExprTypeResolver.cpp @@ -2226,7 +2226,9 @@ class InitializerExprTypeResolver IETR_VAL(reflectionProvider, reflectionProviderOf(prop(slots::reflectionProviderProvider))); IETR_VAL(function, pt_reflection_provider_get_function(reflectionProvider.raw(), name, context)); IETR_VAL(variants, callOn(function.raw(), mGetVariants)); - return createFirstClassCallable(function.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes); + IETR_VAL(functionName, callOn(function.raw(), mGetName)); + IETR_VAL(origin, pt_closure_origin_for_function(functionName.raw())); + return createFirstClassCallable(function.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes, origin.raw()); } return newObjectTypeLiteral(PT_LC("Closure")); @@ -2302,7 +2304,8 @@ class InitializerExprTypeResolver } IETR_VAL(variants, callOn(method.raw(), mGetVariants)); - return createFirstClassCallable(method.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes); + IETR_VAL(origin, pt_closure_origin_for_method(classType.raw(), &methodName, true)); + return createFirstClassCallable(method.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes, origin.raw()); } int isNew = isAClass(expr, PT_CLASS_NEW); @@ -2368,10 +2371,16 @@ class InitializerExprTypeResolver return zv::Val(std::move(renamed)); } - /* Mirrors createFirstClassCallable(); $function and $partialApplicationArgs PHP null for null */ - static zv::Val createFirstClassCallable(zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes) + /* Mirrors createFirstClassCallable(); $function, $partialApplicationArgs and $origin PHP null for null */ + static zv::Val createFirstClassCallable(zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes, zval *originIn) { bool partialApplication = Z_TYPE_P(partialApplicationArgs) != IS_NULL; + zv::Val origin = zv::Val::copyOf(zv::Ref(originIn)); + if (Z_TYPE_P(originIn) == IS_OBJECT && partialApplication) { + zv::Args withArgv{partialApplicationArgs, boundArgTypes}; + origin = pt_type_call(Z_OBJ_P(originIn), PT_LC("withpartialapplication"), 2, withArgv); + if (UNEXPECTED(origin.isUndef())) return zv::Val(); + } if (UNEXPECTED(Z_TYPE_P(variants) != IS_ARRAY)) { zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(variants)); if (UNEXPECTED(EG(exception) != NULL)) return zv::Val(); @@ -2577,7 +2586,9 @@ class InitializerExprTypeResolver acceptsNamedArguments.raw(), mustUseReturnValue.raw(), predicateAssertions.raw(), - isStaticClosure.raw() + isStaticClosure.raw(), + NULL, + origin.raw() ))) return zv::Val(); closureTypes.push(zv::Val::adopt(closureType)); } @@ -3543,12 +3554,12 @@ zv::Val pt_initializer_expr_type_resolver_get_first_class_callable_type(zval *re return callResolverMethod(site, resolver, PT_LC("getfirstclasscallabletype"), 4, argv); } -zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes) +zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes, zval *origin) { - if (EXPECTED(isNativeResolver(resolver))) return InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes); + if (EXPECTED(isNativeResolver(resolver))) return InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes, origin); static pt_method_site site; - zv::Args argv{function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes}; - return callResolverMethod(site, resolver, PT_LC("createfirstclasscallable"), 5, argv); + zv::Args argv{function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes, origin}; + return callResolverMethod(site, resolver, PT_LC("createfirstclasscallable"), 6, argv); } zv::Val pt_initializer_expr_type_resolver_get_class_const_fetch_type_by_reflection(zval *resolver, zval *class_, zval *constantName, zval *classReflection, const pt_ietr_get_type &getTypeCallback, bool nativeTypesPromoted) @@ -3769,9 +3780,21 @@ PT_MINIT_REGISTRATION(pt_register_initializer_expr_type_resolver) }); cls.method(sigs::createFirstClassCallable, [](INTERNAL_FUNCTION_PARAMETERS) { - zval *function, *variants, *partialApplicationArgs = NULL, *boundArgTypes = NULL; + zval *function, *variants, *partialApplicationArgs = NULL, *boundArgTypes = NULL, *origin = NULL; bool nativeTypesPromoted; - if (!zp::parse, zp::Opt>(execute_data, function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes)) RETURN_THROWS(); + if (!zp::parse, zp::Opt, zp::Opt>(execute_data, function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes, origin)) RETURN_THROWS(); + zval nullOrigin; + if (origin == NULL) { + ZVAL_NULL(&nullOrigin); + origin = &nullOrigin; + } else if (Z_TYPE_P(origin) == IS_OBJECT) { + zend_class_entry *closureOriginCe = pt_class(PT_CLASS_CLOSURE_ORIGIN); + if (UNEXPECTED(closureOriginCe == NULL)) RETURN_THROWS(); + if (UNEXPECTED(!instanceof_function(Z_OBJCE_P(origin), closureOriginCe))) { + zend_argument_type_error(6, "must be of type ?PHPStan\\Type\\ClosureOrigin, %s given", zend_zval_value_name(origin)); + RETURN_THROWS(); + } + } zval nullArgs; if (partialApplicationArgs == NULL) { ZVAL_NULL(&nullArgs); @@ -3795,7 +3818,7 @@ PT_MINIT_REGISTRATION(pt_register_initializer_expr_type_resolver) RETURN_THROWS(); } } - PT_RETURN_VAL(InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes)); + PT_RETURN_VAL(InitializerExprTypeResolver::createFirstClassCallable(function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes, origin)); }); cls.method(sigs::getBitwiseAndType, IETR_OPERATOR_GLUE(self.getOperatorType(IETR_BITWISE_AND, left, right, getTypeCallback))); diff --git a/turbo-ext/src/MethodCallableNodeHandler.cpp b/turbo-ext/src/MethodCallableNodeHandler.cpp index 22a394a4e26..435bdc1c8ca 100644 --- a/turbo-ext/src/MethodCallableNodeHandler.cpp +++ b/turbo-ext/src/MethodCallableNodeHandler.cpp @@ -274,7 +274,9 @@ class MethodCallableNodeHandler if (boundArgTypes.isNull()) { boundArgTypes = zv::Val(zv::Arr::empty()); } - return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), method.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes.raw()); + zv::Val origin = pt_closure_origin_for_method(varType.raw(), methodName, false); + if (UNEXPECTED(origin.isUndef())) return zv::Val(); + return ptveh::createFirstClassCallable(OBJ_PROP_NUM(self, slots::initializerExprTypeResolver), method.raw(), variants.raw(), nativeTypesPromoted, partialApplicationArgs, boundArgTypes.raw(), origin.raw()); } /* the handler entry (Engine.h) */ diff --git a/turbo-ext/src/VirtualExprHandlers.h b/turbo-ext/src/VirtualExprHandlers.h index 97a96cd6537..499615e10e8 100644 --- a/turbo-ext/src/VirtualExprHandlers.h +++ b/turbo-ext/src/VirtualExprHandlers.h @@ -141,10 +141,10 @@ inline zval *nodeRead(NodeProp &prop, zval *node) * once they are ported) */ -/* $initializerExprTypeResolver->createFirstClassCallable($function, $variants, $nativeTypesPromoted, $partialApplicationArgs, $boundArgTypes) */ -inline zv::Val createFirstClassCallable(zval *initializerExprTypeResolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes) +/* $initializerExprTypeResolver->createFirstClassCallable($function, $variants, $nativeTypesPromoted, $partialApplicationArgs, $boundArgTypes, $origin) */ +inline zv::Val createFirstClassCallable(zval *initializerExprTypeResolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes, zval *origin) { - return pt_initializer_expr_type_resolver_create_first_class_callable(initializerExprTypeResolver, function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes); + return pt_initializer_expr_type_resolver_create_first_class_callable(initializerExprTypeResolver, function, variants, nativeTypesPromoted, partialApplicationArgs, boundArgTypes, origin); } /* $initializerExprTypeResolver->getFirstClassCallableType($expr, $context, $nativeTypesPromoted, $boundArgTypes) */ diff --git a/turbo-ext/src/generated/ClosureType.h b/turbo-ext/src/generated/ClosureType.h index a2e7e5a8e39..9c0fc814225 100644 --- a/turbo-ext/src/generated/ClosureType.h +++ b/turbo-ext/src/generated/ClosureType.h @@ -30,6 +30,7 @@ inline constexpr uint32_t throwPoints = 16; inline constexpr uint32_t invalidateExpressions = 17; inline constexpr uint32_t usedVariables = 18; inline constexpr uint32_t byRefUseTypes = 19; +inline constexpr uint32_t origin = 20; } // namespace slot inline void declareClass(reg::Class &cls) @@ -60,6 +61,7 @@ inline void declareProperties(reg::Class &cls) cls.property("invalidateExpressions", ZEND_ACC_PRIVATE, reg::PropertyKind::Typed, MAY_BE_ARRAY); cls.property("usedVariables", ZEND_ACC_PRIVATE, reg::PropertyKind::Typed, MAY_BE_ARRAY); cls.property("byRefUseTypes", ZEND_ACC_PRIVATE, reg::PropertyKind::Typed, MAY_BE_ARRAY); + cls.property("origin", ZEND_ACC_PRIVATE, reg::PropertyKind::Typed, MAY_BE_NULL, "PHPStan\\Type\\ClosureOrigin"); } /* the shared registrars of the traits the twin uses, in its own order (a used trait's own traits after it) */ @@ -101,164 +103,170 @@ inline constexpr char strings[] = "PHPStan\\Reflection\\Assertions\0" /* 351 */ "isStatic\0" /* 381 */ "byRefUseTypes\0" /* 390 */ - "__construct\0" /* 404 */ - "\0" /* 416 */ - "getAsserts\0" /* 417 */ - "getTemplateTags\0" /* 428 */ - "PHPStan\\Type\\ClosureType\0" /* 444 */ - "createPure\0" /* 469 */ - "isPure\0" /* 480 */ - "getClassName\0" /* 487 */ - "PHPStan\\Reflection\\ClassReflection\0" /* 500 */ - "getClassReflection\0" /* 535 */ - "className\0" /* 554 */ - "PHPStan\\Type\\TypeWithClassName\0" /* 564 */ - "getAncestorWithClassName\0" /* 595 */ - "getReferencedClasses\0" /* 620 */ - "getObjectClassNames\0" /* 641 */ - "getObjectClassReflections\0" /* 661 */ - "type\0" /* 687 */ - "strictTypes\0" /* 692 */ - "PHPStan\\Type\\AcceptsResult\0" /* 704 */ - "accepts\0" /* 731 */ - "PHPStan\\Type\\IsSuperTypeOfResult\0" /* 739 */ - "isSuperTypeOf\0" /* 772 */ - "treatMixedAsAny\0" /* 786 */ - "isSuperTypeOfInternal\0" /* 802 */ - "equals\0" /* 824 */ - "other\0" /* 831 */ - "hasEqualUnresolvedSignature\0" /* 837 */ - "level\0" /* 865 */ - "PHPStan\\Type\\VerbosityLevel\0" /* 871 */ - "describe\0" /* 899 */ - "describeCallable\0" /* 908 */ - "isOffsetAccessLegal\0" /* 925 */ - "isObject\0" /* 945 */ - "getClassStringType\0" /* 954 */ - "isEnum\0" /* 973 */ - "ancestorClassName\0" /* 980 */ - "templateTypeName\0" /* 998 */ - "getTemplateType\0" /* 1015 */ - "canAccessProperties\0" /* 1031 */ - "propertyName\0" /* 1051 */ - "hasProperty\0" /* 1064 */ - "scope\0" /* 1076 */ - "PHPStan\\Reflection\\ClassMemberAccessAnswerer\0" /* 1082 */ - "PHPStan\\Reflection\\ExtendedPropertyReflection\0" /* 1127 */ - "getProperty\0" /* 1173 */ - "PHPStan\\Reflection\\Type\\UnresolvedPropertyPrototypeReflection\0" /* 1185 */ - "getUnresolvedPropertyPrototype\0" /* 1247 */ - "hasInstanceProperty\0" /* 1278 */ - "getInstanceProperty\0" /* 1298 */ - "getUnresolvedInstancePropertyPrototype\0" /* 1318 */ - "hasStaticProperty\0" /* 1357 */ - "getStaticProperty\0" /* 1375 */ - "getUnresolvedStaticPropertyPrototype\0" /* 1393 */ - "canCallMethods\0" /* 1430 */ - "methodName\0" /* 1445 */ - "hasMethod\0" /* 1456 */ - "PHPStan\\Reflection\\ExtendedMethodReflection\0" /* 1466 */ - "getMethod\0" /* 1510 */ - "PHPStan\\Reflection\\Type\\UnresolvedMethodPrototypeReflection\0" /* 1520 */ - "getUnresolvedMethodPrototype\0" /* 1580 */ - "canAccessConstants\0" /* 1609 */ - "constantName\0" /* 1628 */ - "hasConstant\0" /* 1641 */ - "PHPStan\\Reflection\\ClassConstantReflection\0" /* 1653 */ - "getConstant\0" /* 1696 */ - "getConstantStrings\0" /* 1708 */ - "isIterable\0" /* 1727 */ - "isIterableAtLeastOnce\0" /* 1738 */ - "isCallable\0" /* 1760 */ - "getEnumCases\0" /* 1771 */ - "PHPStan\\Type\\Enum\\EnumCaseObjectType\0" /* 1784 */ - "getEnumCaseObject\0" /* 1821 */ - "isCommonCallable\0" /* 1839 */ - "getCallableParametersAcceptors\0" /* 1856 */ - "getThrowPoints\0" /* 1887 */ - "getImpurePoints\0" /* 1902 */ - "getInvalidateExpressions\0" /* 1918 */ - "getUsedVariables\0" /* 1943 */ - "getByRefUseTypes\0" /* 1960 */ - "containsUnresolvedTemplateArgument\0" /* 1977 */ - "isStaticClosure\0" /* 2012 */ - "isCloneable\0" /* 2028 */ - "PHPStan\\Type\\BooleanType\0" /* 2040 */ - "toBoolean\0" /* 2065 */ - "toNumber\0" /* 2075 */ - "toBitwiseNotType\0" /* 2084 */ - "toGetClassResultType\0" /* 2101 */ - "reflectionProvider\0" /* 2122 */ - "PHPStan\\Reflection\\ReflectionProvider\0" /* 2141 */ - "toClassConstantType\0" /* 2179 */ - "PHPStan\\Type\\ClassNameToObjectTypeResult\0" /* 2199 */ - "toObjectTypeForInstanceofCheck\0" /* 2240 */ - "objectOrClassType\0" /* 2271 */ - "allowString\0" /* 2289 */ - "allowSameClass\0" /* 2301 */ - "toObjectTypeForIsACheck\0" /* 2316 */ - "toAbsoluteNumber\0" /* 2340 */ - "toInteger\0" /* 2357 */ - "toFloat\0" /* 2367 */ - "toString\0" /* 2375 */ - "toArray\0" /* 2384 */ - "toArrayKey\0" /* 2392 */ - "toCoercedArgumentType\0" /* 2403 */ - "getTemplateTypeMap\0" /* 2425 */ - "getResolvedTemplateTypeMap\0" /* 2444 */ - "getCallSiteVarianceMap\0" /* 2471 */ - "getParameters\0" /* 2494 */ - "isVariadic\0" /* 2508 */ - "getReturnType\0" /* 2519 */ - "receivedType\0" /* 2533 */ - "inferTemplateTypes\0" /* 2546 */ - "parametersAcceptor\0" /* 2565 */ - "PHPStan\\Reflection\\ParametersAcceptor\0" /* 2584 */ - "inferTemplateTypesOnParametersAcceptor\0" /* 2622 */ - "positionVariance\0" /* 2661 */ - "PHPStan\\Type\\Generic\\TemplateTypeVariance\0" /* 2678 */ - "getReferencedTemplateTypes\0" /* 2720 */ - "cb\0" /* 2747 */ - "traverse\0" /* 2750 */ - "right\0" /* 2759 */ - "traverseSimultaneously\0" /* 2765 */ - "isNull\0" /* 2788 */ - "isConstantValue\0" /* 2795 */ - "isConstantScalarValue\0" /* 2811 */ - "getConstantScalarTypes\0" /* 2833 */ - "getConstantScalarValues\0" /* 2856 */ - "isTrue\0" /* 2880 */ - "isFalse\0" /* 2887 */ - "isBoolean\0" /* 2895 */ - "isFloat\0" /* 2905 */ - "isInteger\0" /* 2913 */ - "isString\0" /* 2923 */ - "isNumericString\0" /* 2932 */ - "isDecimalIntegerString\0" /* 2948 */ - "isNonEmptyString\0" /* 2971 */ - "isNonFalsyString\0" /* 2988 */ - "isLiteralString\0" /* 3005 */ - "isLowercaseString\0" /* 3021 */ - "isClassString\0" /* 3039 */ - "isUppercaseString\0" /* 3053 */ - "getClassStringObjectType\0" /* 3071 */ - "getObjectTypeOrClassStringObjectType\0" /* 3096 */ - "isVoid\0" /* 3133 */ - "isScalar\0" /* 3140 */ - "phpVersion\0" /* 3149 */ - "PHPStan\\Php\\PhpVersion\0" /* 3160 */ - "looseCompare\0" /* 3183 */ - "exponent\0" /* 3196 */ - "arithmeticPower\0" /* 3205 */ - "getFiniteTypes\0" /* 3221 */ - "PHPStan\\PhpDocParser\\Ast\\Type\\TypeNode\0" /* 3236 */ - "toPhpDocNode\0" /* 3275 */ - "position\0" /* 3288 */ - "PHPStan\\Type\\NativeTypePosition\0" /* 3297 */ - "toNativePhpTypeNode\0" /* 3329 */ - "hasTemplateOrLateResolvableType\0" /* 3349 */ - "PHPStan\\Type\\ValueSet\0" /* 3381 */ - "toValueSet"; /* 3403 */ + "origin\0" /* 404 */ + "PHPStan\\Type\\ClosureOrigin\0" /* 411 */ + "__construct\0" /* 438 */ + "\0" /* 450 */ + "getAsserts\0" /* 451 */ + "getTemplateTags\0" /* 462 */ + "PHPStan\\Type\\ClosureType\0" /* 478 */ + "createPure\0" /* 503 */ + "isPure\0" /* 514 */ + "getClassName\0" /* 521 */ + "PHPStan\\Reflection\\ClassReflection\0" /* 534 */ + "getClassReflection\0" /* 569 */ + "className\0" /* 588 */ + "PHPStan\\Type\\TypeWithClassName\0" /* 598 */ + "getAncestorWithClassName\0" /* 629 */ + "getReferencedClasses\0" /* 654 */ + "getObjectClassNames\0" /* 675 */ + "getObjectClassReflections\0" /* 695 */ + "type\0" /* 721 */ + "strictTypes\0" /* 726 */ + "PHPStan\\Type\\AcceptsResult\0" /* 738 */ + "accepts\0" /* 765 */ + "PHPStan\\Type\\IsSuperTypeOfResult\0" /* 773 */ + "isSuperTypeOf\0" /* 806 */ + "treatMixedAsAny\0" /* 820 */ + "isSuperTypeOfInternal\0" /* 836 */ + "equals\0" /* 858 */ + "a\0" /* 865 */ + "b\0" /* 867 */ + "hasEqualOrigins\0" /* 869 */ + "other\0" /* 885 */ + "hasEqualUnresolvedSignature\0" /* 891 */ + "level\0" /* 919 */ + "PHPStan\\Type\\VerbosityLevel\0" /* 925 */ + "describe\0" /* 953 */ + "describeCallable\0" /* 962 */ + "isOffsetAccessLegal\0" /* 979 */ + "isObject\0" /* 999 */ + "getClassStringType\0" /* 1008 */ + "isEnum\0" /* 1027 */ + "ancestorClassName\0" /* 1034 */ + "templateTypeName\0" /* 1052 */ + "getTemplateType\0" /* 1069 */ + "canAccessProperties\0" /* 1085 */ + "propertyName\0" /* 1105 */ + "hasProperty\0" /* 1118 */ + "scope\0" /* 1130 */ + "PHPStan\\Reflection\\ClassMemberAccessAnswerer\0" /* 1136 */ + "PHPStan\\Reflection\\ExtendedPropertyReflection\0" /* 1181 */ + "getProperty\0" /* 1227 */ + "PHPStan\\Reflection\\Type\\UnresolvedPropertyPrototypeReflection\0" /* 1239 */ + "getUnresolvedPropertyPrototype\0" /* 1301 */ + "hasInstanceProperty\0" /* 1332 */ + "getInstanceProperty\0" /* 1352 */ + "getUnresolvedInstancePropertyPrototype\0" /* 1372 */ + "hasStaticProperty\0" /* 1411 */ + "getStaticProperty\0" /* 1429 */ + "getUnresolvedStaticPropertyPrototype\0" /* 1447 */ + "canCallMethods\0" /* 1484 */ + "methodName\0" /* 1499 */ + "hasMethod\0" /* 1510 */ + "PHPStan\\Reflection\\ExtendedMethodReflection\0" /* 1520 */ + "getMethod\0" /* 1564 */ + "PHPStan\\Reflection\\Type\\UnresolvedMethodPrototypeReflection\0" /* 1574 */ + "getUnresolvedMethodPrototype\0" /* 1634 */ + "canAccessConstants\0" /* 1663 */ + "constantName\0" /* 1682 */ + "hasConstant\0" /* 1695 */ + "PHPStan\\Reflection\\ClassConstantReflection\0" /* 1707 */ + "getConstant\0" /* 1750 */ + "getConstantStrings\0" /* 1762 */ + "isIterable\0" /* 1781 */ + "isIterableAtLeastOnce\0" /* 1792 */ + "isCallable\0" /* 1814 */ + "getEnumCases\0" /* 1825 */ + "PHPStan\\Type\\Enum\\EnumCaseObjectType\0" /* 1838 */ + "getEnumCaseObject\0" /* 1875 */ + "isCommonCallable\0" /* 1893 */ + "getCallableParametersAcceptors\0" /* 1910 */ + "getThrowPoints\0" /* 1941 */ + "getImpurePoints\0" /* 1956 */ + "getInvalidateExpressions\0" /* 1972 */ + "getUsedVariables\0" /* 1997 */ + "getByRefUseTypes\0" /* 2014 */ + "getOrigin\0" /* 2031 */ + "containsUnresolvedTemplateArgument\0" /* 2041 */ + "isStaticClosure\0" /* 2076 */ + "isCloneable\0" /* 2092 */ + "PHPStan\\Type\\BooleanType\0" /* 2104 */ + "toBoolean\0" /* 2129 */ + "toNumber\0" /* 2139 */ + "toBitwiseNotType\0" /* 2148 */ + "toGetClassResultType\0" /* 2165 */ + "reflectionProvider\0" /* 2186 */ + "PHPStan\\Reflection\\ReflectionProvider\0" /* 2205 */ + "toClassConstantType\0" /* 2243 */ + "PHPStan\\Type\\ClassNameToObjectTypeResult\0" /* 2263 */ + "toObjectTypeForInstanceofCheck\0" /* 2304 */ + "objectOrClassType\0" /* 2335 */ + "allowString\0" /* 2353 */ + "allowSameClass\0" /* 2365 */ + "toObjectTypeForIsACheck\0" /* 2380 */ + "toAbsoluteNumber\0" /* 2404 */ + "toInteger\0" /* 2421 */ + "toFloat\0" /* 2431 */ + "toString\0" /* 2439 */ + "toArray\0" /* 2448 */ + "toArrayKey\0" /* 2456 */ + "toCoercedArgumentType\0" /* 2467 */ + "getTemplateTypeMap\0" /* 2489 */ + "getResolvedTemplateTypeMap\0" /* 2508 */ + "getCallSiteVarianceMap\0" /* 2535 */ + "getParameters\0" /* 2558 */ + "isVariadic\0" /* 2572 */ + "getReturnType\0" /* 2583 */ + "receivedType\0" /* 2597 */ + "inferTemplateTypes\0" /* 2610 */ + "parametersAcceptor\0" /* 2629 */ + "PHPStan\\Reflection\\ParametersAcceptor\0" /* 2648 */ + "inferTemplateTypesOnParametersAcceptor\0" /* 2686 */ + "positionVariance\0" /* 2725 */ + "PHPStan\\Type\\Generic\\TemplateTypeVariance\0" /* 2742 */ + "getReferencedTemplateTypes\0" /* 2784 */ + "cb\0" /* 2811 */ + "traverse\0" /* 2814 */ + "right\0" /* 2823 */ + "traverseSimultaneously\0" /* 2829 */ + "isNull\0" /* 2852 */ + "isConstantValue\0" /* 2859 */ + "isConstantScalarValue\0" /* 2875 */ + "getConstantScalarTypes\0" /* 2897 */ + "getConstantScalarValues\0" /* 2920 */ + "isTrue\0" /* 2944 */ + "isFalse\0" /* 2951 */ + "isBoolean\0" /* 2959 */ + "isFloat\0" /* 2969 */ + "isInteger\0" /* 2977 */ + "isString\0" /* 2987 */ + "isNumericString\0" /* 2996 */ + "isDecimalIntegerString\0" /* 3012 */ + "isNonEmptyString\0" /* 3035 */ + "isNonFalsyString\0" /* 3052 */ + "isLiteralString\0" /* 3069 */ + "isLowercaseString\0" /* 3085 */ + "isClassString\0" /* 3103 */ + "isUppercaseString\0" /* 3117 */ + "getClassStringObjectType\0" /* 3135 */ + "getObjectTypeOrClassStringObjectType\0" /* 3160 */ + "isVoid\0" /* 3197 */ + "isScalar\0" /* 3204 */ + "phpVersion\0" /* 3213 */ + "PHPStan\\Php\\PhpVersion\0" /* 3224 */ + "looseCompare\0" /* 3247 */ + "exponent\0" /* 3260 */ + "arithmeticPower\0" /* 3269 */ + "getFiniteTypes\0" /* 3285 */ + "PHPStan\\PhpDocParser\\Ast\\Type\\TypeNode\0" /* 3300 */ + "toPhpDocNode\0" /* 3339 */ + "position\0" /* 3352 */ + "PHPStan\\Type\\NativeTypePosition\0" /* 3361 */ + "toNativePhpTypeNode\0" /* 3393 */ + "hasTemplateOrLateResolvableType\0" /* 3413 */ + "PHPStan\\Type\\ValueSet\0" /* 3445 */ + "toValueSet"; /* 3467 */ inline constexpr reg::PackedArg args[] = { reg::packed(0, MAY_BE_NULL | MAY_BE_ARRAY, reg::NoString, false, false, 11), /* __construct $parameters */ reg::packed(16, MAY_BE_NULL, 27, false, false, 11), /* __construct $returnType */ @@ -276,287 +284,294 @@ inline constexpr reg::PackedArg args[] = { reg::packed(340, MAY_BE_NULL, 351, false, false, 11), /* __construct $assertions */ reg::packed(381, MAY_BE_NULL, 300, false, false, 11), /* __construct $isStatic */ reg::packed(390, MAY_BE_ARRAY, reg::NoString, false, false, 214), /* __construct $byRefUseTypes */ - reg::packed(416, 0, 351), /* getAsserts return */ - reg::packed(416, MAY_BE_ARRAY), /* getTemplateTags return */ - reg::packed(416, 0, 444), /* createPure return */ - reg::packed(416, 0, 300), /* isPure return */ - reg::packed(416, MAY_BE_STRING), /* getClassName return */ - reg::packed(416, MAY_BE_NULL, 500), /* getClassReflection return */ - reg::packed(554, MAY_BE_STRING), /* getAncestorWithClassName $className */ - reg::packed(416, MAY_BE_NULL, 564), /* getAncestorWithClassName return */ - reg::packed(416, MAY_BE_ARRAY), /* getReferencedClasses return */ - reg::packed(416, MAY_BE_ARRAY), /* getObjectClassNames return */ - reg::packed(416, MAY_BE_ARRAY), /* getObjectClassReflections return */ - reg::packed(687, 0, 27), /* accepts $type */ - reg::packed(692, MAY_BE_BOOL), /* accepts $strictTypes */ - reg::packed(416, 0, 704), /* accepts return */ - reg::packed(687, 0, 27), /* isSuperTypeOf $type */ - reg::packed(416, 0, 739), /* isSuperTypeOf return */ - reg::packed(687, 0, 27), /* isSuperTypeOfInternal $type */ - reg::packed(786, MAY_BE_BOOL), /* isSuperTypeOfInternal $treatMixedAsAny */ - reg::packed(692, MAY_BE_BOOL, reg::NoString, false, false, 54), /* isSuperTypeOfInternal $strictTypes */ - reg::packed(416, 0, 739), /* isSuperTypeOfInternal return */ - reg::packed(687, 0, 27), /* equals $type */ - reg::packed(416, MAY_BE_BOOL), /* equals return */ - reg::packed(831, 0, 444), /* hasEqualUnresolvedSignature $other */ - reg::packed(416, MAY_BE_BOOL), /* hasEqualUnresolvedSignature return */ - reg::packed(865, 0, 871), /* describe $level */ - reg::packed(416, MAY_BE_STRING), /* describe return */ - reg::packed(416, MAY_BE_STRING), /* describeCallable return */ - reg::packed(416, 0, 300), /* isOffsetAccessLegal return */ - reg::packed(416, 0, 300), /* isObject return */ - reg::packed(416, 0, 27), /* getClassStringType return */ - reg::packed(416, 0, 300), /* isEnum return */ - reg::packed(980, MAY_BE_STRING), /* getTemplateType $ancestorClassName */ - reg::packed(998, MAY_BE_STRING), /* getTemplateType $templateTypeName */ - reg::packed(416, 0, 27), /* getTemplateType return */ - reg::packed(416, 0, 300), /* canAccessProperties return */ - reg::packed(1051, MAY_BE_STRING), /* hasProperty $propertyName */ - reg::packed(416, 0, 300), /* hasProperty return */ - reg::packed(1051, MAY_BE_STRING), /* getProperty $propertyName */ - reg::packed(1076, 0, 1082), /* getProperty $scope */ - reg::packed(416, 0, 1127), /* getProperty return */ - reg::packed(1051, MAY_BE_STRING), /* getUnresolvedPropertyPrototype $propertyName */ - reg::packed(1076, 0, 1082), /* getUnresolvedPropertyPrototype $scope */ - reg::packed(416, 0, 1185), /* getUnresolvedPropertyPrototype return */ - reg::packed(1051, MAY_BE_STRING), /* hasInstanceProperty $propertyName */ - reg::packed(416, 0, 300), /* hasInstanceProperty return */ - reg::packed(1051, MAY_BE_STRING), /* getInstanceProperty $propertyName */ - reg::packed(1076, 0, 1082), /* getInstanceProperty $scope */ - reg::packed(416, 0, 1127), /* getInstanceProperty return */ - reg::packed(1051, MAY_BE_STRING), /* getUnresolvedInstancePropertyPrototype $propertyName */ - reg::packed(1076, 0, 1082), /* getUnresolvedInstancePropertyPrototype $scope */ - reg::packed(416, 0, 1185), /* getUnresolvedInstancePropertyPrototype return */ - reg::packed(1051, MAY_BE_STRING), /* hasStaticProperty $propertyName */ - reg::packed(416, 0, 300), /* hasStaticProperty return */ - reg::packed(1051, MAY_BE_STRING), /* getStaticProperty $propertyName */ - reg::packed(1076, 0, 1082), /* getStaticProperty $scope */ - reg::packed(416, 0, 1127), /* getStaticProperty return */ - reg::packed(1051, MAY_BE_STRING), /* getUnresolvedStaticPropertyPrototype $propertyName */ - reg::packed(1076, 0, 1082), /* getUnresolvedStaticPropertyPrototype $scope */ - reg::packed(416, 0, 1185), /* getUnresolvedStaticPropertyPrototype return */ - reg::packed(416, 0, 300), /* canCallMethods return */ - reg::packed(1445, MAY_BE_STRING), /* hasMethod $methodName */ - reg::packed(416, 0, 300), /* hasMethod return */ - reg::packed(1445, MAY_BE_STRING), /* getMethod $methodName */ - reg::packed(1076, 0, 1082), /* getMethod $scope */ - reg::packed(416, 0, 1466), /* getMethod return */ - reg::packed(1445, MAY_BE_STRING), /* getUnresolvedMethodPrototype $methodName */ - reg::packed(1076, 0, 1082), /* getUnresolvedMethodPrototype $scope */ - reg::packed(416, 0, 1520), /* getUnresolvedMethodPrototype return */ - reg::packed(416, 0, 300), /* canAccessConstants return */ - reg::packed(1628, MAY_BE_STRING), /* hasConstant $constantName */ - reg::packed(416, 0, 300), /* hasConstant return */ - reg::packed(1628, MAY_BE_STRING), /* getConstant $constantName */ - reg::packed(416, 0, 1653), /* getConstant return */ - reg::packed(416, MAY_BE_ARRAY), /* getConstantStrings return */ - reg::packed(416, 0, 300), /* isIterable return */ - reg::packed(416, 0, 300), /* isIterableAtLeastOnce return */ - reg::packed(416, 0, 300), /* isCallable return */ - reg::packed(416, MAY_BE_ARRAY), /* getEnumCases return */ - reg::packed(416, MAY_BE_NULL, 1784), /* getEnumCaseObject return */ - reg::packed(416, MAY_BE_BOOL), /* isCommonCallable return */ - reg::packed(1076, 0, 1082), /* getCallableParametersAcceptors $scope */ - reg::packed(416, MAY_BE_ARRAY), /* getCallableParametersAcceptors return */ - reg::packed(416, MAY_BE_ARRAY), /* getThrowPoints return */ - reg::packed(416, MAY_BE_ARRAY), /* getImpurePoints return */ - reg::packed(416, MAY_BE_ARRAY), /* getInvalidateExpressions return */ - reg::packed(416, MAY_BE_ARRAY), /* getUsedVariables return */ - reg::packed(416, MAY_BE_ARRAY), /* getByRefUseTypes return */ - reg::packed(416, MAY_BE_BOOL), /* containsUnresolvedTemplateArgument return */ - reg::packed(416, 0, 300), /* acceptsNamedArguments return */ - reg::packed(416, 0, 300), /* mustUseReturnValue return */ - reg::packed(416, 0, 300), /* isStaticClosure return */ - reg::packed(416, 0, 300), /* isCloneable return */ - reg::packed(416, 0, 2040), /* toBoolean return */ - reg::packed(416, 0, 27), /* toNumber return */ - reg::packed(416, 0, 27), /* toBitwiseNotType return */ - reg::packed(416, 0, 27), /* toGetClassResultType return */ - reg::packed(2122, 0, 2141), /* toClassConstantType $reflectionProvider */ - reg::packed(416, 0, 27), /* toClassConstantType return */ - reg::packed(416, 0, 2199), /* toObjectTypeForInstanceofCheck return */ - reg::packed(2271, 0, 27), /* toObjectTypeForIsACheck $objectOrClassType */ - reg::packed(2289, MAY_BE_BOOL), /* toObjectTypeForIsACheck $allowString */ - reg::packed(2301, MAY_BE_BOOL), /* toObjectTypeForIsACheck $allowSameClass */ - reg::packed(416, 0, 2199), /* toObjectTypeForIsACheck return */ - reg::packed(416, 0, 27), /* toAbsoluteNumber return */ - reg::packed(416, 0, 27), /* toInteger return */ - reg::packed(416, 0, 27), /* toFloat return */ - reg::packed(416, 0, 27), /* toString return */ - reg::packed(416, 0, 27), /* toArray return */ - reg::packed(416, 0, 27), /* toArrayKey return */ - reg::packed(692, MAY_BE_BOOL), /* toCoercedArgumentType $strictTypes */ - reg::packed(416, 0, 27), /* toCoercedArgumentType return */ - reg::packed(416, 0, 75), /* getTemplateTypeMap return */ - reg::packed(416, 0, 75), /* getResolvedTemplateTypeMap return */ - reg::packed(416, 0, 156), /* getCallSiteVarianceMap return */ - reg::packed(416, MAY_BE_ARRAY), /* getParameters return */ - reg::packed(416, MAY_BE_BOOL), /* isVariadic return */ - reg::packed(416, 0, 27), /* getReturnType return */ - reg::packed(2533, 0, 27), /* inferTemplateTypes $receivedType */ - reg::packed(416, 0, 75), /* inferTemplateTypes return */ - reg::packed(2565, 0, 2584), /* inferTemplateTypesOnParametersAcceptor $parametersAcceptor */ - reg::packed(416, 0, 75), /* inferTemplateTypesOnParametersAcceptor return */ - reg::packed(2661, 0, 2678), /* getReferencedTemplateTypes $positionVariance */ - reg::packed(416, MAY_BE_ARRAY), /* getReferencedTemplateTypes return */ - reg::packed(2747, MAY_BE_CALLABLE), /* traverse $cb */ - reg::packed(416, 0, 27), /* traverse return */ - reg::packed(2759, 0, 27), /* traverseSimultaneously $right */ - reg::packed(2747, MAY_BE_CALLABLE), /* traverseSimultaneously $cb */ - reg::packed(416, 0, 27), /* traverseSimultaneously return */ - reg::packed(416, 0, 300), /* isNull return */ - reg::packed(416, 0, 300), /* isConstantValue return */ - reg::packed(416, 0, 300), /* isConstantScalarValue return */ - reg::packed(416, MAY_BE_ARRAY), /* getConstantScalarTypes return */ - reg::packed(416, MAY_BE_ARRAY), /* getConstantScalarValues return */ - reg::packed(416, 0, 300), /* isTrue return */ - reg::packed(416, 0, 300), /* isFalse return */ - reg::packed(416, 0, 300), /* isBoolean return */ - reg::packed(416, 0, 300), /* isFloat return */ - reg::packed(416, 0, 300), /* isInteger return */ - reg::packed(416, 0, 300), /* isString return */ - reg::packed(416, 0, 300), /* isNumericString return */ - reg::packed(416, 0, 300), /* isDecimalIntegerString return */ - reg::packed(416, 0, 300), /* isNonEmptyString return */ - reg::packed(416, 0, 300), /* isNonFalsyString return */ - reg::packed(416, 0, 300), /* isLiteralString return */ - reg::packed(416, 0, 300), /* isLowercaseString return */ - reg::packed(416, 0, 300), /* isClassString return */ - reg::packed(416, 0, 300), /* isUppercaseString return */ - reg::packed(416, 0, 27), /* getClassStringObjectType return */ - reg::packed(416, 0, 27), /* getObjectTypeOrClassStringObjectType return */ - reg::packed(416, 0, 300), /* isVoid return */ - reg::packed(416, 0, 300), /* isScalar return */ - reg::packed(687, 0, 27), /* looseCompare $type */ - reg::packed(3149, 0, 3160), /* looseCompare $phpVersion */ - reg::packed(416, 0, 2040), /* looseCompare return */ - reg::packed(3196, 0, 27), /* arithmeticPower $exponent */ - reg::packed(3149, 0, 3160), /* arithmeticPower $phpVersion */ - reg::packed(416, 0, 27), /* arithmeticPower return */ - reg::packed(416, MAY_BE_ARRAY), /* getFiniteTypes return */ - reg::packed(416, 0, 3236), /* toPhpDocNode return */ - reg::packed(3288, 0, 3297), /* toNativePhpTypeNode $position */ - reg::packed(416, MAY_BE_BOOL), /* hasTemplateOrLateResolvableType return */ - reg::packed(416, 0, 3381), /* toValueSet return */ + reg::packed(404, MAY_BE_NULL, 411, false, false, 11), /* __construct $origin */ + reg::packed(450, 0, 351), /* getAsserts return */ + reg::packed(450, MAY_BE_ARRAY), /* getTemplateTags return */ + reg::packed(450, 0, 478), /* createPure return */ + reg::packed(450, 0, 300), /* isPure return */ + reg::packed(450, MAY_BE_STRING), /* getClassName return */ + reg::packed(450, MAY_BE_NULL, 534), /* getClassReflection return */ + reg::packed(588, MAY_BE_STRING), /* getAncestorWithClassName $className */ + reg::packed(450, MAY_BE_NULL, 598), /* getAncestorWithClassName return */ + reg::packed(450, MAY_BE_ARRAY), /* getReferencedClasses return */ + reg::packed(450, MAY_BE_ARRAY), /* getObjectClassNames return */ + reg::packed(450, MAY_BE_ARRAY), /* getObjectClassReflections return */ + reg::packed(721, 0, 27), /* accepts $type */ + reg::packed(726, MAY_BE_BOOL), /* accepts $strictTypes */ + reg::packed(450, 0, 738), /* accepts return */ + reg::packed(721, 0, 27), /* isSuperTypeOf $type */ + reg::packed(450, 0, 773), /* isSuperTypeOf return */ + reg::packed(721, 0, 27), /* isSuperTypeOfInternal $type */ + reg::packed(820, MAY_BE_BOOL), /* isSuperTypeOfInternal $treatMixedAsAny */ + reg::packed(726, MAY_BE_BOOL, reg::NoString, false, false, 54), /* isSuperTypeOfInternal $strictTypes */ + reg::packed(450, 0, 773), /* isSuperTypeOfInternal return */ + reg::packed(721, 0, 27), /* equals $type */ + reg::packed(450, MAY_BE_BOOL), /* equals return */ + reg::packed(865, 0, 478), /* hasEqualOrigins $a */ + reg::packed(867, 0, 478), /* hasEqualOrigins $b */ + reg::packed(450, MAY_BE_BOOL), /* hasEqualOrigins return */ + reg::packed(885, 0, 478), /* hasEqualUnresolvedSignature $other */ + reg::packed(450, MAY_BE_BOOL), /* hasEqualUnresolvedSignature return */ + reg::packed(919, 0, 925), /* describe $level */ + reg::packed(450, MAY_BE_STRING), /* describe return */ + reg::packed(450, MAY_BE_STRING), /* describeCallable return */ + reg::packed(450, 0, 300), /* isOffsetAccessLegal return */ + reg::packed(450, 0, 300), /* isObject return */ + reg::packed(450, 0, 27), /* getClassStringType return */ + reg::packed(450, 0, 300), /* isEnum return */ + reg::packed(1034, MAY_BE_STRING), /* getTemplateType $ancestorClassName */ + reg::packed(1052, MAY_BE_STRING), /* getTemplateType $templateTypeName */ + reg::packed(450, 0, 27), /* getTemplateType return */ + reg::packed(450, 0, 300), /* canAccessProperties return */ + reg::packed(1105, MAY_BE_STRING), /* hasProperty $propertyName */ + reg::packed(450, 0, 300), /* hasProperty return */ + reg::packed(1105, MAY_BE_STRING), /* getProperty $propertyName */ + reg::packed(1130, 0, 1136), /* getProperty $scope */ + reg::packed(450, 0, 1181), /* getProperty return */ + reg::packed(1105, MAY_BE_STRING), /* getUnresolvedPropertyPrototype $propertyName */ + reg::packed(1130, 0, 1136), /* getUnresolvedPropertyPrototype $scope */ + reg::packed(450, 0, 1239), /* getUnresolvedPropertyPrototype return */ + reg::packed(1105, MAY_BE_STRING), /* hasInstanceProperty $propertyName */ + reg::packed(450, 0, 300), /* hasInstanceProperty return */ + reg::packed(1105, MAY_BE_STRING), /* getInstanceProperty $propertyName */ + reg::packed(1130, 0, 1136), /* getInstanceProperty $scope */ + reg::packed(450, 0, 1181), /* getInstanceProperty return */ + reg::packed(1105, MAY_BE_STRING), /* getUnresolvedInstancePropertyPrototype $propertyName */ + reg::packed(1130, 0, 1136), /* getUnresolvedInstancePropertyPrototype $scope */ + reg::packed(450, 0, 1239), /* getUnresolvedInstancePropertyPrototype return */ + reg::packed(1105, MAY_BE_STRING), /* hasStaticProperty $propertyName */ + reg::packed(450, 0, 300), /* hasStaticProperty return */ + reg::packed(1105, MAY_BE_STRING), /* getStaticProperty $propertyName */ + reg::packed(1130, 0, 1136), /* getStaticProperty $scope */ + reg::packed(450, 0, 1181), /* getStaticProperty return */ + reg::packed(1105, MAY_BE_STRING), /* getUnresolvedStaticPropertyPrototype $propertyName */ + reg::packed(1130, 0, 1136), /* getUnresolvedStaticPropertyPrototype $scope */ + reg::packed(450, 0, 1239), /* getUnresolvedStaticPropertyPrototype return */ + reg::packed(450, 0, 300), /* canCallMethods return */ + reg::packed(1499, MAY_BE_STRING), /* hasMethod $methodName */ + reg::packed(450, 0, 300), /* hasMethod return */ + reg::packed(1499, MAY_BE_STRING), /* getMethod $methodName */ + reg::packed(1130, 0, 1136), /* getMethod $scope */ + reg::packed(450, 0, 1520), /* getMethod return */ + reg::packed(1499, MAY_BE_STRING), /* getUnresolvedMethodPrototype $methodName */ + reg::packed(1130, 0, 1136), /* getUnresolvedMethodPrototype $scope */ + reg::packed(450, 0, 1574), /* getUnresolvedMethodPrototype return */ + reg::packed(450, 0, 300), /* canAccessConstants return */ + reg::packed(1682, MAY_BE_STRING), /* hasConstant $constantName */ + reg::packed(450, 0, 300), /* hasConstant return */ + reg::packed(1682, MAY_BE_STRING), /* getConstant $constantName */ + reg::packed(450, 0, 1707), /* getConstant return */ + reg::packed(450, MAY_BE_ARRAY), /* getConstantStrings return */ + reg::packed(450, 0, 300), /* isIterable return */ + reg::packed(450, 0, 300), /* isIterableAtLeastOnce return */ + reg::packed(450, 0, 300), /* isCallable return */ + reg::packed(450, MAY_BE_ARRAY), /* getEnumCases return */ + reg::packed(450, MAY_BE_NULL, 1838), /* getEnumCaseObject return */ + reg::packed(450, MAY_BE_BOOL), /* isCommonCallable return */ + reg::packed(1130, 0, 1136), /* getCallableParametersAcceptors $scope */ + reg::packed(450, MAY_BE_ARRAY), /* getCallableParametersAcceptors return */ + reg::packed(450, MAY_BE_ARRAY), /* getThrowPoints return */ + reg::packed(450, MAY_BE_ARRAY), /* getImpurePoints return */ + reg::packed(450, MAY_BE_ARRAY), /* getInvalidateExpressions return */ + reg::packed(450, MAY_BE_ARRAY), /* getUsedVariables return */ + reg::packed(450, MAY_BE_ARRAY), /* getByRefUseTypes return */ + reg::packed(450, MAY_BE_NULL, 411), /* getOrigin return */ + reg::packed(450, MAY_BE_BOOL), /* containsUnresolvedTemplateArgument return */ + reg::packed(450, 0, 300), /* acceptsNamedArguments return */ + reg::packed(450, 0, 300), /* mustUseReturnValue return */ + reg::packed(450, 0, 300), /* isStaticClosure return */ + reg::packed(450, 0, 300), /* isCloneable return */ + reg::packed(450, 0, 2104), /* toBoolean return */ + reg::packed(450, 0, 27), /* toNumber return */ + reg::packed(450, 0, 27), /* toBitwiseNotType return */ + reg::packed(450, 0, 27), /* toGetClassResultType return */ + reg::packed(2186, 0, 2205), /* toClassConstantType $reflectionProvider */ + reg::packed(450, 0, 27), /* toClassConstantType return */ + reg::packed(450, 0, 2263), /* toObjectTypeForInstanceofCheck return */ + reg::packed(2335, 0, 27), /* toObjectTypeForIsACheck $objectOrClassType */ + reg::packed(2353, MAY_BE_BOOL), /* toObjectTypeForIsACheck $allowString */ + reg::packed(2365, MAY_BE_BOOL), /* toObjectTypeForIsACheck $allowSameClass */ + reg::packed(450, 0, 2263), /* toObjectTypeForIsACheck return */ + reg::packed(450, 0, 27), /* toAbsoluteNumber return */ + reg::packed(450, 0, 27), /* toInteger return */ + reg::packed(450, 0, 27), /* toFloat return */ + reg::packed(450, 0, 27), /* toString return */ + reg::packed(450, 0, 27), /* toArray return */ + reg::packed(450, 0, 27), /* toArrayKey return */ + reg::packed(726, MAY_BE_BOOL), /* toCoercedArgumentType $strictTypes */ + reg::packed(450, 0, 27), /* toCoercedArgumentType return */ + reg::packed(450, 0, 75), /* getTemplateTypeMap return */ + reg::packed(450, 0, 75), /* getResolvedTemplateTypeMap return */ + reg::packed(450, 0, 156), /* getCallSiteVarianceMap return */ + reg::packed(450, MAY_BE_ARRAY), /* getParameters return */ + reg::packed(450, MAY_BE_BOOL), /* isVariadic return */ + reg::packed(450, 0, 27), /* getReturnType return */ + reg::packed(2597, 0, 27), /* inferTemplateTypes $receivedType */ + reg::packed(450, 0, 75), /* inferTemplateTypes return */ + reg::packed(2629, 0, 2648), /* inferTemplateTypesOnParametersAcceptor $parametersAcceptor */ + reg::packed(450, 0, 75), /* inferTemplateTypesOnParametersAcceptor return */ + reg::packed(2725, 0, 2742), /* getReferencedTemplateTypes $positionVariance */ + reg::packed(450, MAY_BE_ARRAY), /* getReferencedTemplateTypes return */ + reg::packed(2811, MAY_BE_CALLABLE), /* traverse $cb */ + reg::packed(450, 0, 27), /* traverse return */ + reg::packed(2823, 0, 27), /* traverseSimultaneously $right */ + reg::packed(2811, MAY_BE_CALLABLE), /* traverseSimultaneously $cb */ + reg::packed(450, 0, 27), /* traverseSimultaneously return */ + reg::packed(450, 0, 300), /* isNull return */ + reg::packed(450, 0, 300), /* isConstantValue return */ + reg::packed(450, 0, 300), /* isConstantScalarValue return */ + reg::packed(450, MAY_BE_ARRAY), /* getConstantScalarTypes return */ + reg::packed(450, MAY_BE_ARRAY), /* getConstantScalarValues return */ + reg::packed(450, 0, 300), /* isTrue return */ + reg::packed(450, 0, 300), /* isFalse return */ + reg::packed(450, 0, 300), /* isBoolean return */ + reg::packed(450, 0, 300), /* isFloat return */ + reg::packed(450, 0, 300), /* isInteger return */ + reg::packed(450, 0, 300), /* isString return */ + reg::packed(450, 0, 300), /* isNumericString return */ + reg::packed(450, 0, 300), /* isDecimalIntegerString return */ + reg::packed(450, 0, 300), /* isNonEmptyString return */ + reg::packed(450, 0, 300), /* isNonFalsyString return */ + reg::packed(450, 0, 300), /* isLiteralString return */ + reg::packed(450, 0, 300), /* isLowercaseString return */ + reg::packed(450, 0, 300), /* isClassString return */ + reg::packed(450, 0, 300), /* isUppercaseString return */ + reg::packed(450, 0, 27), /* getClassStringObjectType return */ + reg::packed(450, 0, 27), /* getObjectTypeOrClassStringObjectType return */ + reg::packed(450, 0, 300), /* isVoid return */ + reg::packed(450, 0, 300), /* isScalar return */ + reg::packed(721, 0, 27), /* looseCompare $type */ + reg::packed(3213, 0, 3224), /* looseCompare $phpVersion */ + reg::packed(450, 0, 2104), /* looseCompare return */ + reg::packed(3260, 0, 27), /* arithmeticPower $exponent */ + reg::packed(3213, 0, 3224), /* arithmeticPower $phpVersion */ + reg::packed(450, 0, 27), /* arithmeticPower return */ + reg::packed(450, MAY_BE_ARRAY), /* getFiniteTypes return */ + reg::packed(450, 0, 3300), /* toPhpDocNode return */ + reg::packed(3352, 0, 3361), /* toNativePhpTypeNode $position */ + reg::packed(450, MAY_BE_BOOL), /* hasTemplateOrLateResolvableType return */ + reg::packed(450, 0, 3445), /* toValueSet return */ }; using Sig = reg::Sig; } // namespace sigtab /* the signatures of the methods the class declares itself (a used trait's are in the trait's header) */ namespace sig { -inline constexpr sigtab::Sig __construct = { { 404 /* __construct */, 0, 0, 16, reg::NoArg, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getAsserts = { { 417 /* getAsserts */, 0, 16, 0, 16, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getTemplateTags = { { 428 /* getTemplateTags */, 0, 17, 0, 17, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig createPure = { { 469 /* createPure */, 0, 18, 0, 18, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC } }; -inline constexpr sigtab::Sig isPure = { { 480 /* isPure */, 0, 19, 0, 19, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getClassName = { { 487 /* getClassName */, 0, 20, 0, 20, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getClassReflection = { { 535 /* getClassReflection */, 0, 21, 0, 21, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getAncestorWithClassName = { { 595 /* getAncestorWithClassName */, 1, 22, 1, 23, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getReferencedClasses = { { 620 /* getReferencedClasses */, 0, 24, 0, 24, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getObjectClassNames = { { 641 /* getObjectClassNames */, 0, 25, 0, 25, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getObjectClassReflections = { { 661 /* getObjectClassReflections */, 0, 26, 0, 26, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig accepts = { { 731 /* accepts */, 2, 27, 2, 29, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isSuperTypeOf = { { 772 /* isSuperTypeOf */, 1, 30, 1, 31, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isSuperTypeOfInternal = { { 802 /* isSuperTypeOfInternal */, 2, 32, 3, 35, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig equals = { { 824 /* equals */, 1, 36, 1, 37, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasEqualUnresolvedSignature = { { 837 /* hasEqualUnresolvedSignature */, 1, 38, 1, 39, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig describe = { { 899 /* describe */, 1, 40, 1, 41, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig describeCallable = { { 908 /* describeCallable */, 0, 42, 0, 42, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig isOffsetAccessLegal = { { 925 /* isOffsetAccessLegal */, 0, 43, 0, 43, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isObject = { { 945 /* isObject */, 0, 44, 0, 44, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getClassStringType = { { 954 /* getClassStringType */, 0, 45, 0, 45, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isEnum = { { 973 /* isEnum */, 0, 46, 0, 46, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getTemplateType = { { 1015 /* getTemplateType */, 2, 47, 2, 49, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig canAccessProperties = { { 1031 /* canAccessProperties */, 0, 50, 0, 50, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasProperty = { { 1064 /* hasProperty */, 1, 51, 1, 52, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getProperty = { { 1173 /* getProperty */, 2, 53, 2, 55, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnresolvedPropertyPrototype = { { 1247 /* getUnresolvedPropertyPrototype */, 2, 56, 2, 58, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasInstanceProperty = { { 1278 /* hasInstanceProperty */, 1, 59, 1, 60, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getInstanceProperty = { { 1298 /* getInstanceProperty */, 2, 61, 2, 63, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnresolvedInstancePropertyPrototype = { { 1318 /* getUnresolvedInstancePropertyPrototype */, 2, 64, 2, 66, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasStaticProperty = { { 1357 /* hasStaticProperty */, 1, 67, 1, 68, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getStaticProperty = { { 1375 /* getStaticProperty */, 2, 69, 2, 71, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnresolvedStaticPropertyPrototype = { { 1393 /* getUnresolvedStaticPropertyPrototype */, 2, 72, 2, 74, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig canCallMethods = { { 1430 /* canCallMethods */, 0, 75, 0, 75, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasMethod = { { 1456 /* hasMethod */, 1, 76, 1, 77, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getMethod = { { 1510 /* getMethod */, 2, 78, 2, 80, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnresolvedMethodPrototype = { { 1580 /* getUnresolvedMethodPrototype */, 2, 81, 2, 83, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig canAccessConstants = { { 1609 /* canAccessConstants */, 0, 84, 0, 84, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasConstant = { { 1641 /* hasConstant */, 1, 85, 1, 86, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getConstant = { { 1696 /* getConstant */, 1, 87, 1, 88, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getConstantStrings = { { 1708 /* getConstantStrings */, 0, 89, 0, 89, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isIterable = { { 1727 /* isIterable */, 0, 90, 0, 90, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isIterableAtLeastOnce = { { 1738 /* isIterableAtLeastOnce */, 0, 91, 0, 91, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isCallable = { { 1760 /* isCallable */, 0, 92, 0, 92, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getEnumCases = { { 1771 /* getEnumCases */, 0, 93, 0, 93, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getEnumCaseObject = { { 1821 /* getEnumCaseObject */, 0, 94, 0, 94, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isCommonCallable = { { 1839 /* isCommonCallable */, 0, 95, 0, 95, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getCallableParametersAcceptors = { { 1856 /* getCallableParametersAcceptors */, 1, 96, 1, 97, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getThrowPoints = { { 1887 /* getThrowPoints */, 0, 98, 0, 98, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getImpurePoints = { { 1902 /* getImpurePoints */, 0, 99, 0, 99, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getInvalidateExpressions = { { 1918 /* getInvalidateExpressions */, 0, 100, 0, 100, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUsedVariables = { { 1943 /* getUsedVariables */, 0, 101, 0, 101, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getByRefUseTypes = { { 1960 /* getByRefUseTypes */, 0, 102, 0, 102, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig containsUnresolvedTemplateArgument = { { 1977 /* containsUnresolvedTemplateArgument */, 0, 103, 0, 103, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig acceptsNamedArguments = { { 278 /* acceptsNamedArguments */, 0, 104, 0, 104, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig mustUseReturnValue = { { 321 /* mustUseReturnValue */, 0, 105, 0, 105, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isStaticClosure = { { 2012 /* isStaticClosure */, 0, 106, 0, 106, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isCloneable = { { 2028 /* isCloneable */, 0, 107, 0, 107, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toBoolean = { { 2065 /* toBoolean */, 0, 108, 0, 108, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toNumber = { { 2075 /* toNumber */, 0, 109, 0, 109, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toBitwiseNotType = { { 2084 /* toBitwiseNotType */, 0, 110, 0, 110, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toGetClassResultType = { { 2101 /* toGetClassResultType */, 0, 111, 0, 111, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toClassConstantType = { { 2179 /* toClassConstantType */, 1, 112, 1, 113, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toObjectTypeForInstanceofCheck = { { 2240 /* toObjectTypeForInstanceofCheck */, 0, 114, 0, 114, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toObjectTypeForIsACheck = { { 2316 /* toObjectTypeForIsACheck */, 3, 115, 3, 118, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toAbsoluteNumber = { { 2340 /* toAbsoluteNumber */, 0, 119, 0, 119, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toInteger = { { 2357 /* toInteger */, 0, 120, 0, 120, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toFloat = { { 2367 /* toFloat */, 0, 121, 0, 121, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toString = { { 2375 /* toString */, 0, 122, 0, 122, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toArray = { { 2384 /* toArray */, 0, 123, 0, 123, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toArrayKey = { { 2392 /* toArrayKey */, 0, 124, 0, 124, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toCoercedArgumentType = { { 2403 /* toCoercedArgumentType */, 1, 125, 1, 126, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getTemplateTypeMap = { { 2425 /* getTemplateTypeMap */, 0, 127, 0, 127, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getResolvedTemplateTypeMap = { { 2444 /* getResolvedTemplateTypeMap */, 0, 128, 0, 128, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getCallSiteVarianceMap = { { 2471 /* getCallSiteVarianceMap */, 0, 129, 0, 129, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getParameters = { { 2494 /* getParameters */, 0, 130, 0, 130, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isVariadic = { { 2508 /* isVariadic */, 0, 131, 0, 131, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getReturnType = { { 2519 /* getReturnType */, 0, 132, 0, 132, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig inferTemplateTypes = { { 2546 /* inferTemplateTypes */, 1, 133, 1, 134, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig inferTemplateTypesOnParametersAcceptor = { { 2622 /* inferTemplateTypesOnParametersAcceptor */, 1, 135, 1, 136, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getReferencedTemplateTypes = { { 2720 /* getReferencedTemplateTypes */, 1, 137, 1, 138, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig traverse = { { 2750 /* traverse */, 1, 139, 1, 140, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig traverseSimultaneously = { { 2765 /* traverseSimultaneously */, 2, 141, 2, 143, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNull = { { 2788 /* isNull */, 0, 144, 0, 144, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isConstantValue = { { 2795 /* isConstantValue */, 0, 145, 0, 145, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isConstantScalarValue = { { 2811 /* isConstantScalarValue */, 0, 146, 0, 146, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getConstantScalarTypes = { { 2833 /* getConstantScalarTypes */, 0, 147, 0, 147, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getConstantScalarValues = { { 2856 /* getConstantScalarValues */, 0, 148, 0, 148, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isTrue = { { 2880 /* isTrue */, 0, 149, 0, 149, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isFalse = { { 2887 /* isFalse */, 0, 150, 0, 150, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isBoolean = { { 2895 /* isBoolean */, 0, 151, 0, 151, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isFloat = { { 2905 /* isFloat */, 0, 152, 0, 152, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isInteger = { { 2913 /* isInteger */, 0, 153, 0, 153, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isString = { { 2923 /* isString */, 0, 154, 0, 154, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNumericString = { { 2932 /* isNumericString */, 0, 155, 0, 155, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isDecimalIntegerString = { { 2948 /* isDecimalIntegerString */, 0, 156, 0, 156, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNonEmptyString = { { 2971 /* isNonEmptyString */, 0, 157, 0, 157, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNonFalsyString = { { 2988 /* isNonFalsyString */, 0, 158, 0, 158, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isLiteralString = { { 3005 /* isLiteralString */, 0, 159, 0, 159, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isLowercaseString = { { 3021 /* isLowercaseString */, 0, 160, 0, 160, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isClassString = { { 3039 /* isClassString */, 0, 161, 0, 161, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isUppercaseString = { { 3053 /* isUppercaseString */, 0, 162, 0, 162, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getClassStringObjectType = { { 3071 /* getClassStringObjectType */, 0, 163, 0, 163, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getObjectTypeOrClassStringObjectType = { { 3096 /* getObjectTypeOrClassStringObjectType */, 0, 164, 0, 164, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isVoid = { { 3133 /* isVoid */, 0, 165, 0, 165, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isScalar = { { 3140 /* isScalar */, 0, 166, 0, 166, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig looseCompare = { { 3183 /* looseCompare */, 2, 167, 2, 169, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig arithmeticPower = { { 3205 /* arithmeticPower */, 2, 170, 2, 172, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getFiniteTypes = { { 3221 /* getFiniteTypes */, 0, 173, 0, 173, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toPhpDocNode = { { 3275 /* toPhpDocNode */, 0, 174, 0, 174, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toNativePhpTypeNode = { { 3329 /* toNativePhpTypeNode */, 1, 175, 1, reg::NoArg, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasTemplateOrLateResolvableType = { { 3349 /* hasTemplateOrLateResolvableType */, 0, 176, 0, 176, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toValueSet = { { 3403 /* toValueSet */, 0, 177, 0, 177, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig __construct = { { 438 /* __construct */, 0, 0, 17, reg::NoArg, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getAsserts = { { 451 /* getAsserts */, 0, 17, 0, 17, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getTemplateTags = { { 462 /* getTemplateTags */, 0, 18, 0, 18, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig createPure = { { 503 /* createPure */, 0, 19, 0, 19, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC } }; +inline constexpr sigtab::Sig isPure = { { 514 /* isPure */, 0, 20, 0, 20, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getClassName = { { 521 /* getClassName */, 0, 21, 0, 21, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getClassReflection = { { 569 /* getClassReflection */, 0, 22, 0, 22, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getAncestorWithClassName = { { 629 /* getAncestorWithClassName */, 1, 23, 1, 24, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getReferencedClasses = { { 654 /* getReferencedClasses */, 0, 25, 0, 25, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getObjectClassNames = { { 675 /* getObjectClassNames */, 0, 26, 0, 26, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getObjectClassReflections = { { 695 /* getObjectClassReflections */, 0, 27, 0, 27, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig accepts = { { 765 /* accepts */, 2, 28, 2, 30, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isSuperTypeOf = { { 806 /* isSuperTypeOf */, 1, 31, 1, 32, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isSuperTypeOfInternal = { { 836 /* isSuperTypeOfInternal */, 2, 33, 3, 36, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig equals = { { 858 /* equals */, 1, 37, 1, 38, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasEqualOrigins = { { 869 /* hasEqualOrigins */, 2, 39, 2, 41, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; +inline constexpr sigtab::Sig hasEqualUnresolvedSignature = { { 891 /* hasEqualUnresolvedSignature */, 1, 42, 1, 43, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig describe = { { 953 /* describe */, 1, 44, 1, 45, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig describeCallable = { { 962 /* describeCallable */, 0, 46, 0, 46, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig isOffsetAccessLegal = { { 979 /* isOffsetAccessLegal */, 0, 47, 0, 47, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isObject = { { 999 /* isObject */, 0, 48, 0, 48, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getClassStringType = { { 1008 /* getClassStringType */, 0, 49, 0, 49, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isEnum = { { 1027 /* isEnum */, 0, 50, 0, 50, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getTemplateType = { { 1069 /* getTemplateType */, 2, 51, 2, 53, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig canAccessProperties = { { 1085 /* canAccessProperties */, 0, 54, 0, 54, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasProperty = { { 1118 /* hasProperty */, 1, 55, 1, 56, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getProperty = { { 1227 /* getProperty */, 2, 57, 2, 59, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnresolvedPropertyPrototype = { { 1301 /* getUnresolvedPropertyPrototype */, 2, 60, 2, 62, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasInstanceProperty = { { 1332 /* hasInstanceProperty */, 1, 63, 1, 64, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getInstanceProperty = { { 1352 /* getInstanceProperty */, 2, 65, 2, 67, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnresolvedInstancePropertyPrototype = { { 1372 /* getUnresolvedInstancePropertyPrototype */, 2, 68, 2, 70, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasStaticProperty = { { 1411 /* hasStaticProperty */, 1, 71, 1, 72, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getStaticProperty = { { 1429 /* getStaticProperty */, 2, 73, 2, 75, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnresolvedStaticPropertyPrototype = { { 1447 /* getUnresolvedStaticPropertyPrototype */, 2, 76, 2, 78, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig canCallMethods = { { 1484 /* canCallMethods */, 0, 79, 0, 79, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasMethod = { { 1510 /* hasMethod */, 1, 80, 1, 81, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getMethod = { { 1564 /* getMethod */, 2, 82, 2, 84, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnresolvedMethodPrototype = { { 1634 /* getUnresolvedMethodPrototype */, 2, 85, 2, 87, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig canAccessConstants = { { 1663 /* canAccessConstants */, 0, 88, 0, 88, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasConstant = { { 1695 /* hasConstant */, 1, 89, 1, 90, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getConstant = { { 1750 /* getConstant */, 1, 91, 1, 92, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getConstantStrings = { { 1762 /* getConstantStrings */, 0, 93, 0, 93, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isIterable = { { 1781 /* isIterable */, 0, 94, 0, 94, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isIterableAtLeastOnce = { { 1792 /* isIterableAtLeastOnce */, 0, 95, 0, 95, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isCallable = { { 1814 /* isCallable */, 0, 96, 0, 96, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getEnumCases = { { 1825 /* getEnumCases */, 0, 97, 0, 97, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getEnumCaseObject = { { 1875 /* getEnumCaseObject */, 0, 98, 0, 98, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isCommonCallable = { { 1893 /* isCommonCallable */, 0, 99, 0, 99, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getCallableParametersAcceptors = { { 1910 /* getCallableParametersAcceptors */, 1, 100, 1, 101, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getThrowPoints = { { 1941 /* getThrowPoints */, 0, 102, 0, 102, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getImpurePoints = { { 1956 /* getImpurePoints */, 0, 103, 0, 103, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getInvalidateExpressions = { { 1972 /* getInvalidateExpressions */, 0, 104, 0, 104, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUsedVariables = { { 1997 /* getUsedVariables */, 0, 105, 0, 105, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getByRefUseTypes = { { 2014 /* getByRefUseTypes */, 0, 106, 0, 106, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getOrigin = { { 2031 /* getOrigin */, 0, 107, 0, 107, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig containsUnresolvedTemplateArgument = { { 2041 /* containsUnresolvedTemplateArgument */, 0, 108, 0, 108, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig acceptsNamedArguments = { { 278 /* acceptsNamedArguments */, 0, 109, 0, 109, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig mustUseReturnValue = { { 321 /* mustUseReturnValue */, 0, 110, 0, 110, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isStaticClosure = { { 2076 /* isStaticClosure */, 0, 111, 0, 111, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isCloneable = { { 2092 /* isCloneable */, 0, 112, 0, 112, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toBoolean = { { 2129 /* toBoolean */, 0, 113, 0, 113, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toNumber = { { 2139 /* toNumber */, 0, 114, 0, 114, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toBitwiseNotType = { { 2148 /* toBitwiseNotType */, 0, 115, 0, 115, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toGetClassResultType = { { 2165 /* toGetClassResultType */, 0, 116, 0, 116, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toClassConstantType = { { 2243 /* toClassConstantType */, 1, 117, 1, 118, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toObjectTypeForInstanceofCheck = { { 2304 /* toObjectTypeForInstanceofCheck */, 0, 119, 0, 119, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toObjectTypeForIsACheck = { { 2380 /* toObjectTypeForIsACheck */, 3, 120, 3, 123, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toAbsoluteNumber = { { 2404 /* toAbsoluteNumber */, 0, 124, 0, 124, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toInteger = { { 2421 /* toInteger */, 0, 125, 0, 125, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toFloat = { { 2431 /* toFloat */, 0, 126, 0, 126, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toString = { { 2439 /* toString */, 0, 127, 0, 127, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toArray = { { 2448 /* toArray */, 0, 128, 0, 128, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toArrayKey = { { 2456 /* toArrayKey */, 0, 129, 0, 129, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toCoercedArgumentType = { { 2467 /* toCoercedArgumentType */, 1, 130, 1, 131, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getTemplateTypeMap = { { 2489 /* getTemplateTypeMap */, 0, 132, 0, 132, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getResolvedTemplateTypeMap = { { 2508 /* getResolvedTemplateTypeMap */, 0, 133, 0, 133, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getCallSiteVarianceMap = { { 2535 /* getCallSiteVarianceMap */, 0, 134, 0, 134, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getParameters = { { 2558 /* getParameters */, 0, 135, 0, 135, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isVariadic = { { 2572 /* isVariadic */, 0, 136, 0, 136, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getReturnType = { { 2583 /* getReturnType */, 0, 137, 0, 137, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig inferTemplateTypes = { { 2610 /* inferTemplateTypes */, 1, 138, 1, 139, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig inferTemplateTypesOnParametersAcceptor = { { 2686 /* inferTemplateTypesOnParametersAcceptor */, 1, 140, 1, 141, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getReferencedTemplateTypes = { { 2784 /* getReferencedTemplateTypes */, 1, 142, 1, 143, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig traverse = { { 2814 /* traverse */, 1, 144, 1, 145, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig traverseSimultaneously = { { 2829 /* traverseSimultaneously */, 2, 146, 2, 148, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNull = { { 2852 /* isNull */, 0, 149, 0, 149, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isConstantValue = { { 2859 /* isConstantValue */, 0, 150, 0, 150, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isConstantScalarValue = { { 2875 /* isConstantScalarValue */, 0, 151, 0, 151, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getConstantScalarTypes = { { 2897 /* getConstantScalarTypes */, 0, 152, 0, 152, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getConstantScalarValues = { { 2920 /* getConstantScalarValues */, 0, 153, 0, 153, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isTrue = { { 2944 /* isTrue */, 0, 154, 0, 154, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isFalse = { { 2951 /* isFalse */, 0, 155, 0, 155, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isBoolean = { { 2959 /* isBoolean */, 0, 156, 0, 156, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isFloat = { { 2969 /* isFloat */, 0, 157, 0, 157, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isInteger = { { 2977 /* isInteger */, 0, 158, 0, 158, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isString = { { 2987 /* isString */, 0, 159, 0, 159, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNumericString = { { 2996 /* isNumericString */, 0, 160, 0, 160, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isDecimalIntegerString = { { 3012 /* isDecimalIntegerString */, 0, 161, 0, 161, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNonEmptyString = { { 3035 /* isNonEmptyString */, 0, 162, 0, 162, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNonFalsyString = { { 3052 /* isNonFalsyString */, 0, 163, 0, 163, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isLiteralString = { { 3069 /* isLiteralString */, 0, 164, 0, 164, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isLowercaseString = { { 3085 /* isLowercaseString */, 0, 165, 0, 165, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isClassString = { { 3103 /* isClassString */, 0, 166, 0, 166, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isUppercaseString = { { 3117 /* isUppercaseString */, 0, 167, 0, 167, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getClassStringObjectType = { { 3135 /* getClassStringObjectType */, 0, 168, 0, 168, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getObjectTypeOrClassStringObjectType = { { 3160 /* getObjectTypeOrClassStringObjectType */, 0, 169, 0, 169, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isVoid = { { 3197 /* isVoid */, 0, 170, 0, 170, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isScalar = { { 3204 /* isScalar */, 0, 171, 0, 171, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig looseCompare = { { 3247 /* looseCompare */, 2, 172, 2, 174, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig arithmeticPower = { { 3269 /* arithmeticPower */, 2, 175, 2, 177, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getFiniteTypes = { { 3285 /* getFiniteTypes */, 0, 178, 0, 178, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toPhpDocNode = { { 3339 /* toPhpDocNode */, 0, 179, 0, 179, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toNativePhpTypeNode = { { 3393 /* toNativePhpTypeNode */, 1, 180, 1, reg::NoArg, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasTemplateOrLateResolvableType = { { 3413 /* hasTemplateOrLateResolvableType */, 0, 181, 0, 181, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toValueSet = { { 3467 /* toValueSet */, 0, 182, 0, 182, ZEND_ACC_PUBLIC } }; } // namespace sig } // namespace ptdecl::ClosureType diff --git a/turbo-ext/src/generated/InitializerExprTypeResolver.h b/turbo-ext/src/generated/InitializerExprTypeResolver.h index e4ecd71a20f..1c17629aeca 100644 --- a/turbo-ext/src/generated/InitializerExprTypeResolver.h +++ b/turbo-ext/src/generated/InitializerExprTypeResolver.h @@ -102,57 +102,59 @@ inline constexpr char strings[] = "variants\0" /* 1186 */ "partialApplicationArgs\0" /* 1195 */ "[]\0" /* 1218 */ - "createFirstClassCallable\0" /* 1221 */ - "parameters\0" /* 1246 */ - "names\0" /* 1257 */ - "renameParameters\0" /* 1263 */ - "getBitwiseAndType\0" /* 1280 */ - "getBitwiseOrType\0" /* 1298 */ - "getBitwiseXorType\0" /* 1315 */ - "getSpaceshipType\0" /* 1333 */ - "getDivType\0" /* 1350 */ - "getModType\0" /* 1361 */ - "getPlusType\0" /* 1372 */ - "getMinusType\0" /* 1384 */ - "getMulType\0" /* 1397 */ - "getPowType\0" /* 1408 */ - "getShiftLeftType\0" /* 1419 */ - "getShiftRightType\0" /* 1436 */ - "leftType\0" /* 1454 */ - "rightType\0" /* 1463 */ - "PHPStan\\Type\\TypeResult\0" /* 1473 */ - "resolveIdenticalType\0" /* 1497 */ - "resolveEqualType\0" /* 1518 */ - "isNonNumericString\0" /* 1535 */ - "PHPStan\\Type\\Constant\\ConstantArrayType\0" /* 1554 */ - "valueComparisonCallback\0" /* 1594 */ - "resolveConstantArrayTypeComparison\0" /* 1618 */ - "class\0" /* 1653 */ - "PhpParser\\Node\\Name|PhpParser\\Node\\Expr\0" /* 1659 */ - "constantName\0" /* 1699 */ - "classReflection\0" /* 1712 */ - "PHPStan\\Reflection\\ClassReflection\0" /* 1728 */ - "false\0" /* 1763 */ - "getClassConstFetchTypeByReflection\0" /* 1769 */ - "fetchedOnType\0" /* 1804 */ - "transformStaticType\0" /* 1818 */ - "getClassConstFetchType\0" /* 1838 */ - "getUnaryPlusType\0" /* 1861 */ - "getUnaryMinusType\0" /* 1878 */ - "getBitwiseNotType\0" /* 1896 */ - "getBitwiseNotTypeFromType\0" /* 1914 */ - "name\0" /* 1940 */ - "PhpParser\\Node\\Name\0" /* 1945 */ - "resolveName\0" /* 1965 */ - "PHPStan\\Type\\TypeWithClassName\0" /* 1977 */ - "resolveTypeByName\0" /* 2008 */ - "classType\0" /* 2026 */ - "methodReflectionCandidate\0" /* 2036 */ - "PHPStan\\Reflection\\MethodReflection\0" /* 2062 */ - "resolveTypeByNameWithLateStaticBinding\0" /* 2098 */ - "PHPStan\\Reflection\\ReflectionProvider\0" /* 2137 */ - "getReflectionProvider\0" /* 2175 */ - "getNeverType"; /* 2197 */ + "origin\0" /* 1221 */ + "PHPStan\\Type\\ClosureOrigin\0" /* 1228 */ + "createFirstClassCallable\0" /* 1255 */ + "parameters\0" /* 1280 */ + "names\0" /* 1291 */ + "renameParameters\0" /* 1297 */ + "getBitwiseAndType\0" /* 1314 */ + "getBitwiseOrType\0" /* 1332 */ + "getBitwiseXorType\0" /* 1349 */ + "getSpaceshipType\0" /* 1367 */ + "getDivType\0" /* 1384 */ + "getModType\0" /* 1395 */ + "getPlusType\0" /* 1406 */ + "getMinusType\0" /* 1418 */ + "getMulType\0" /* 1431 */ + "getPowType\0" /* 1442 */ + "getShiftLeftType\0" /* 1453 */ + "getShiftRightType\0" /* 1470 */ + "leftType\0" /* 1488 */ + "rightType\0" /* 1497 */ + "PHPStan\\Type\\TypeResult\0" /* 1507 */ + "resolveIdenticalType\0" /* 1531 */ + "resolveEqualType\0" /* 1552 */ + "isNonNumericString\0" /* 1569 */ + "PHPStan\\Type\\Constant\\ConstantArrayType\0" /* 1588 */ + "valueComparisonCallback\0" /* 1628 */ + "resolveConstantArrayTypeComparison\0" /* 1652 */ + "class\0" /* 1687 */ + "PhpParser\\Node\\Name|PhpParser\\Node\\Expr\0" /* 1693 */ + "constantName\0" /* 1733 */ + "classReflection\0" /* 1746 */ + "PHPStan\\Reflection\\ClassReflection\0" /* 1762 */ + "false\0" /* 1797 */ + "getClassConstFetchTypeByReflection\0" /* 1803 */ + "fetchedOnType\0" /* 1838 */ + "transformStaticType\0" /* 1852 */ + "getClassConstFetchType\0" /* 1872 */ + "getUnaryPlusType\0" /* 1895 */ + "getUnaryMinusType\0" /* 1912 */ + "getBitwiseNotType\0" /* 1930 */ + "getBitwiseNotTypeFromType\0" /* 1948 */ + "name\0" /* 1974 */ + "PhpParser\\Node\\Name\0" /* 1979 */ + "resolveName\0" /* 1999 */ + "PHPStan\\Type\\TypeWithClassName\0" /* 2011 */ + "resolveTypeByName\0" /* 2042 */ + "classType\0" /* 2060 */ + "methodReflectionCandidate\0" /* 2070 */ + "PHPStan\\Reflection\\MethodReflection\0" /* 2096 */ + "resolveTypeByNameWithLateStaticBinding\0" /* 2132 */ + "PHPStan\\Reflection\\ReflectionProvider\0" /* 2171 */ + "getReflectionProvider\0" /* 2209 */ + "getNeverType"; /* 2231 */ inline constexpr reg::PackedArg args[] = { reg::packed(0, 0, 17), /* __construct $constantResolver */ reg::packed(51, 0, 78), /* __construct $reflectionProviderProvider */ @@ -203,9 +205,10 @@ inline constexpr reg::PackedArg args[] = { reg::packed(1035, MAY_BE_BOOL), /* createFirstClassCallable $nativeTypesPromoted */ reg::packed(1195, MAY_BE_NULL | MAY_BE_ARRAY, reg::NoString, false, false, 825), /* createFirstClassCallable $partialApplicationArgs */ reg::packed(1055, MAY_BE_ARRAY, reg::NoString, false, false, 1218), /* createFirstClassCallable $boundArgTypes */ + reg::packed(1221, MAY_BE_NULL, 1228, false, false, 825), /* createFirstClassCallable $origin */ reg::packed(626, 0, 627), /* createFirstClassCallable return */ - reg::packed(1246, MAY_BE_ARRAY), /* renameParameters $parameters */ - reg::packed(1257, MAY_BE_ARRAY), /* renameParameters $names */ + reg::packed(1280, MAY_BE_ARRAY), /* renameParameters $parameters */ + reg::packed(1291, MAY_BE_ARRAY), /* renameParameters $names */ reg::packed(626, MAY_BE_ARRAY), /* renameParameters return */ reg::packed(703, 0, 556), /* getBitwiseAndType $left */ reg::packed(708, 0, 556), /* getBitwiseAndType $right */ @@ -255,31 +258,31 @@ inline constexpr reg::PackedArg args[] = { reg::packed(708, 0, 556), /* getShiftRightType $right */ reg::packed(714, MAY_BE_CALLABLE), /* getShiftRightType $getTypeCallback */ reg::packed(626, 0, 627), /* getShiftRightType return */ - reg::packed(1454, 0, 627), /* resolveIdenticalType $leftType */ - reg::packed(1463, 0, 627), /* resolveIdenticalType $rightType */ - reg::packed(626, 0, 1473), /* resolveIdenticalType return */ - reg::packed(1454, 0, 627), /* resolveEqualType $leftType */ - reg::packed(1463, 0, 627), /* resolveEqualType $rightType */ + reg::packed(1488, 0, 627), /* resolveIdenticalType $leftType */ + reg::packed(1497, 0, 627), /* resolveIdenticalType $rightType */ + reg::packed(626, 0, 1507), /* resolveIdenticalType return */ + reg::packed(1488, 0, 627), /* resolveEqualType $leftType */ + reg::packed(1497, 0, 627), /* resolveEqualType $rightType */ reg::packed(789, MAY_BE_NULL, 801, false, false, 825), /* resolveEqualType $phpVersions */ - reg::packed(626, 0, 1473), /* resolveEqualType return */ + reg::packed(626, 0, 1507), /* resolveEqualType return */ reg::packed(907, 0, 627), /* isNonNumericString $type */ reg::packed(789, MAY_BE_ARRAY), /* isNonNumericString $phpVersions */ reg::packed(626, MAY_BE_BOOL), /* isNonNumericString return */ - reg::packed(1454, 0, 1554), /* resolveConstantArrayTypeComparison $leftType */ - reg::packed(1463, 0, 1554), /* resolveConstantArrayTypeComparison $rightType */ - reg::packed(1594, MAY_BE_CALLABLE), /* resolveConstantArrayTypeComparison $valueComparisonCallback */ - reg::packed(626, 0, 1473), /* resolveConstantArrayTypeComparison return */ - reg::packed(1653, 0, 1659), /* getClassConstFetchTypeByReflection $class */ - reg::packed(1699, MAY_BE_STRING), /* getClassConstFetchTypeByReflection $constantName */ - reg::packed(1712, MAY_BE_NULL, 1728), /* getClassConstFetchTypeByReflection $classReflection */ + reg::packed(1488, 0, 1588), /* resolveConstantArrayTypeComparison $leftType */ + reg::packed(1497, 0, 1588), /* resolveConstantArrayTypeComparison $rightType */ + reg::packed(1628, MAY_BE_CALLABLE), /* resolveConstantArrayTypeComparison $valueComparisonCallback */ + reg::packed(626, 0, 1507), /* resolveConstantArrayTypeComparison return */ + reg::packed(1687, 0, 1693), /* getClassConstFetchTypeByReflection $class */ + reg::packed(1733, MAY_BE_STRING), /* getClassConstFetchTypeByReflection $constantName */ + reg::packed(1746, MAY_BE_NULL, 1762), /* getClassConstFetchTypeByReflection $classReflection */ reg::packed(714, MAY_BE_CALLABLE), /* getClassConstFetchTypeByReflection $getTypeCallback */ - reg::packed(1035, MAY_BE_BOOL, reg::NoString, false, false, 1763), /* getClassConstFetchTypeByReflection $nativeTypesPromoted */ + reg::packed(1035, MAY_BE_BOOL, reg::NoString, false, false, 1797), /* getClassConstFetchTypeByReflection $nativeTypesPromoted */ reg::packed(626, 0, 627), /* getClassConstFetchTypeByReflection return */ reg::packed(907, 0, 627), /* transformStaticType $type */ - reg::packed(1804, 0, 627), /* transformStaticType $fetchedOnType */ + reg::packed(1838, 0, 627), /* transformStaticType $fetchedOnType */ reg::packed(626, 0, 627), /* transformStaticType return */ - reg::packed(1653, 0, 1659), /* getClassConstFetchType $class */ - reg::packed(1699, MAY_BE_STRING), /* getClassConstFetchType $constantName */ + reg::packed(1687, 0, 1693), /* getClassConstFetchType $class */ + reg::packed(1733, MAY_BE_STRING), /* getClassConstFetchType $constantName */ reg::packed(653, MAY_BE_NULL | MAY_BE_STRING), /* getClassConstFetchType $className */ reg::packed(714, MAY_BE_CALLABLE), /* getClassConstFetchType $getTypeCallback */ reg::packed(626, 0, 627), /* getClassConstFetchType return */ @@ -294,19 +297,19 @@ inline constexpr reg::PackedArg args[] = { reg::packed(626, 0, 627), /* getBitwiseNotType return */ reg::packed(880, 0, 627), /* getBitwiseNotTypeFromType $exprType */ reg::packed(626, 0, 627), /* getBitwiseNotTypeFromType return */ - reg::packed(1940, 0, 1945), /* resolveName $name */ - reg::packed(1712, MAY_BE_NULL, 1728), /* resolveName $classReflection */ + reg::packed(1974, 0, 1979), /* resolveName $name */ + reg::packed(1746, MAY_BE_NULL, 1762), /* resolveName $classReflection */ reg::packed(626, MAY_BE_STRING), /* resolveName return */ - reg::packed(1940, 0, 1945), /* resolveTypeByName $name */ - reg::packed(1712, MAY_BE_NULL, 1728), /* resolveTypeByName $classReflection */ - reg::packed(626, 0, 1977), /* resolveTypeByName return */ - reg::packed(1653, 0, 1945), /* resolveTypeByNameWithLateStaticBinding $class */ - reg::packed(2026, 0, 627), /* resolveTypeByNameWithLateStaticBinding $classType */ - reg::packed(2036, 0, 2062), /* resolveTypeByNameWithLateStaticBinding $methodReflectionCandidate */ + reg::packed(1974, 0, 1979), /* resolveTypeByName $name */ + reg::packed(1746, MAY_BE_NULL, 1762), /* resolveTypeByName $classReflection */ + reg::packed(626, 0, 2011), /* resolveTypeByName return */ + reg::packed(1687, 0, 1979), /* resolveTypeByNameWithLateStaticBinding $class */ + reg::packed(2060, 0, 627), /* resolveTypeByNameWithLateStaticBinding $classType */ + reg::packed(2070, 0, 2096), /* resolveTypeByNameWithLateStaticBinding $methodReflectionCandidate */ reg::packed(626, 0, 627), /* resolveTypeByNameWithLateStaticBinding return */ - reg::packed(626, 0, 2137), /* getReflectionProvider return */ - reg::packed(1454, 0, 627), /* getNeverType $leftType */ - reg::packed(1463, 0, 627), /* getNeverType $rightType */ + reg::packed(626, 0, 2171), /* getReflectionProvider return */ + reg::packed(1488, 0, 627), /* getNeverType $leftType */ + reg::packed(1497, 0, 627), /* getNeverType $rightType */ reg::packed(626, 0, 627), /* getNeverType return */ }; using Sig = reg::Sig; @@ -325,36 +328,36 @@ inline constexpr sigtab::Sig getCastObjectType = { { 889 /* getCastObjectType */ inline constexpr sigtab::Sig getFunctionType = { { 934 /* getFunctionType */, 4, 32, 4, 36, ZEND_ACC_PUBLIC } }; inline constexpr sigtab::Sig isParameterValueNullable = { { 981 /* isParameterValueNullable */, 1, 37, 1, 38, ZEND_ACC_PRIVATE } }; inline constexpr sigtab::Sig getFirstClassCallableType = { { 1069 /* getFirstClassCallableType */, 3, 39, 4, 43, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig createFirstClassCallable = { { 1221 /* createFirstClassCallable */, 3, 44, 5, 49, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig renameParameters = { { 1263 /* renameParameters */, 2, 50, 2, 52, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; -inline constexpr sigtab::Sig getBitwiseAndType = { { 1280 /* getBitwiseAndType */, 3, 53, 3, 56, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseOrType = { { 1298 /* getBitwiseOrType */, 3, 57, 3, 60, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseXorType = { { 1315 /* getBitwiseXorType */, 3, 61, 3, 64, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getSpaceshipType = { { 1333 /* getSpaceshipType */, 3, 65, 3, 68, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getDivType = { { 1350 /* getDivType */, 3, 69, 3, 72, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getModType = { { 1361 /* getModType */, 3, 73, 3, 76, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getPlusType = { { 1372 /* getPlusType */, 3, 77, 3, 80, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getMinusType = { { 1384 /* getMinusType */, 3, 81, 3, 84, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getMulType = { { 1397 /* getMulType */, 3, 85, 3, 88, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getPowType = { { 1408 /* getPowType */, 3, 89, 3, 92, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getShiftLeftType = { { 1419 /* getShiftLeftType */, 3, 93, 3, 96, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getShiftRightType = { { 1436 /* getShiftRightType */, 3, 97, 3, 100, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig resolveIdenticalType = { { 1497 /* resolveIdenticalType */, 2, 101, 2, 103, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig resolveEqualType = { { 1518 /* resolveEqualType */, 2, 104, 3, 107, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNonNumericString = { { 1535 /* isNonNumericString */, 2, 108, 2, 110, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; -inline constexpr sigtab::Sig resolveConstantArrayTypeComparison = { { 1618 /* resolveConstantArrayTypeComparison */, 3, 111, 3, 114, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getClassConstFetchTypeByReflection = { { 1769 /* getClassConstFetchTypeByReflection */, 4, 115, 5, 120, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig transformStaticType = { { 1818 /* transformStaticType */, 2, 121, 2, 123, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getClassConstFetchType = { { 1838 /* getClassConstFetchType */, 4, 124, 4, 128, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnaryPlusType = { { 1861 /* getUnaryPlusType */, 2, 129, 2, 131, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnaryMinusType = { { 1878 /* getUnaryMinusType */, 2, 132, 2, 134, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseNotType = { { 1896 /* getBitwiseNotType */, 2, 135, 2, 137, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getBitwiseNotTypeFromType = { { 1914 /* getBitwiseNotTypeFromType */, 1, 138, 1, 139, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig resolveName = { { 1965 /* resolveName */, 2, 140, 2, 142, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig resolveTypeByName = { { 2008 /* resolveTypeByName */, 2, 143, 2, 145, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig resolveTypeByNameWithLateStaticBinding = { { 2098 /* resolveTypeByNameWithLateStaticBinding */, 3, 146, 3, 149, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getReflectionProvider = { { 2175 /* getReflectionProvider */, 0, 150, 0, 150, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getNeverType = { { 2197 /* getNeverType */, 2, 151, 2, 153, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig createFirstClassCallable = { { 1255 /* createFirstClassCallable */, 3, 44, 6, 50, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig renameParameters = { { 1297 /* renameParameters */, 2, 51, 2, 53, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; +inline constexpr sigtab::Sig getBitwiseAndType = { { 1314 /* getBitwiseAndType */, 3, 54, 3, 57, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseOrType = { { 1332 /* getBitwiseOrType */, 3, 58, 3, 61, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseXorType = { { 1349 /* getBitwiseXorType */, 3, 62, 3, 65, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getSpaceshipType = { { 1367 /* getSpaceshipType */, 3, 66, 3, 69, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getDivType = { { 1384 /* getDivType */, 3, 70, 3, 73, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getModType = { { 1395 /* getModType */, 3, 74, 3, 77, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getPlusType = { { 1406 /* getPlusType */, 3, 78, 3, 81, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getMinusType = { { 1418 /* getMinusType */, 3, 82, 3, 85, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getMulType = { { 1431 /* getMulType */, 3, 86, 3, 89, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getPowType = { { 1442 /* getPowType */, 3, 90, 3, 93, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getShiftLeftType = { { 1453 /* getShiftLeftType */, 3, 94, 3, 97, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getShiftRightType = { { 1470 /* getShiftRightType */, 3, 98, 3, 101, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig resolveIdenticalType = { { 1531 /* resolveIdenticalType */, 2, 102, 2, 104, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig resolveEqualType = { { 1552 /* resolveEqualType */, 2, 105, 3, 108, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNonNumericString = { { 1569 /* isNonNumericString */, 2, 109, 2, 111, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; +inline constexpr sigtab::Sig resolveConstantArrayTypeComparison = { { 1652 /* resolveConstantArrayTypeComparison */, 3, 112, 3, 115, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getClassConstFetchTypeByReflection = { { 1803 /* getClassConstFetchTypeByReflection */, 4, 116, 5, 121, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig transformStaticType = { { 1852 /* transformStaticType */, 2, 122, 2, 124, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getClassConstFetchType = { { 1872 /* getClassConstFetchType */, 4, 125, 4, 129, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnaryPlusType = { { 1895 /* getUnaryPlusType */, 2, 130, 2, 132, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnaryMinusType = { { 1912 /* getUnaryMinusType */, 2, 133, 2, 135, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseNotType = { { 1930 /* getBitwiseNotType */, 2, 136, 2, 138, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getBitwiseNotTypeFromType = { { 1948 /* getBitwiseNotTypeFromType */, 1, 139, 1, 140, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig resolveName = { { 1999 /* resolveName */, 2, 141, 2, 143, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig resolveTypeByName = { { 2042 /* resolveTypeByName */, 2, 144, 2, 146, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig resolveTypeByNameWithLateStaticBinding = { { 2132 /* resolveTypeByNameWithLateStaticBinding */, 3, 147, 3, 150, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getReflectionProvider = { { 2209 /* getReflectionProvider */, 0, 151, 0, 151, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getNeverType = { { 2231 /* getNeverType */, 2, 152, 2, 154, ZEND_ACC_PRIVATE } }; } // namespace sig } // namespace ptdecl::InitializerExprTypeResolver diff --git a/turbo-ext/src/support.cpp b/turbo-ext/src/support.cpp index ef31d7e0a1a..62d889a5a13 100644 --- a/turbo-ext/src/support.cpp +++ b/turbo-ext/src/support.cpp @@ -418,6 +418,8 @@ static const pt_class_template pt_class_templates[PT_CLASS_COUNT] = { /* PT_CLASS_ARRAY_MAP_CALLBACK_PARAMETER_TYPES */ {"arrayMapCallbackParameterTypes", "PHPStan\\Reflection\\ArrayMapCallbackParameterTypes"}, /* PT_CLASS_VALUE_DEPENDENCY_COLLECTOR */ {"valueDependencyCollector", "PHPStan\\Analyser\\ValueDependencyCollector"}, /* PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS */ {"partialFunctionApplicationParameters", "PHPStan\\Reflection\\PartialFunctionApplicationParameters"}, + /* PT_CLASS_CLOSURE_ORIGIN */ {"closureOrigin", "PHPStan\\Type\\ClosureOrigin"}, + /* PT_CLASS_CLOSURE_ORIGIN_CALL_REPLAY */ {"closureOriginCallReplay", "PHPStan\\Analyser\\ExprHandler\\Helper\\ClosureOriginCallReplay"}, }; zend_class_entry *pt_class(int idx) diff --git a/turbo-ext/src/support.h b/turbo-ext/src/support.h index 3c887159c17..b534721a537 100644 --- a/turbo-ext/src/support.h +++ b/turbo-ext/src/support.h @@ -525,6 +525,9 @@ enum { PT_CLASS_VALUE_DEPENDENCY_COLLECTOR, /* the closure parameters of a partial function application */ PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS, + /* the callee of a closure created from a callable, and the replay of its calls */ + PT_CLASS_CLOSURE_ORIGIN, + PT_CLASS_CLOSURE_ORIGIN_CALL_REPLAY, PT_CLASS_COUNT }; @@ -1094,7 +1097,7 @@ extern zend_class_entry *pt_ce_closure_type; * exception */ [[nodiscard]] bool pt_iterable_type_new(zval *out, zval *keyType, zval *itemType); bool pt_callable_type_new(zval *out, zval *parameters = NULL, zval *returnType = NULL, bool variadic = true, zval *templateTypeMap = NULL, zval *resolvedTemplateTypeMap = NULL, zval *templateTags = NULL, zval *isPure = NULL, zval *assertions = NULL); -bool pt_closure_type_new(zval *out, zval *parameters = NULL, zval *returnType = NULL, bool variadic = true, zval *templateTypeMap = NULL, zval *resolvedTemplateTypeMap = NULL, zval *callSiteVarianceMap = NULL, zval *templateTags = NULL, zval *throwPoints = NULL, zval *impurePoints = NULL, zval *invalidateExpressions = NULL, zval *usedVariables = NULL, zval *acceptsNamedArguments = NULL, zval *mustUseReturnValue = NULL, zval *assertions = NULL, zval *isStatic = NULL, zval *byRefUseTypes = NULL); +bool pt_closure_type_new(zval *out, zval *parameters = NULL, zval *returnType = NULL, bool variadic = true, zval *templateTypeMap = NULL, zval *resolvedTemplateTypeMap = NULL, zval *callSiteVarianceMap = NULL, zval *templateTags = NULL, zval *throwPoints = NULL, zval *impurePoints = NULL, zval *invalidateExpressions = NULL, zval *usedVariables = NULL, zval *acceptsNamedArguments = NULL, zval *mustUseReturnValue = NULL, zval *assertions = NULL, zval *isStatic = NULL, zval *byRefUseTypes = NULL, zval *origin = NULL); /* merged from the parallel port branch */ /* the array-shape type (ConstantArrayType.cpp) */ @@ -3297,6 +3300,10 @@ zv::Val pt_closure_signature_inference_add_absorbed_in_union_of_two(zval *scope, /* $closureParameterResolver->resolveCallableTypeForScope($expr, $scope); * UNDEF = pending exception */ zv::Val pt_closure_parameter_resolver_resolve_callable_type_for_scope(zval *resolver, zval *expr, zval *scope); +/* ClosureOrigin::forFunction($functionName) / ClosureOrigin::forMethod($calledOnType, + * $methodName, $isStaticCall); UNDEF = pending exception */ +zv::Val pt_closure_origin_for_function(zval *functionName); +zv::Val pt_closure_origin_for_method(zval *calledOnType, zval *methodName, bool isStaticCall); /* $closureType->getByRefUseTypes(); UNDEF = pending exception */ zv::Val pt_closure_type_get_by_ref_use_types(zval *closureType); /* $closureType->containsUnresolvedTemplateArgument(); false = pending @@ -4087,7 +4094,7 @@ enum pt_ietr_binary_operator : uint8_t * ->getFirstClassCallableType($expr, $context, $nativeTypesPromoted, * $boundArgTypes) / * ->createFirstClassCallable($function, $variants, $nativeTypesPromoted, - * $partialApplicationArgs, $boundArgTypes) / + * $partialApplicationArgs, $boundArgTypes, $origin) / * ->getClassConstFetchTypeByReflection($class, $constantName, * $classReflection, $getTypeCallback) / ->getUnaryPlusType($expr, * $getTypeCallback) / ->getUnaryMinusType(...) / ->getBitwiseNotType(...): @@ -4107,7 +4114,7 @@ zv::Val pt_initializer_expr_type_resolver_get_cast_type(zval *resolver, zval *ex zv::Val pt_initializer_expr_type_resolver_get_cast_object_type(zval *resolver, zval *exprType); zv::Val pt_initializer_expr_type_resolver_get_function_type(zval *resolver, zval *type, bool isNullable, bool isVariadic, zval *context); zv::Val pt_initializer_expr_type_resolver_get_first_class_callable_type(zval *resolver, zval *expr, zval *context, bool nativeTypesPromoted, zval *boundArgTypes); -zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes); +zv::Val pt_initializer_expr_type_resolver_create_first_class_callable(zval *resolver, zval *function, zval *variants, bool nativeTypesPromoted, zval *partialApplicationArgs, zval *boundArgTypes, zval *origin); zv::Val pt_initializer_expr_type_resolver_get_class_const_fetch_type_by_reflection(zval *resolver, zval *class_, zval *constantName, zval *classReflection, const pt_ietr_get_type &getTypeCallback, bool nativeTypesPromoted = false); zv::Val pt_initializer_expr_type_resolver_get_unary_plus_type(zval *resolver, zval *expr, const pt_ietr_get_type &getTypeCallback); zv::Val pt_initializer_expr_type_resolver_get_unary_minus_type(zval *resolver, zval *expr, const pt_ietr_get_type &getTypeCallback); diff --git a/turbo-ext/tests/type-family.php b/turbo-ext/tests/type-family.php index e593c007c5a..c6ff137585e 100644 --- a/turbo-ext/tests/type-family.php +++ b/turbo-ext/tests/type-family.php @@ -2782,6 +2782,13 @@ public function getSubtractedType(): ?\PHPStan\Type\Type 'closureTemplate' => new \PHPStan\Type\ClosureType([$callableParam('a', $callableT), $callableParam('b', $callableU)], $callableT, true, $callableTemplateTypeMap, $callableResolvedTemplateTypeMap, null, $callableTemplateTags), 'closureAsserts' => new \PHPStan\Type\ClosureType([$callableParam('a', new \PHPStan\Type\MixedType())], new \PHPStan\Type\BooleanType(), assertions: $callableAssertionsIfTrue), 'closureAssertsTemplate' => new \PHPStan\Type\ClosureType([$callableParam('a', new \PHPStan\Type\MixedType())], new \PHPStan\Type\BooleanType(), true, $callableTemplateTypeMap, null, null, $callableTemplateTags, [], null, [], [], null, null, $callableAssertionsTemplate), + 'closureOriginStrtoupper' => new \PHPStan\Type\ClosureType([$callableParam('string', new \PHPStan\Type\StringType())], new \PHPStan\Type\StringType(), origin: \PHPStan\Type\ClosureOrigin::forFunction('strtoupper')), + 'closureOriginStrtoupperCopy' => new \PHPStan\Type\ClosureType([$callableParam('string', new \PHPStan\Type\StringType())], new \PHPStan\Type\StringType(), origin: \PHPStan\Type\ClosureOrigin::forFunction('strtoupper')), + 'closureOriginStrtolower' => new \PHPStan\Type\ClosureType([$callableParam('string', new \PHPStan\Type\StringType())], new \PHPStan\Type\StringType(), origin: \PHPStan\Type\ClosureOrigin::forFunction('strtolower')), + 'closureOriginPlain' => new \PHPStan\Type\ClosureType([$callableParam('string', new \PHPStan\Type\StringType())], new \PHPStan\Type\StringType()), + 'closureOriginMethod' => new \PHPStan\Type\ClosureType([$callableParam('modifier', new \PHPStan\Type\StringType())], new \PHPStan\Type\ObjectType(\DateTimeImmutable::class), origin: \PHPStan\Type\ClosureOrigin::forMethod(new \PHPStan\Type\ObjectType(\DateTimeImmutable::class), 'modify', false)), + 'closureOriginPartial' => new \PHPStan\Type\ClosureType([$callableParam('subject', new \PHPStan\Type\StringType())], new \PHPStan\Type\StringType(), origin: \PHPStan\Type\ClosureOrigin::forFunction('str_replace')->withPartialApplication([new \PhpParser\Node\Arg(new \PhpParser\Node\Scalar\String_(' ')), new \PhpParser\Node\Arg(new \PhpParser\Node\Scalar\String_('-')), new \PhpParser\Node\ArgPlaceholder()], [0 => new \PHPStan\Type\Constant\ConstantStringType(' '), 1 => new \PHPStan\Type\Constant\ConstantStringType('-')])), + 'closureOriginTemplate' => new \PHPStan\Type\ClosureType([$callableParam('a', $callableT)], $callableT, true, $callableTemplateTypeMap, null, null, $callableTemplateTags, origin: \PHPStan\Type\ClosureOrigin::forFunction('pick')->withPartialApplication([new \PhpParser\Node\Arg(new \PhpParser\Node\Scalar\Int_(1)), new \PhpParser\Node\ArgPlaceholder()], [0 => $callableT])), 'closureNestedMarker' => new \PHPStan\Type\ClosureType([$callableParam('a', new \PHPStan\Type\UnionType([new \PHPStan\Type\IntegerType(), new \PHPStan\Type\ArrayType(new \PHPStan\Type\MixedType(), new \PHPStan\Type\Generic\UnresolvedTemplateArgumentType(new \PhpParser\Node\Expr\Variable('x'), $callableT, null))]))], new \PHPStan\Type\VoidType()), 'iterable' => new \PHPStan\Type\IterableType(new \PHPStan\Type\MixedType(), new \PHPStan\Type\MixedType()), 'iterableExplicit' => new \PHPStan\Type\IterableType(new \PHPStan\Type\MixedType(true), new \PHPStan\Type\MixedType(true)), From 831dec5a9d9e74021c95e497f88c5710a206e231 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Tue, 10 Nov 2026 21:22:37 +0000 Subject: [PATCH 07/20] Report a named argument for a parameter a partial application bound PHP throws "Named parameter $x overwrites previous argument" when a variadic closure created by a partial function application is called with a named argument for a parameter the application already bound, positionally or by name. The origin of the closure now carries the names of the bound parameters, and calling the closure with one of them is reported. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- .../InitializerExprTypeResolver.php | 8 +++-- .../PartialFunctionApplicationParameters.php | 24 +++++++++++--- src/Rules/Functions/CallCallablesRule.php | 33 +++++++++++++++++++ src/Type/ClosureOrigin.php | 24 +++++++++++++- .../Rules/Functions/CallCallablesRuleTest.php | 20 +++++++++++ ...ial-function-application-closure-calls.php | 23 +++++++++++++ turbo-ext/src/InitializerExprTypeResolver.cpp | 10 ++++-- 7 files changed, 132 insertions(+), 10 deletions(-) diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index da55dd5b329..20d46fbf889 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -956,13 +956,17 @@ public function createFirstClassCallable( } $isVariadic = $variant->isVariadic(); $templateTypeMap = $variant->getTemplateTypeMap(); + $variantOrigin = $origin; if ($partialApplicationArgs !== null) { $partialApplication = PartialFunctionApplicationParameters::apply($parameters, $partialApplicationArgs, $boundArgTypes, $returnType, $templateTypeMap); if ($partialApplication === null) { // creating the closure from this variant throws continue; } - [$parameters, $isVariadic, $returnType, $templateTypeMap] = $partialApplication; + [$parameters, $isVariadic, $returnType, $templateTypeMap, $boundParameterNames] = $partialApplication; + if ($variantOrigin !== null) { + $variantOrigin = $variantOrigin->withBoundParameterNames($boundParameterNames); + } } $templateTags = []; @@ -1003,7 +1007,7 @@ public function createFirstClassCallable( mustUseReturnValue: $mustUseReturnValue, assertions: $assertions, isStatic: $isStaticClosure, - origin: $origin, + origin: $variantOrigin, ); } diff --git a/src/Reflection/PartialFunctionApplicationParameters.php b/src/Reflection/PartialFunctionApplicationParameters.php index 1d773fb7f32..340d1b30014 100644 --- a/src/Reflection/PartialFunctionApplicationParameters.php +++ b/src/Reflection/PartialFunctionApplicationParameters.php @@ -40,7 +40,9 @@ final class PartialFunctionApplicationParameters { /** - * The closure's parameters, whether it is variadic, its return type and its template types. + * The closure's parameters, whether it is variadic, its return type, its template types + * and the names of the callee's parameters the bound arguments fill (a bound argument + * collected by the variadic counts by its own name, when it has one). * * Templates the bound arguments infer are resolved: in the return type, a template * no closure parameter mentions becomes the inferred type, and one a closure parameter @@ -49,7 +51,7 @@ final class PartialFunctionApplicationParameters * @param list $parameters * @param array $args * @param array $boundArgTypes the types of the bound arguments, keyed like $args - * @return array{list, bool, Type, TemplateTypeMap}|null null when creating the closure throws + * @return array{list, bool, Type, TemplateTypeMap, list}|null null when creating the closure throws */ public static function apply(array $parameters, array $args, array $boundArgTypes, Type $returnType, TemplateTypeMap $templateTypeMap): ?array { @@ -58,8 +60,20 @@ public static function apply(array $parameters, array $args, array $boundArgType return null; } [$closureParameters, $isVariadic, $bound] = $mapped; + $boundNames = []; + foreach ($bound as [$parameter, $argIndex]) { + if (!$parameter->isVariadic()) { + $boundNames[] = $parameter->getName(); + continue; + } + $arg = $args[$argIndex]; + if (!$arg instanceof Arg || $arg->name === null) { + continue; + } + $boundNames[] = $arg->name->toString(); + } if ($templateTypeMap->isEmpty()) { - return [$closureParameters, $isVariadic, $returnType, $templateTypeMap]; + return [$closureParameters, $isVariadic, $returnType, $templateTypeMap, $boundNames]; } $inferred = TemplateTypeMap::createEmpty(); @@ -70,7 +84,7 @@ public static function apply(array $parameters, array $args, array $boundArgType $inferred = $inferred->union($parameter->getType()->inferTemplateTypes($boundArgTypes[$argIndex])); } if ($inferred->isEmpty()) { - return [$closureParameters, $isVariadic, $returnType, $templateTypeMap]; + return [$closureParameters, $isVariadic, $returnType, $templateTypeMap, $boundNames]; } $inClosureParameters = []; @@ -107,7 +121,7 @@ public static function apply(array $parameters, array $args, array $boundArgType $closureTemplateTypes[$name] = $templateType; } - return [$closureParameters, $isVariadic, $returnType, new TemplateTypeMap($closureTemplateTypes)]; + return [$closureParameters, $isVariadic, $returnType, new TemplateTypeMap($closureTemplateTypes), $boundNames]; } /** diff --git a/src/Rules/Functions/CallCallablesRule.php b/src/Rules/Functions/CallCallablesRule.php index 2d25ffeef72..ec0c9cd0656 100644 --- a/src/Rules/Functions/CallCallablesRule.php +++ b/src/Rules/Functions/CallCallablesRule.php @@ -20,9 +20,11 @@ use PHPStan\Type\ClosureType; use PHPStan\Type\ErrorType; use PHPStan\Type\Type; +use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; use function array_merge; use function count; +use function in_array; use function sprintf; use function ucfirst; @@ -111,6 +113,16 @@ public function processNode( null, ); + foreach ($node->getArgs() as $arg) { + if ($arg->name === null || !self::isBoundByPartialApplication($type, $arg->name->toString())) { + continue; + } + $messages[] = RuleErrorBuilder::message(sprintf('Argument for parameter $%s has already been bound by the partial function application.', $arg->name->toString())) + ->identifier('argument.duplicate') + ->line($arg->getStartLine()) + ->build(); + } + if ($type instanceof ClosureType) { $callableDescription = 'closure'; } else { @@ -150,4 +162,25 @@ public function processNode( ); } + /** + * Whether every closure the type can be is a variadic one a partial function application + * created with the parameter bound - its call then throws "Named parameter overwrites + * previous argument". A closure that is not variadic reports the name as unknown instead. + */ + private static function isBoundByPartialApplication(Type $type, string $name): bool + { + $members = $type instanceof UnionType ? $type->getTypes() : [$type]; + foreach ($members as $member) { + if (!$member instanceof ClosureType || !$member->isVariadic()) { + return false; + } + $origin = $member->getOrigin(); + if ($origin === null || !in_array($name, $origin->getBoundParameterNames(), true)) { + return false; + } + } + + return true; + } + } diff --git a/src/Type/ClosureOrigin.php b/src/Type/ClosureOrigin.php index eaa04c4ab10..94cf5b00c6e 100644 --- a/src/Type/ClosureOrigin.php +++ b/src/Type/ClosureOrigin.php @@ -35,6 +35,7 @@ final class ClosureOrigin * @param list|null $partialApplicationArgs the name and the bound type (null for `?`) of each * argument of a partial function application before `...`, * null for a first-class callable + * @param list $boundParameterNames the callee's parameters the partial function application bound */ private function __construct( private ?string $functionName, @@ -43,6 +44,7 @@ private function __construct( private bool $isStaticCall, private ?array $partialApplicationArgs, private bool $hasVariadicPlaceholder, + private array $boundParameterNames = [], ) { } @@ -79,6 +81,25 @@ public function withPartialApplication(array $args, array $boundArgTypes): self return new self($this->functionName, $this->calledOnType, $this->methodName, $this->isStaticCall, $partialApplicationArgs, $hasVariadicPlaceholder); } + /** + * @param list $boundParameterNames + */ + public function withBoundParameterNames(array $boundParameterNames): self + { + return new self($this->functionName, $this->calledOnType, $this->methodName, $this->isStaticCall, $this->partialApplicationArgs, $this->hasVariadicPlaceholder, $boundParameterNames); + } + + /** + * The names a call of the closure cannot pass by name: PHP reports that such an argument + * overwrites the bound one when the closure is variadic. + * + * @return list + */ + public function getBoundParameterNames(): array + { + return $this->boundParameterNames; + } + public function equals(self $other): bool { if ( @@ -86,6 +107,7 @@ public function equals(self $other): bool || $this->methodName !== $other->methodName || $this->isStaticCall !== $other->isStaticCall || $this->hasVariadicPlaceholder !== $other->hasVariadicPlaceholder + || $this->boundParameterNames !== $other->boundParameterNames ) { return false; } @@ -170,7 +192,7 @@ public function traverse(callable $cb): self return $this; } - return new self($this->functionName, $calledOnType, $this->methodName, $this->isStaticCall, $partialApplicationArgs, $this->hasVariadicPlaceholder); + return new self($this->functionName, $calledOnType, $this->methodName, $this->isStaticCall, $partialApplicationArgs, $this->hasVariadicPlaceholder, $this->boundParameterNames); } /** diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index a0dbda702ac..b36e6af1bc4 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -521,6 +521,26 @@ public function testPartialFunctionApplicationClosureCalls(): void 'Parameter #2 $a of closure expects int, float given.', 39, ], + [ + 'Argument for parameter $a has already been bound by the partial function application.', + 46, + ], + [ + 'Argument for parameter $c has already been bound by the partial function application.', + 48, + ], + [ + 'Argument for parameter $x has already been bound by the partial function application.', + 52, + ], + [ + 'Unknown parameter $a in call to closure.', + 56, + ], + [ + 'Argument for parameter $a has already been bound by the partial function application.', + 60, + ], ]); } diff --git a/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php b/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php index 3e9d11a0ac0..0f9dede417d 100644 --- a/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php +++ b/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php @@ -38,3 +38,26 @@ function test(): void $i(1.0, 1, 'b'); $i(1, 1.0, 'b'); } + +function bound(bool $flag): void +{ + // a variadic closure cannot take a bound parameter by name + $j = doFoo(1, ?, ...); + $j('b', 1.0, a: true); + $j('b', 1.0, x: true); + doFoo(1, ?, 3.0, ...)('b', c: true); + + // a bound argument the variadic collects by name counts too + $k = doFoo(1, 'b', 3.0, x: true, ...); + $k(x: false); + $k(y: false); + + // a closure that is not variadic reports the name as unknown + opt(1, ?)('b', a: 1); + + // a union reports it when every member bound the parameter + $l = $flag ? doFoo(1, 'b', ?, ...) : doFoo(2, 'c', ?, ...); + $l(1.0, a: true); + $m = $flag ? doFoo(1, 'b', ?, ...) : static fn (float $c, bool ...$d): string => ''; + $m(1.0, a: true); +} diff --git a/turbo-ext/src/InitializerExprTypeResolver.cpp b/turbo-ext/src/InitializerExprTypeResolver.cpp index 8191ccfa985..c62994b41f7 100644 --- a/turbo-ext/src/InitializerExprTypeResolver.cpp +++ b/turbo-ext/src/InitializerExprTypeResolver.cpp @@ -2508,6 +2508,7 @@ class InitializerExprTypeResolver bool isVariadic = zend_is_true(isVariadicHold.raw()); IETR_VAL(templateTypeMapInit, callOn(variant, mGetTemplateTypeMap)); zv::Val templateTypeMap = std::move(templateTypeMapInit); + zv::Val variantOrigin = zv::Val::copyOf(zv::Ref(origin.raw())); if (partialApplication) { static pt_method_site applySite; zv::Args applyArgv{parameters.raw(), partialApplicationArgs, boundArgTypes, returnType.raw(), templateTypeMap.raw()}; @@ -2521,7 +2522,8 @@ class InitializerExprTypeResolver zval *appliedIsVariadic = zend_hash_index_find(Z_ARRVAL_P(applied.raw()), 1); zval *appliedReturnType = zend_hash_index_find(Z_ARRVAL_P(applied.raw()), 2); zval *appliedTemplateTypeMap = zend_hash_index_find(Z_ARRVAL_P(applied.raw()), 3); - if (UNEXPECTED(appliedParameters == NULL || appliedIsVariadic == NULL || appliedReturnType == NULL || appliedTemplateTypeMap == NULL)) { + zval *appliedBoundParameterNames = zend_hash_index_find(Z_ARRVAL_P(applied.raw()), 4); + if (UNEXPECTED(appliedParameters == NULL || appliedIsVariadic == NULL || appliedReturnType == NULL || appliedTemplateTypeMap == NULL || appliedBoundParameterNames == NULL)) { pt_throw_should_not_happen(); return zv::Val(); } @@ -2529,6 +2531,10 @@ class InitializerExprTypeResolver isVariadic = zend_is_true(appliedIsVariadic); returnType = zv::Val::copyOf(zv::Ref(appliedReturnType)); templateTypeMap = zv::Val::copyOf(zv::Ref(appliedTemplateTypeMap)); + if (Z_TYPE_P(variantOrigin.raw()) == IS_OBJECT) { + IETR_VAL(withBoundNames, pt_type_call(Z_OBJ_P(variantOrigin.raw()), PT_LC("withboundparameternames"), 1, appliedBoundParameterNames)); + variantOrigin = std::move(withBoundNames); + } } zv::Arr templateTags = zv::Arr::create(0); @@ -2588,7 +2594,7 @@ class InitializerExprTypeResolver predicateAssertions.raw(), isStaticClosure.raw(), NULL, - origin.raw() + variantOrigin.raw() ))) return zv::Val(); closureTypes.push(zv::Val::adopt(closureType)); } From 32098af9fb8dece166ede8a863cf832f93bbc48a Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Tue, 10 Nov 2026 21:32:21 +0000 Subject: [PATCH 08/20] Take the throw points of a closure call from its replayed callee A closure created from a callable carries the throw points of any call of its callee, so a stored json_decode(...) called without JSON_THROW_ON_ERROR still claimed to throw JsonException, and with implicit throws off a stored strlen(...) claimed to throw. The replayed call of the callee already knows the throw points of this call; the closure call now uses them. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- src/Analyser/ExprHandler/FuncCallHandler.php | 4 ++-- .../Helper/ClosureOriginCallReplay.php | 7 ++++++- .../CatchWithUnthrownExceptionRuleTest.php | 8 ++++++++ .../data/dead-catch-first-class-callables.php | 16 ++++++++++++++++ .../dead-catch-partial-function-application.php | 15 +++++++++++++++ turbo-ext/src/FuncCallHandler.cpp | 8 ++++---- 6 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/Analyser/ExprHandler/FuncCallHandler.php b/src/Analyser/ExprHandler/FuncCallHandler.php index dcf333e6a4c..2f2a8b76c82 100644 --- a/src/Analyser/ExprHandler/FuncCallHandler.php +++ b/src/Analyser/ExprHandler/FuncCallHandler.php @@ -602,11 +602,11 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex $this->getDependencies($beforeScope, $functionReflection, $nameResult, $preliminaryResult), ); $result = $preliminaryResult->finalize($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints, $variableFlow, $dependencies); - if ($nameType === null) { + if ($nameResult === null) { return $result; } - return ClosureOriginCallReplay::replay($nodeScopeResolver, $this->expressionResultFactory, $expr, $nameType, $scopeBeforeArgs, $storage, $result); + return ClosureOriginCallReplay::replay($nodeScopeResolver, $this->expressionResultFactory, $expr, $nameResult, $nameType, $scopeBeforeArgs, $storage, $result); } /** diff --git a/src/Analyser/ExprHandler/Helper/ClosureOriginCallReplay.php b/src/Analyser/ExprHandler/Helper/ClosureOriginCallReplay.php index f885735ab9f..4c078aa48bc 100644 --- a/src/Analyser/ExprHandler/Helper/ClosureOriginCallReplay.php +++ b/src/Analyser/ExprHandler/Helper/ClosureOriginCallReplay.php @@ -41,6 +41,7 @@ public static function replay( NodeScopeResolver $nodeScopeResolver, ExpressionResultFactory $expressionResultFactory, FuncCall $expr, + ExpressionResult $nameResult, Type $calleeType, MutatingScope $scopeBeforeArgs, ExpressionResultStorage $storage, @@ -84,9 +85,13 @@ public static function replay( $scope = $replayed[0]->getScope(); $isAlwaysTerminating = $replayed[0]->isAlwaysTerminating(); + // the callee's throw points depend on the arguments (json_decode()'s flags), + // the closure's are the ones of any call + $throwPoints = [...$nameResult->getThrowPoints(), ...$replayed[0]->getThrowPoints()]; foreach (array_slice($replayed, 1) as $replayedResult) { $scope = $scope->mergeWith($replayedResult->getScope()); $isAlwaysTerminating = $isAlwaysTerminating && $replayedResult->isAlwaysTerminating(); + $throwPoints = [...$throwPoints, ...$replayedResult->getThrowPoints()]; } // positional: simple-downgrader resolves named arguments only on $this->property->method() calls @@ -96,7 +101,7 @@ public static function replay( $expr, $result->hasYield(), $result->isAlwaysTerminating() || $isAlwaysTerminating, - $result->getThrowPoints(), + $throwPoints, $result->getImpurePoints(), static fn (bool $nativeTypesPromoted): Type => TypeCombinator::union(...array_map( static fn (ExpressionResult $replayedResult): Type => $replayedResult->getKeepVoidType($nativeTypesPromoted), diff --git a/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php b/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php index c507dd69742..d43a9500e84 100644 --- a/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php @@ -413,6 +413,10 @@ public function testPartialFunctionApplication(): void 'Dead catch - DeadCatchPartialFunctionApplication\FooException is never thrown in the try block.', 61, ], + [ + 'Dead catch - JsonException is never thrown in the try block.', + 76, + ], ]); } @@ -423,6 +427,10 @@ public function testFirstClassCallables(): void 'Dead catch - InvalidArgumentException is never thrown in the try block.', 29, ], + [ + 'Dead catch - JsonException is never thrown in the try block.', + 45, + ], ]); } diff --git a/tests/PHPStan/Rules/Exceptions/data/dead-catch-first-class-callables.php b/tests/PHPStan/Rules/Exceptions/data/dead-catch-first-class-callables.php index a212159e99a..1a5da34cea6 100644 --- a/tests/PHPStan/Rules/Exceptions/data/dead-catch-first-class-callables.php +++ b/tests/PHPStan/Rules/Exceptions/data/dead-catch-first-class-callables.php @@ -31,4 +31,20 @@ public function doBaz(): void } } + public function doJson(string $s): void + { + $decode = json_decode(...); + try { + $decode($s, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + + } + + try { + $decode($s); + } catch (\JsonException $e) { + + } + } + } diff --git a/tests/PHPStan/Rules/Exceptions/data/dead-catch-partial-function-application.php b/tests/PHPStan/Rules/Exceptions/data/dead-catch-partial-function-application.php index a44ca47a4ae..bb38a7041a2 100644 --- a/tests/PHPStan/Rules/Exceptions/data/dead-catch-partial-function-application.php +++ b/tests/PHPStan/Rules/Exceptions/data/dead-catch-partial-function-application.php @@ -61,3 +61,18 @@ function (Foo $foo, callable $cb): void { } catch (FooException $e) { } }; + +function (string $s): void { + // calling the closure throws what the call of its callee throws + $decodeThrowing = json_decode(?, flags: JSON_THROW_ON_ERROR); + try { + $decodeThrowing($s); + } catch (\JsonException $e) { + } + + $decode = json_decode(?, true); + try { + $decode($s); + } catch (\JsonException $e) { + } +}; diff --git a/turbo-ext/src/FuncCallHandler.cpp b/turbo-ext/src/FuncCallHandler.cpp index 1ca0ffae19c..2d59110db60 100644 --- a/turbo-ext/src/FuncCallHandler.cpp +++ b/turbo-ext/src/FuncCallHandler.cpp @@ -1282,12 +1282,12 @@ class FuncCallHandler if (UNEXPECTED(dependencies.isUndef())) return zv::Val(); } zv::Val result = pt_expression_result_finalize(preliminaryResult.raw(), scope.raw(), hasYield, isAlwaysTerminating, throwPoints.raw(), impurePoints.raw(), variableFlow.raw(), dependencies.raw()); - if (UNEXPECTED(result.isUndef()) || calleeNameType.isNull()) return result; + if (UNEXPECTED(result.isUndef()) || nameResult.isNull() || calleeNameType.isNull()) return result; - /* ClosureOriginCallReplay::replay($nodeScopeResolver, $this->expressionResultFactory, $expr, $nameType, $scopeBeforeArgs, $storage, $result) */ + /* ClosureOriginCallReplay::replay($nodeScopeResolver, $this->expressionResultFactory, $expr, $nameResult, $nameType, $scopeBeforeArgs, $storage, $result) */ static pt_method_site replaySite; - zv::Args replayArgv{nodeScopeResolver, slot(slots::expressionResultFactory), expr, calleeNameType.raw(), scopeBeforeArgs, storage, result.raw()}; - return pt_call_static_cached(replaySite, PT_CLASS_CLOSURE_ORIGIN_CALL_REPLAY, PT_LC("replay"), 7, replayArgv); + zv::Args replayArgv{nodeScopeResolver, slot(slots::expressionResultFactory), expr, nameResult.raw(), calleeNameType.raw(), scopeBeforeArgs, storage, result.raw()}; + return pt_call_static_cached(replaySite, PT_CLASS_CLOSURE_ORIGIN_CALL_REPLAY, PT_LC("replay"), 8, replayArgv); } /* the handler entry (Engine.h) */ From bd8f6f770c8f4cc4c4cd06ea028a2dffd9a97088 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Tue, 10 Nov 2026 21:32:21 +0000 Subject: [PATCH 09/20] Test first-class callables where the suite did not cover them - named and by-ref arguments of a stored first-class callable - usort(), uasort(), array_reduce(), array_walk() and call_user_func_array() with first-class callable callbacks, compatible and not - the closure types of multi-variant built-ins and of @method static - templates kept through a first-class callable of a first-class callable - the type of new Foo(...) - first-class callables in constant expressions (PHP 8.5), called - parent::abstractMethod(...) - result cache dependencies of the target of a first-class callable Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- .../dep.patch | 28 +++++ .../phpstan.neon | 6 + .../result-cache-first-class-callable_test.sh | 30 +++++ .../src/Dep.php | 23 ++++ .../src/FunctionFcc.php | 10 ++ .../src/MethodFcc.php | 10 ++ .../src/StaticMethodFcc.php | 10 ++ .../src/Unrelated.php | 8 ++ .../tmp/.gitignore | 2 + ...t-class-callables-constant-expressions.php | 33 ++++++ .../Analyser/nsrt/first-class-callables.php | 103 ++++++++++++++++++ .../Rules/Functions/CallCallablesRuleTest.php | 20 ++++ .../CallToFunctionParametersRuleTest.php | 35 ++++++ .../data/call-first-class-callables.php | 22 ++++ .../data/first-class-callable-callbacks.php | 73 +++++++++++++ .../Methods/StaticMethodCallableRuleTest.php | 4 + .../Methods/data/static-method-callable.php | 25 +++++ 17 files changed, 442 insertions(+) create mode 100644 e2e/result-cache-first-class-callable/dep.patch create mode 100644 e2e/result-cache-first-class-callable/phpstan.neon create mode 100755 e2e/result-cache-first-class-callable/result-cache-first-class-callable_test.sh create mode 100644 e2e/result-cache-first-class-callable/src/Dep.php create mode 100644 e2e/result-cache-first-class-callable/src/FunctionFcc.php create mode 100644 e2e/result-cache-first-class-callable/src/MethodFcc.php create mode 100644 e2e/result-cache-first-class-callable/src/StaticMethodFcc.php create mode 100644 e2e/result-cache-first-class-callable/src/Unrelated.php create mode 100644 e2e/result-cache-first-class-callable/tmp/.gitignore create mode 100644 tests/PHPStan/Analyser/nsrt/first-class-callables-constant-expressions.php create mode 100644 tests/PHPStan/Rules/Functions/data/first-class-callable-callbacks.php diff --git a/e2e/result-cache-first-class-callable/dep.patch b/e2e/result-cache-first-class-callable/dep.patch new file mode 100644 index 00000000000..cf5bc0b5248 --- /dev/null +++ b/e2e/result-cache-first-class-callable/dep.patch @@ -0,0 +1,28 @@ +--- src/Dep.php ++++ src/Dep.php +@@ -5,21 +5,21 @@ + class Dep + { + +- public function m(): string ++ public function m(): int + { +- return 'a'; ++ return 1; + } + +- public static function s(): string ++ public static function s(): int + { +- return 'a'; ++ return 1; + } + + } + +-function f(): string ++function f(): int + { +- return 'a'; ++ return 1; + } diff --git a/e2e/result-cache-first-class-callable/phpstan.neon b/e2e/result-cache-first-class-callable/phpstan.neon new file mode 100644 index 00000000000..1618e38b360 --- /dev/null +++ b/e2e/result-cache-first-class-callable/phpstan.neon @@ -0,0 +1,6 @@ +parameters: + level: 8 + phpVersion: 80100 + tmpDir: tmp + paths: + - src diff --git a/e2e/result-cache-first-class-callable/result-cache-first-class-callable_test.sh b/e2e/result-cache-first-class-callable/result-cache-first-class-callable_test.sh new file mode 100755 index 00000000000..c597ae39035 --- /dev/null +++ b/e2e/result-cache-first-class-callable/result-cache-first-class-callable_test.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# @tags result-cache + +function set_up() { + e2e::set_up +} + +function tear_down() { + e2e::tear_down +} + +function test_result_cache_first_class_callable() { + OUTPUT=$(../../bin/phpstan analyse -vv --error-format raw 2>&1) && CODE=0 || CODE=$? + echo "$OUTPUT" + assert_same "0" "$CODE" + # The signature of a first-class callable is the signature of its target, so a + # file creating one from a function, a method or a static method of Dep.php + # depends on Dep.php. Unrelated.php does not. + patch -b src/Dep.php < dep.patch + INFO=$(../../bin/phpstan result-cache-info --json) + echo "$INFO" + assert_equals 'true' "$(echo "$INFO" | jq --raw-output '.resultCacheUsed')" + assert_equals '4' "$(echo "$INFO" | jq --raw-output '.filesToAnalyseCount')" + OUTPUT=$(../../bin/phpstan analyse --error-format raw 2>&1) && CODE=0 || CODE=$? + echo "$OUTPUT" + assert_same "1" "$CODE" + assert_contains 'FunctionFcc.php:9:Function ResultCacheE2EFirstClassCallable\functionFcc() should return string but returns int.' "$OUTPUT" + assert_contains 'MethodFcc.php:9:Function ResultCacheE2EFirstClassCallable\methodFcc() should return string but returns int.' "$OUTPUT" + assert_contains 'StaticMethodFcc.php:9:Function ResultCacheE2EFirstClassCallable\staticMethodFcc() should return string but returns int.' "$OUTPUT" +} diff --git a/e2e/result-cache-first-class-callable/src/Dep.php b/e2e/result-cache-first-class-callable/src/Dep.php new file mode 100644 index 00000000000..702109565de --- /dev/null +++ b/e2e/result-cache-first-class-callable/src/Dep.php @@ -0,0 +1,23 @@ +m(...); + + return $f(); +} diff --git a/e2e/result-cache-first-class-callable/src/StaticMethodFcc.php b/e2e/result-cache-first-class-callable/src/StaticMethodFcc.php new file mode 100644 index 00000000000..02984713a67 --- /dev/null +++ b/e2e/result-cache-first-class-callable/src/StaticMethodFcc.php @@ -0,0 +1,10 @@ += 8.5 + +declare(strict_types = 1); + +namespace FirstClassCallablesConstantExpressions; + +use function PHPStan\Testing\assertType; + +const LENGTH = strlen(...); + +class Foo +{ + + public const UPPER = strtoupper(...); + + public const SELF = self::double(...); + + public static function double(int $i): int + { + return $i * 2; + } + + public function doFoo(): void + { + assertType('Closure(string): int<0, max>', LENGTH); + assertType('3', (LENGTH)('abc')); + assertType('Closure(string): uppercase-string', self::UPPER); + assertType("'A'", (self::UPPER)('a')); + assertType('Closure(int): int', self::SELF); + assertType('int', (self::SELF)(2)); + } + +} diff --git a/tests/PHPStan/Analyser/nsrt/first-class-callables.php b/tests/PHPStan/Analyser/nsrt/first-class-callables.php index 43cc852e889..4d965bbf3eb 100644 --- a/tests/PHPStan/Analyser/nsrt/first-class-callables.php +++ b/tests/PHPStan/Analyser/nsrt/first-class-callables.php @@ -114,3 +114,106 @@ public function doBaz(callable $n): void } } + +/** + * @method static string magicStatic(int $i) + * @method string magic(int $i) + */ +class MagicCallables +{ + + /** + * @param array $args + */ + public static function __callStatic(string $name, array $args): mixed + { + return ''; + } + + /** + * @param array $args + */ + public function __call(string $name, array $args): mixed + { + return ''; + } + + public function doFoo(): void + { + assertType('Closure(int): string', self::magicStatic(...)); + assertType('string', self::magicStatic(...)(1)); + assertType('Closure(int): string', $this->magic(...)); + assertType('string', $this->magic(...)(1)); + } + +} + +class MultiVariantCallables +{ + + public function doFoo(): void + { + assertType('(Closure(): int)|(Closure(int, int): int)', mt_rand(...)); + assertType('(Closure(string): (non-empty-string|false))|(Closure(string, string): (non-empty-string|false))', strtok(...)); + assertType('int<1, 6>', mt_rand(...)(1, 6)); + } + +} + +class SecondLevelCallables +{ + + /** + * @template T + * @param T $a + * @return T + */ + public function identity($a) + { + return $a; + } + + public function doFoo(): void + { + $f = $this->identity(...); + $g = $f(...); + assertType('Closure(T): T', $g); + assertType('1', $g(1)); + $h = $g(...); + assertType("'x'", $h('x')); + } + +} + +class NewCallable +{ + + public function doFoo(): void + { + assertType('*ERROR*', new \stdClass(...)); + } + +} + +class CallbackCallables +{ + + public function sum(int $carry, int $item): int + { + return $carry + $item; + } + + /** + * @param list $strings + * @param list $ints + */ + public function doFoo(array $strings, array $ints): void + { + usort($strings, strcmp(...)); + assertType('list', $strings); + assertType('int', array_reduce($ints, $this->sum(...), 0)); + assertType('lowercase-string&non-falsy-string', call_user_func_array(str_replace(...), [' ', '-', 'a b'])); + assertType('3', call_user_func(strlen(...), 'abc')); + } + +} diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index b36e6af1bc4..6b3a3091072 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -284,6 +284,26 @@ public function testFirstClassCallables(): void 'Unknown parameter $str in call to callable (Closure(string): (non-empty-string|false))|(Closure(string, string): (non-empty-string|false)).', 54, ], + [ + 'Missing parameter $b (string) in call to closure.', + 69, + ], + [ + 'Argument for parameter $a has already been passed.', + 70, + ], + [ + 'Parameter $a of closure expects int, string given.', + 72, + ], + [ + 'Parameter $b of closure expects string, int given.', + 72, + ], + [ + 'Parameter #1 $array of closure is passed by reference, so it expects variables only.', + 76, + ], ]); } diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 3fc642a997c..7f3313665be 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -3539,6 +3539,41 @@ public function testBug15700(): void ]); } + #[RequiresPhp('>= 8.1.0')] + public function testFirstClassCallableCallbacks(): void + { + $this->analyse([__DIR__ . '/data/first-class-callable-callbacks.php'], [ + [ + 'Parameter #2 $callback of function usort expects callable(string, string): int, Closure(int, int): int given.', + 66, + ], + [ + 'Parameter #2 $callback of function uasort expects callable(string, string): int, Closure(int, int): int given.', + 67, + ], + [ + 'Parameter #2 $callback of function usort expects callable(int, int): int, Closure(string, string): int given.', + 68, + ], + [ + 'Parameter #2 $callback of function array_reduce expects callable(int, string): int, Closure(int, int): int given.', + 69, + ], + [ + 'Parameter #2 $callback of function array_reduce expects callable(string, int): string, Closure(string, string): string given.', + 70, + ], + [ + 'Parameter #2 $callback of function array_walk expects callable(string, int<0, max>): mixed, Closure(int, int): void given.', + 71, + ], + [ + 'Parameter #2 $callback of function array_walk expects callable(int, int<0, max>): mixed, Closure(string, string): void given.', + 72, + ], + ]); + } + #[RequiresPhp('>= 8.6.0-dev')] public function testPartialFunctionApplicationCallbacks(): void { diff --git a/tests/PHPStan/Rules/Functions/data/call-first-class-callables.php b/tests/PHPStan/Rules/Functions/data/call-first-class-callables.php index 981ca9cccc7..7959ebbbdc5 100644 --- a/tests/PHPStan/Rules/Functions/data/call-first-class-callables.php +++ b/tests/PHPStan/Rules/Functions/data/call-first-class-callables.php @@ -53,3 +53,25 @@ function doBaz($context, \Closure $union): void $strtok(string: 'a b', token: ' '); $strtok(str: 'a b'); } + +function namedArgs(int $a, string $b, bool ...$c): void +{ +} + +/** + * @param list $ints + */ +function storedClosures(array $ints): void +{ + $f = namedArgs(...); + $f(b: 'x', a: 1); + $f(1, 'x', true, false); + $f(a: 1); + $f(1, a: 2, b: 'x'); + $f(1, 'x', d: true); + $f(b: 1, a: 'x'); + + $sort = sort(...); + $sort($ints); + $sort([3, 1, 2]); +} diff --git a/tests/PHPStan/Rules/Functions/data/first-class-callable-callbacks.php b/tests/PHPStan/Rules/Functions/data/first-class-callable-callbacks.php new file mode 100644 index 00000000000..597d06cb5fe --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/first-class-callable-callbacks.php @@ -0,0 +1,73 @@ += 8.1 + +declare(strict_types = 1); + +namespace FirstClassCallableCallbacks; + +function compareInts(int $a, int $b): int +{ + return $a <=> $b; +} + +function sum(int $carry, int $item): int +{ + return $carry + $item; +} + +function increment(int &$value, int $key): void +{ + $value++; +} + +function describe(string $value, string $key): void +{ +} + +class Callbacks +{ + + public function compare(string $a, string $b): int + { + return strcmp($a, $b); + } + + public static function concat(string $carry, string $item): string + { + return $carry . $item; + } + +} + +/** + * @param list $ints + * @param list $strings + * @param array $map + */ +function compatible(array $ints, array $strings, array $map, Callbacks $callbacks): void +{ + usort($ints, compareInts(...)); + usort($strings, strcmp(...)); + uasort($map, $callbacks->compare(...)); + array_reduce($ints, sum(...), 0); + array_reduce($strings, Callbacks::concat(...), ''); + array_walk($ints, increment(...)); + array_walk($map, describe(...)); + call_user_func_array(compareInts(...), [1, 2]); + call_user_func_array(str_replace(...), [' ', '-', 'a b']); +} + +/** + * @param list $ints + * @param list $strings + * @param array $map + */ +function incompatible(array $ints, array $strings, array $map, Callbacks $callbacks): void +{ + usort($strings, compareInts(...)); + uasort($map, compareInts(...)); + usort($ints, $callbacks->compare(...)); + array_reduce($strings, sum(...), 0); + array_reduce($ints, Callbacks::concat(...), ''); + array_walk($strings, increment(...)); + array_walk($ints, describe(...)); +} diff --git a/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php index 0dcb92fd640..f312967b65c 100644 --- a/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php @@ -106,6 +106,10 @@ public function testRule(): void 'Cannot call static method doFoo() on int.', 22, ], + [ + 'Cannot call abstract method StaticMethodCallable\\AbstractParent::doFoo().', + 88, + ], ]); } diff --git a/tests/PHPStan/Rules/Methods/data/static-method-callable.php b/tests/PHPStan/Rules/Methods/data/static-method-callable.php index d8256c1c4b7..4e3d3ee6b5d 100644 --- a/tests/PHPStan/Rules/Methods/data/static-method-callable.php +++ b/tests/PHPStan/Rules/Methods/data/static-method-callable.php @@ -67,3 +67,28 @@ public function doFoo() } } + +abstract class AbstractParent +{ + + abstract public function doFoo(): int; + + public function doBar(): int + { + return 1; + } + +} + +class AbstractChild extends AbstractParent +{ + + public function doFoo(): int + { + parent::doFoo(...); + parent::doBar(...); + + return 1; + } + +} From 9c22850792276b34220e551271060aa8537b286e Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Wed, 11 Nov 2026 06:57:07 +0000 Subject: [PATCH 10/20] Accept a first-class callable of a multi-variant callee when any variant fits A first-class callable of a built-in with several variants, like max(...), is a union of one closure per variant, but the closure is one: any variant that fits makes it acceptable, like the string 'max' already was. Union members that are closures with equal origins now answer acceptance and subtyping together, or-ed. RuleLevelHelper::transformAcceptedType() kept the origin off the closures it rebuilt, so the members could not be matched. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- src/Rules/RuleLevelHelper.php | 1 + src/Type/ClosureOrigin.php | 67 ++ src/Type/UnionType.php | 26 +- .../CallToFunctionParametersRuleTest.php | 23 +- .../data/first-class-callable-callbacks.php | 15 + turbo-ext/src/UnionType.cpp | 27 + turbo-ext/src/generated/UnionType.h | 1013 +++++++++-------- 7 files changed, 658 insertions(+), 514 deletions(-) diff --git a/src/Rules/RuleLevelHelper.php b/src/Rules/RuleLevelHelper.php index dafeac72578..525bd2bf2e2 100644 --- a/src/Rules/RuleLevelHelper.php +++ b/src/Rules/RuleLevelHelper.php @@ -210,6 +210,7 @@ private function transformAcceptedType(Type $acceptingType, Type $acceptedType): $acceptedType->acceptsNamedArguments(), $acceptedType->mustUseReturnValue(), isStatic: $acceptedType->isStaticClosure(), + origin: $acceptedType->getOrigin(), ); } diff --git a/src/Type/ClosureOrigin.php b/src/Type/ClosureOrigin.php index 94cf5b00c6e..2a84ae23efe 100644 --- a/src/Type/ClosureOrigin.php +++ b/src/Type/ClosureOrigin.php @@ -100,6 +100,73 @@ public function getBoundParameterNames(): array return $this->boundParameterNames; } + /** + * The answers of a union's members combined per closure the union can hold. Closures + * created from the same callable with the same arguments are one closure, overloaded + * with the variants of its callee: like the variants of a callable string, any of its + * signatures that holds is enough. + * + * @param list $types + * @param list $results the answer for each of $types + * @return list + */ + public static function combineOverloadAcceptsResults(array $types, array $results): array + { + $combined = []; + foreach (self::groupOverloadResults($types, $results) as $overloads) { + $result = $overloads[0]; + foreach (array_slice($overloads, 1) as $overload) { + $result = $result->or($overload); + } + $combined[] = $result; + } + + return $combined; + } + + /** + * @see combineOverloadAcceptsResults() + * @param list $types + * @param list $results the answer for each of $types + * @return list + */ + public static function combineOverloadIsSuperTypeOfResults(array $types, array $results): array + { + $combined = []; + foreach (self::groupOverloadResults($types, $results) as $overloads) { + $combined[] = count($overloads) === 1 ? $overloads[0] : $overloads[0]->or(...array_slice($overloads, 1)); + } + + return $combined; + } + + /** + * @template TResult + * @param list $types + * @param list $results + * @return list> + */ + private static function groupOverloadResults(array $types, array $results): array + { + $origins = []; + $groups = []; + foreach ($types as $i => $type) { + $origin = $type instanceof ClosureType ? $type->getOrigin() : null; + if ($origin !== null) { + foreach ($origins as $index => $groupOrigin) { + if ($groupOrigin !== null && $groupOrigin->equals($origin)) { + $groups[$index][] = $results[$i]; + continue 2; + } + } + } + $origins[] = $origin; + $groups[] = [$results[$i]]; + } + + return $groups; + } + public function equals(self $other): bool { if ( diff --git a/src/Type/UnionType.php b/src/Type/UnionType.php index 99b46164c63..5506cc53738 100644 --- a/src/Type/UnionType.php +++ b/src/Type/UnionType.php @@ -416,7 +416,12 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return IsSuperTypeOfResult::createFromBoolean($containment->yes()); } - return IsSuperTypeOfResult::extremeIdentity(...array_map(static fn (Type $innerType) => $otherType->isSuperTypeOf($innerType), $this->types)); + $results = array_map(static fn (Type $innerType) => $otherType->isSuperTypeOf($innerType), $this->types); + if ($this->hasClosureMember()) { + $results = ClosureOrigin::combineOverloadIsSuperTypeOfResults($this->types, $results); + } + + return IsSuperTypeOfResult::extremeIdentity(...$results); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult @@ -428,7 +433,24 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsRes return AcceptsResult::createYes(); } - return AcceptsResult::extremeIdentity(...array_map(static fn (Type $innerType) => $acceptingType->accepts($innerType, $strictTypes), $this->types)); + $results = array_map(static fn (Type $innerType) => $acceptingType->accepts($innerType, $strictTypes), $this->types); + if ($this->hasClosureMember()) { + $results = ClosureOrigin::combineOverloadAcceptsResults($this->types, $results); + } + + return AcceptsResult::extremeIdentity(...$results); + } + + /** Closure members of one overloaded callee answer together, see ClosureOrigin::combineOverloadAcceptsResults(). */ + private function hasClosureMember(): bool + { + foreach ($this->types as $type) { + if ($type instanceof ClosureType) { + return true; + } + } + + return false; } /** diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 7f3313665be..6ae46c1996f 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -3545,31 +3545,40 @@ public function testFirstClassCallableCallbacks(): void $this->analyse([__DIR__ . '/data/first-class-callable-callbacks.php'], [ [ 'Parameter #2 $callback of function usort expects callable(string, string): int, Closure(int, int): int given.', - 66, + 71, ], [ 'Parameter #2 $callback of function uasort expects callable(string, string): int, Closure(int, int): int given.', - 67, + 72, ], [ 'Parameter #2 $callback of function usort expects callable(int, int): int, Closure(string, string): int given.', - 68, + 73, ], [ 'Parameter #2 $callback of function array_reduce expects callable(int, string): int, Closure(int, int): int given.', - 69, + 74, ], [ 'Parameter #2 $callback of function array_reduce expects callable(string, int): string, Closure(string, string): string given.', - 70, + 75, ], [ 'Parameter #2 $callback of function array_walk expects callable(string, int<0, max>): mixed, Closure(int, int): void given.', - 71, + 76, ], [ 'Parameter #2 $callback of function array_walk expects callable(int, int<0, max>): mixed, Closure(string, string): void given.', - 72, + 77, + ], + [ + 'Parameter #1 $callback of function array_map expects (callable(int): mixed)|null, (Closure(string): (non-empty-string|false))|(Closure(string, string): (non-empty-string|false)) given.', + 78, + 'Type #1 from the union: Parameter #2 $token of passed callable is required but accepting callable does not have that parameter. It will be called without it.', + ], + [ + 'Parameter #1 $callback of function array_map expects (callable(int): mixed)|null, (Closure(string): lowercase-string)|(Closure(string): uppercase-string) given.', + 87, ], ]); } diff --git a/tests/PHPStan/Rules/Functions/data/first-class-callable-callbacks.php b/tests/PHPStan/Rules/Functions/data/first-class-callable-callbacks.php index 597d06cb5fe..a1b46d22e74 100644 --- a/tests/PHPStan/Rules/Functions/data/first-class-callable-callbacks.php +++ b/tests/PHPStan/Rules/Functions/data/first-class-callable-callbacks.php @@ -54,6 +54,11 @@ function compatible(array $ints, array $strings, array $map, Callbacks $callback array_walk($map, describe(...)); call_user_func_array(compareInts(...), [1, 2]); call_user_func_array(str_replace(...), [' ', '-', 'a b']); + + // the closure of a multi-variant function fits when any of its variants does + array_reduce($ints, max(...), 0); + array_map(max(...), $ints, $ints); + array_map(mt_rand(...), $ints, $ints); } /** @@ -70,4 +75,14 @@ function incompatible(array $ints, array $strings, array $map, Callbacks $callba array_reduce($ints, Callbacks::concat(...), ''); array_walk($strings, increment(...)); array_walk($ints, describe(...)); + array_map(strtok(...), $ints); +} + +/** + * @param list $ints + */ +function differentCallees(array $ints, bool $flag): void +{ + // closures of different functions are alternatives, each of them has to fit + array_map($flag ? strtoupper(...) : strtolower(...), $ints); } diff --git a/turbo-ext/src/UnionType.cpp b/turbo-ext/src/UnionType.cpp index 1e6c36967e6..1d34d005cb3 100644 --- a/turbo-ext/src/UnionType.cpp +++ b/turbo-ext/src/UnionType.cpp @@ -35,6 +35,7 @@ #include "TypeTraits.h" #include "generated/UnionType.h" +#include "Engine.h" namespace slots = ptdecl::UnionType::slot; namespace sigs = ptdecl::UnionType::sig; @@ -845,6 +846,9 @@ class UnionType zv::Val results = mapReversed(PT_LC("issupertypeof"), Z_OBJ_P(otherType), 0, NULL); if (UNEXPECTED(results.isUndef())) return zv::Val(); + static pt_method_site combineSite; + results = combineOverloadResults(std::move(results), combineSite, PT_LC("combineoverloadissupertypeofresults")); + if (UNEXPECTED(results.isUndef())) return zv::Val(); return pt_is_super_type_of_result_extreme_identity_spread(zv::ArrRef(results.raw()).table()); } @@ -860,9 +864,32 @@ class UnionType ZVAL_BOOL(&strictZv, strictTypes); zv::Val results = mapReversed(PT_LC("accepts"), Z_OBJ_P(acceptingType), 1, &strictZv); if (UNEXPECTED(results.isUndef())) return zv::Val(); + static pt_method_site combineSite; + results = combineOverloadResults(std::move(results), combineSite, PT_LC("combineoverloadacceptsresults")); + if (UNEXPECTED(results.isUndef())) return zv::Val(); return pt_accepts_result_extreme_identity_spread(zv::ArrRef(results.raw()).table()); } + /* The results as they are without a ClosureType member (the private + * hasClosureMember()), else ClosureOrigin::combineOverload*Results($this->types, + * $results) named by lcName; UNDEF = pending exception */ + zv::Val combineOverloadResults(zv::Val results, pt_method_site &site, const char *lcName, size_t lcNameLen) const + { + zval *types = this->types(); + if (UNEXPECTED(types == NULL)) return zv::Val(); + bool hasClosure = false; + for (zv::ArrayEntry entry : zv::ArrRef(types)) { + zval *member = entry.value().deref().raw(); + if (Z_TYPE_P(member) == IS_OBJECT && instanceof_function(Z_OBJCE_P(member), pt_ce_closure_type)) { + hasClosure = true; + break; + } + } + if (!hasClosure) return results; + zv::Args argv{types, results.raw()}; + return pt_call_static_cached(site, PT_CLASS_CLOSURE_ORIGIN, lcName, lcNameLen, 2, argv); + } + /* the same class (`$type instanceof static`) with the same member * count, then the finite sets or member-by-member equals() with each * match consumed once; false with an exception pending */ diff --git a/turbo-ext/src/generated/UnionType.h b/turbo-ext/src/generated/UnionType.h index 66861a8da1f..e852fdef5a3 100644 --- a/turbo-ext/src/generated/UnionType.h +++ b/turbo-ext/src/generated/UnionType.h @@ -90,210 +90,211 @@ inline constexpr char strings[] = "isSubTypeOf\0" /* 433 */ "acceptingType\0" /* 445 */ "isAcceptedBy\0" /* 459 */ - "yesOnly\0" /* 472 */ - "PHPStan\\TrinaryLogic\0" /* 480 */ - "finiteTypeSetContainedIn\0" /* 501 */ - "equals\0" /* 526 */ - "level\0" /* 533 */ - "PHPStan\\Type\\VerbosityLevel\0" /* 539 */ - "describe\0" /* 567 */ - "canCallback\0" /* 576 */ - "hasCallback\0" /* 588 */ - "hasInternal\0" /* 600 */ - "getCallback\0" /* 612 */ - "getInternal\0" /* 624 */ - "ancestorClassName\0" /* 636 */ - "templateTypeName\0" /* 654 */ - "getTemplateType\0" /* 671 */ - "isObject\0" /* 687 */ - "getClassStringType\0" /* 696 */ - "isEnum\0" /* 715 */ - "canAccessProperties\0" /* 722 */ - "propertyName\0" /* 742 */ - "hasProperty\0" /* 755 */ - "scope\0" /* 767 */ - "PHPStan\\Reflection\\ClassMemberAccessAnswerer\0" /* 773 */ - "PHPStan\\Reflection\\ExtendedPropertyReflection\0" /* 818 */ - "getProperty\0" /* 864 */ - "PHPStan\\Reflection\\Type\\UnresolvedPropertyPrototypeReflection\0" /* 876 */ - "getUnresolvedPropertyPrototype\0" /* 938 */ - "hasInstanceProperty\0" /* 969 */ - "getInstanceProperty\0" /* 989 */ - "getUnresolvedInstancePropertyPrototype\0" /* 1009 */ - "hasStaticProperty\0" /* 1048 */ - "getStaticProperty\0" /* 1066 */ - "getUnresolvedStaticPropertyPrototype\0" /* 1084 */ - "canCallMethods\0" /* 1121 */ - "methodName\0" /* 1136 */ - "hasMethod\0" /* 1147 */ - "PHPStan\\Reflection\\ExtendedMethodReflection\0" /* 1157 */ - "getMethod\0" /* 1201 */ - "PHPStan\\Reflection\\Type\\UnresolvedMethodPrototypeReflection\0" /* 1211 */ - "getUnresolvedMethodPrototype\0" /* 1271 */ - "canAccessConstants\0" /* 1300 */ - "constantName\0" /* 1319 */ - "hasConstant\0" /* 1332 */ - "PHPStan\\Reflection\\ClassConstantReflection\0" /* 1344 */ - "getConstant\0" /* 1387 */ - "isIterable\0" /* 1399 */ - "isIterableAtLeastOnce\0" /* 1410 */ - "getArraySize\0" /* 1432 */ - "getIterableKeyType\0" /* 1445 */ - "getFirstIterableKeyType\0" /* 1464 */ - "getLastIterableKeyType\0" /* 1488 */ - "getIterableValueType\0" /* 1511 */ - "getFirstIterableValueType\0" /* 1532 */ - "getLastIterableValueType\0" /* 1558 */ - "isArray\0" /* 1583 */ - "isConstantArray\0" /* 1591 */ - "isOversizedArray\0" /* 1607 */ - "isList\0" /* 1624 */ - "isString\0" /* 1631 */ - "isNumericString\0" /* 1640 */ - "isDecimalIntegerString\0" /* 1656 */ - "isNonEmptyString\0" /* 1679 */ - "isNonFalsyString\0" /* 1696 */ - "isLiteralString\0" /* 1713 */ - "isLowercaseString\0" /* 1729 */ - "isUppercaseString\0" /* 1747 */ - "isClassString\0" /* 1765 */ - "getClassStringObjectType\0" /* 1779 */ - "getObjectTypeOrClassStringObjectType\0" /* 1804 */ - "isVoid\0" /* 1841 */ - "isScalar\0" /* 1848 */ - "phpVersion\0" /* 1857 */ - "PHPStan\\Php\\PhpVersion\0" /* 1868 */ - "PHPStan\\Type\\BooleanType\0" /* 1891 */ - "looseCompare\0" /* 1916 */ - "isOffsetAccessible\0" /* 1929 */ - "isOffsetAccessLegal\0" /* 1948 */ - "offsetType\0" /* 1968 */ - "hasOffsetValueType\0" /* 1979 */ - "getOffsetValueType\0" /* 1998 */ - "doGetOffsetValueType\0" /* 2017 */ - "valueType\0" /* 2038 */ - "unionValues\0" /* 2048 */ - "true\0" /* 2060 */ - "setOffsetValueType\0" /* 2065 */ - "setExistingOffsetValueType\0" /* 2084 */ - "unsetOffset\0" /* 2111 */ - "filterValueType\0" /* 2123 */ - "strict\0" /* 2139 */ - "getKeysArrayFiltered\0" /* 2146 */ - "getKeysArray\0" /* 2167 */ - "getValuesArray\0" /* 2180 */ - "lengthType\0" /* 2195 */ - "preserveKeys\0" /* 2206 */ - "chunkArray\0" /* 2219 */ - "fillKeysArray\0" /* 2230 */ - "flipArray\0" /* 2244 */ - "otherArraysType\0" /* 2254 */ - "intersectKeyArray\0" /* 2270 */ - "popArray\0" /* 2288 */ - "reverseArray\0" /* 2297 */ - "needleType\0" /* 2310 */ - "null\0" /* 2321 */ - "searchArray\0" /* 2326 */ - "shiftArray\0" /* 2338 */ - "shuffleArray\0" /* 2349 */ - "sliceArray\0" /* 2362 */ - "replacementType\0" /* 2373 */ - "spliceArray\0" /* 2389 */ - "sizeType\0" /* 2401 */ - "truncateListToSize\0" /* 2410 */ - "makeListMaybe\0" /* 2429 */ - "cb\0" /* 2443 */ - "mapValueType\0" /* 2446 */ - "mapKeyType\0" /* 2459 */ - "makeAllArrayKeysOptional\0" /* 2470 */ - "case\0" /* 2495 */ - "changeKeyCaseArray\0" /* 2500 */ - "filterArrayRemovingFalsey\0" /* 2519 */ - "getEnumCases\0" /* 2545 */ - "PHPStan\\Type\\Enum\\EnumCaseObjectType\0" /* 2558 */ - "getEnumCaseObject\0" /* 2595 */ - "isCallable\0" /* 2613 */ - "getCallableParametersAcceptors\0" /* 2624 */ - "isCloneable\0" /* 2655 */ - "isSmallerThan\0" /* 2667 */ - "isSmallerThanOrEqual\0" /* 2681 */ - "isNull\0" /* 2702 */ - "isConstantValue\0" /* 2709 */ - "isConstantScalarValue\0" /* 2725 */ - "getConstantScalarTypes\0" /* 2747 */ - "getConstantScalarValues\0" /* 2770 */ - "isTrue\0" /* 2794 */ - "isFalse\0" /* 2801 */ - "isBoolean\0" /* 2809 */ - "isFloat\0" /* 2819 */ - "isInteger\0" /* 2827 */ - "getSmallerType\0" /* 2837 */ - "getSmallerOrEqualType\0" /* 2852 */ - "getGreaterType\0" /* 2874 */ - "getGreaterOrEqualType\0" /* 2889 */ - "isGreaterThan\0" /* 2911 */ - "isGreaterThanOrEqual\0" /* 2925 */ - "toBoolean\0" /* 2946 */ - "toNumber\0" /* 2956 */ - "PHPStan\\Type\\NumberSet\0" /* 2965 */ - "toNumberSet\0" /* 2988 */ - "toBitwiseNotType\0" /* 3000 */ - "toGetClassResultType\0" /* 3017 */ - "reflectionProvider\0" /* 3038 */ - "PHPStan\\Reflection\\ReflectionProvider\0" /* 3057 */ - "toClassConstantType\0" /* 3095 */ - "PHPStan\\Type\\ClassNameToObjectTypeResult\0" /* 3115 */ - "toObjectTypeForInstanceofCheck\0" /* 3156 */ - "objectOrClassType\0" /* 3187 */ - "allowString\0" /* 3205 */ - "allowSameClass\0" /* 3217 */ - "toObjectTypeForIsACheck\0" /* 3232 */ - "toAbsoluteNumber\0" /* 3256 */ - "toString\0" /* 3273 */ - "toInteger\0" /* 3282 */ - "toFloat\0" /* 3292 */ - "toArray\0" /* 3300 */ - "toArrayKey\0" /* 3308 */ - "toCoercedArgumentType\0" /* 3319 */ - "receivedType\0" /* 3341 */ - "PHPStan\\Type\\Generic\\TemplateTypeMap\0" /* 3354 */ - "inferTemplateTypes\0" /* 3391 */ - "PHPStan\\Type\\Generic\\TemplateType\0" /* 3410 */ - "getNakedTemplateType\0" /* 3444 */ - "inferred\0" /* 3465 */ - "getAbsorbedTemplateTypes\0" /* 3474 */ - "templateType\0" /* 3499 */ - "inferTemplateTypesOn\0" /* 3512 */ - "positionVariance\0" /* 3533 */ - "PHPStan\\Type\\Generic\\TemplateTypeVariance\0" /* 3550 */ - "getReferencedTemplateTypes\0" /* 3592 */ - "traverse\0" /* 3619 */ - "right\0" /* 3628 */ - "traverseSimultaneously\0" /* 3634 */ - "typeToRemove\0" /* 3657 */ - "tryRemove\0" /* 3670 */ - "exponent\0" /* 3680 */ - "arithmeticPower\0" /* 3689 */ - "getFiniteTypes\0" /* 3705 */ - "getResult\0" /* 3720 */ - "unionResults\0" /* 3730 */ - "notBenevolentUnionResults\0" /* 3743 */ - "getType\0" /* 3769 */ - "unionTypes\0" /* 3777 */ - "getValues\0" /* 3788 */ - "criteria\0" /* 3798 */ - "pickFromTypes\0" /* 3807 */ - "PHPStan\\PhpDocParser\\Ast\\Type\\TypeNode\0" /* 3821 */ - "toPhpDocNode\0" /* 3860 */ - "position\0" /* 3873 */ - "PHPStan\\Type\\NativeTypePosition\0" /* 3882 */ - "toNativePhpTypeNode\0" /* 3914 */ - "notBenevolentPickFromTypes\0" /* 3934 */ - "hasTemplateOrLateResolvableType\0" /* 3961 */ - "getPossiblyLooselyEqualType\0" /* 3993 */ - "getAlwaysLooselyEqualType\0" /* 4021 */ - "PHPStan\\Type\\ValueSet\0" /* 4047 */ - "toValueSet"; /* 4069 */ + "hasClosureMember\0" /* 472 */ + "yesOnly\0" /* 489 */ + "PHPStan\\TrinaryLogic\0" /* 497 */ + "finiteTypeSetContainedIn\0" /* 518 */ + "equals\0" /* 543 */ + "level\0" /* 550 */ + "PHPStan\\Type\\VerbosityLevel\0" /* 556 */ + "describe\0" /* 584 */ + "canCallback\0" /* 593 */ + "hasCallback\0" /* 605 */ + "hasInternal\0" /* 617 */ + "getCallback\0" /* 629 */ + "getInternal\0" /* 641 */ + "ancestorClassName\0" /* 653 */ + "templateTypeName\0" /* 671 */ + "getTemplateType\0" /* 688 */ + "isObject\0" /* 704 */ + "getClassStringType\0" /* 713 */ + "isEnum\0" /* 732 */ + "canAccessProperties\0" /* 739 */ + "propertyName\0" /* 759 */ + "hasProperty\0" /* 772 */ + "scope\0" /* 784 */ + "PHPStan\\Reflection\\ClassMemberAccessAnswerer\0" /* 790 */ + "PHPStan\\Reflection\\ExtendedPropertyReflection\0" /* 835 */ + "getProperty\0" /* 881 */ + "PHPStan\\Reflection\\Type\\UnresolvedPropertyPrototypeReflection\0" /* 893 */ + "getUnresolvedPropertyPrototype\0" /* 955 */ + "hasInstanceProperty\0" /* 986 */ + "getInstanceProperty\0" /* 1006 */ + "getUnresolvedInstancePropertyPrototype\0" /* 1026 */ + "hasStaticProperty\0" /* 1065 */ + "getStaticProperty\0" /* 1083 */ + "getUnresolvedStaticPropertyPrototype\0" /* 1101 */ + "canCallMethods\0" /* 1138 */ + "methodName\0" /* 1153 */ + "hasMethod\0" /* 1164 */ + "PHPStan\\Reflection\\ExtendedMethodReflection\0" /* 1174 */ + "getMethod\0" /* 1218 */ + "PHPStan\\Reflection\\Type\\UnresolvedMethodPrototypeReflection\0" /* 1228 */ + "getUnresolvedMethodPrototype\0" /* 1288 */ + "canAccessConstants\0" /* 1317 */ + "constantName\0" /* 1336 */ + "hasConstant\0" /* 1349 */ + "PHPStan\\Reflection\\ClassConstantReflection\0" /* 1361 */ + "getConstant\0" /* 1404 */ + "isIterable\0" /* 1416 */ + "isIterableAtLeastOnce\0" /* 1427 */ + "getArraySize\0" /* 1449 */ + "getIterableKeyType\0" /* 1462 */ + "getFirstIterableKeyType\0" /* 1481 */ + "getLastIterableKeyType\0" /* 1505 */ + "getIterableValueType\0" /* 1528 */ + "getFirstIterableValueType\0" /* 1549 */ + "getLastIterableValueType\0" /* 1575 */ + "isArray\0" /* 1600 */ + "isConstantArray\0" /* 1608 */ + "isOversizedArray\0" /* 1624 */ + "isList\0" /* 1641 */ + "isString\0" /* 1648 */ + "isNumericString\0" /* 1657 */ + "isDecimalIntegerString\0" /* 1673 */ + "isNonEmptyString\0" /* 1696 */ + "isNonFalsyString\0" /* 1713 */ + "isLiteralString\0" /* 1730 */ + "isLowercaseString\0" /* 1746 */ + "isUppercaseString\0" /* 1764 */ + "isClassString\0" /* 1782 */ + "getClassStringObjectType\0" /* 1796 */ + "getObjectTypeOrClassStringObjectType\0" /* 1821 */ + "isVoid\0" /* 1858 */ + "isScalar\0" /* 1865 */ + "phpVersion\0" /* 1874 */ + "PHPStan\\Php\\PhpVersion\0" /* 1885 */ + "PHPStan\\Type\\BooleanType\0" /* 1908 */ + "looseCompare\0" /* 1933 */ + "isOffsetAccessible\0" /* 1946 */ + "isOffsetAccessLegal\0" /* 1965 */ + "offsetType\0" /* 1985 */ + "hasOffsetValueType\0" /* 1996 */ + "getOffsetValueType\0" /* 2015 */ + "doGetOffsetValueType\0" /* 2034 */ + "valueType\0" /* 2055 */ + "unionValues\0" /* 2065 */ + "true\0" /* 2077 */ + "setOffsetValueType\0" /* 2082 */ + "setExistingOffsetValueType\0" /* 2101 */ + "unsetOffset\0" /* 2128 */ + "filterValueType\0" /* 2140 */ + "strict\0" /* 2156 */ + "getKeysArrayFiltered\0" /* 2163 */ + "getKeysArray\0" /* 2184 */ + "getValuesArray\0" /* 2197 */ + "lengthType\0" /* 2212 */ + "preserveKeys\0" /* 2223 */ + "chunkArray\0" /* 2236 */ + "fillKeysArray\0" /* 2247 */ + "flipArray\0" /* 2261 */ + "otherArraysType\0" /* 2271 */ + "intersectKeyArray\0" /* 2287 */ + "popArray\0" /* 2305 */ + "reverseArray\0" /* 2314 */ + "needleType\0" /* 2327 */ + "null\0" /* 2338 */ + "searchArray\0" /* 2343 */ + "shiftArray\0" /* 2355 */ + "shuffleArray\0" /* 2366 */ + "sliceArray\0" /* 2379 */ + "replacementType\0" /* 2390 */ + "spliceArray\0" /* 2406 */ + "sizeType\0" /* 2418 */ + "truncateListToSize\0" /* 2427 */ + "makeListMaybe\0" /* 2446 */ + "cb\0" /* 2460 */ + "mapValueType\0" /* 2463 */ + "mapKeyType\0" /* 2476 */ + "makeAllArrayKeysOptional\0" /* 2487 */ + "case\0" /* 2512 */ + "changeKeyCaseArray\0" /* 2517 */ + "filterArrayRemovingFalsey\0" /* 2536 */ + "getEnumCases\0" /* 2562 */ + "PHPStan\\Type\\Enum\\EnumCaseObjectType\0" /* 2575 */ + "getEnumCaseObject\0" /* 2612 */ + "isCallable\0" /* 2630 */ + "getCallableParametersAcceptors\0" /* 2641 */ + "isCloneable\0" /* 2672 */ + "isSmallerThan\0" /* 2684 */ + "isSmallerThanOrEqual\0" /* 2698 */ + "isNull\0" /* 2719 */ + "isConstantValue\0" /* 2726 */ + "isConstantScalarValue\0" /* 2742 */ + "getConstantScalarTypes\0" /* 2764 */ + "getConstantScalarValues\0" /* 2787 */ + "isTrue\0" /* 2811 */ + "isFalse\0" /* 2818 */ + "isBoolean\0" /* 2826 */ + "isFloat\0" /* 2836 */ + "isInteger\0" /* 2844 */ + "getSmallerType\0" /* 2854 */ + "getSmallerOrEqualType\0" /* 2869 */ + "getGreaterType\0" /* 2891 */ + "getGreaterOrEqualType\0" /* 2906 */ + "isGreaterThan\0" /* 2928 */ + "isGreaterThanOrEqual\0" /* 2942 */ + "toBoolean\0" /* 2963 */ + "toNumber\0" /* 2973 */ + "PHPStan\\Type\\NumberSet\0" /* 2982 */ + "toNumberSet\0" /* 3005 */ + "toBitwiseNotType\0" /* 3017 */ + "toGetClassResultType\0" /* 3034 */ + "reflectionProvider\0" /* 3055 */ + "PHPStan\\Reflection\\ReflectionProvider\0" /* 3074 */ + "toClassConstantType\0" /* 3112 */ + "PHPStan\\Type\\ClassNameToObjectTypeResult\0" /* 3132 */ + "toObjectTypeForInstanceofCheck\0" /* 3173 */ + "objectOrClassType\0" /* 3204 */ + "allowString\0" /* 3222 */ + "allowSameClass\0" /* 3234 */ + "toObjectTypeForIsACheck\0" /* 3249 */ + "toAbsoluteNumber\0" /* 3273 */ + "toString\0" /* 3290 */ + "toInteger\0" /* 3299 */ + "toFloat\0" /* 3309 */ + "toArray\0" /* 3317 */ + "toArrayKey\0" /* 3325 */ + "toCoercedArgumentType\0" /* 3336 */ + "receivedType\0" /* 3358 */ + "PHPStan\\Type\\Generic\\TemplateTypeMap\0" /* 3371 */ + "inferTemplateTypes\0" /* 3408 */ + "PHPStan\\Type\\Generic\\TemplateType\0" /* 3427 */ + "getNakedTemplateType\0" /* 3461 */ + "inferred\0" /* 3482 */ + "getAbsorbedTemplateTypes\0" /* 3491 */ + "templateType\0" /* 3516 */ + "inferTemplateTypesOn\0" /* 3529 */ + "positionVariance\0" /* 3550 */ + "PHPStan\\Type\\Generic\\TemplateTypeVariance\0" /* 3567 */ + "getReferencedTemplateTypes\0" /* 3609 */ + "traverse\0" /* 3636 */ + "right\0" /* 3645 */ + "traverseSimultaneously\0" /* 3651 */ + "typeToRemove\0" /* 3674 */ + "tryRemove\0" /* 3687 */ + "exponent\0" /* 3697 */ + "arithmeticPower\0" /* 3706 */ + "getFiniteTypes\0" /* 3722 */ + "getResult\0" /* 3737 */ + "unionResults\0" /* 3747 */ + "notBenevolentUnionResults\0" /* 3760 */ + "getType\0" /* 3786 */ + "unionTypes\0" /* 3794 */ + "getValues\0" /* 3805 */ + "criteria\0" /* 3815 */ + "pickFromTypes\0" /* 3824 */ + "PHPStan\\PhpDocParser\\Ast\\Type\\TypeNode\0" /* 3838 */ + "toPhpDocNode\0" /* 3877 */ + "position\0" /* 3890 */ + "PHPStan\\Type\\NativeTypePosition\0" /* 3899 */ + "toNativePhpTypeNode\0" /* 3931 */ + "notBenevolentPickFromTypes\0" /* 3951 */ + "hasTemplateOrLateResolvableType\0" /* 3978 */ + "getPossiblyLooselyEqualType\0" /* 4010 */ + "getAlwaysLooselyEqualType\0" /* 4038 */ + "PHPStan\\Type\\ValueSet\0" /* 4064 */ + "toValueSet"; /* 4086 */ inline constexpr reg::PackedArg args[] = { reg::packed(0, MAY_BE_ARRAY), /* __construct $types */ reg::packed(6, MAY_BE_BOOL, reg::NoString, false, false, 17), /* __construct $normalized */ @@ -321,66 +322,67 @@ inline constexpr reg::PackedArg args[] = { reg::packed(445, 0, 79), /* isAcceptedBy $acceptingType */ reg::packed(329, MAY_BE_BOOL), /* isAcceptedBy $strictTypes */ reg::packed(78, 0, 341), /* isAcceptedBy return */ + reg::packed(78, MAY_BE_BOOL), /* hasClosureMember return */ reg::packed(376, 0, 79), /* finiteTypeSetContainedIn $otherType */ - reg::packed(472, MAY_BE_BOOL), /* finiteTypeSetContainedIn $yesOnly */ - reg::packed(78, MAY_BE_NULL, 480), /* finiteTypeSetContainedIn return */ + reg::packed(489, MAY_BE_BOOL), /* finiteTypeSetContainedIn $yesOnly */ + reg::packed(78, MAY_BE_NULL, 497), /* finiteTypeSetContainedIn return */ reg::packed(324, 0, 79), /* equals $type */ reg::packed(78, MAY_BE_BOOL), /* equals return */ - reg::packed(533, 0, 539), /* describe $level */ + reg::packed(550, 0, 556), /* describe $level */ reg::packed(78, MAY_BE_STRING), /* describe return */ - reg::packed(576, MAY_BE_CALLABLE), /* hasInternal $canCallback */ - reg::packed(588, MAY_BE_CALLABLE), /* hasInternal $hasCallback */ - reg::packed(78, 0, 480), /* hasInternal return */ - reg::packed(588, MAY_BE_CALLABLE), /* getInternal $hasCallback */ - reg::packed(612, MAY_BE_CALLABLE), /* getInternal $getCallback */ + reg::packed(593, MAY_BE_CALLABLE), /* hasInternal $canCallback */ + reg::packed(605, MAY_BE_CALLABLE), /* hasInternal $hasCallback */ + reg::packed(78, 0, 497), /* hasInternal return */ + reg::packed(605, MAY_BE_CALLABLE), /* getInternal $hasCallback */ + reg::packed(629, MAY_BE_CALLABLE), /* getInternal $getCallback */ reg::packed(78, MAY_BE_OBJECT), /* getInternal return */ - reg::packed(636, MAY_BE_STRING), /* getTemplateType $ancestorClassName */ - reg::packed(654, MAY_BE_STRING), /* getTemplateType $templateTypeName */ + reg::packed(653, MAY_BE_STRING), /* getTemplateType $ancestorClassName */ + reg::packed(671, MAY_BE_STRING), /* getTemplateType $templateTypeName */ reg::packed(78, 0, 79), /* getTemplateType return */ - reg::packed(78, 0, 480), /* isObject return */ + reg::packed(78, 0, 497), /* isObject return */ reg::packed(78, 0, 79), /* getClassStringType return */ - reg::packed(78, 0, 480), /* isEnum return */ - reg::packed(78, 0, 480), /* canAccessProperties return */ - reg::packed(742, MAY_BE_STRING), /* hasProperty $propertyName */ - reg::packed(78, 0, 480), /* hasProperty return */ - reg::packed(742, MAY_BE_STRING), /* getProperty $propertyName */ - reg::packed(767, 0, 773), /* getProperty $scope */ - reg::packed(78, 0, 818), /* getProperty return */ - reg::packed(742, MAY_BE_STRING), /* getUnresolvedPropertyPrototype $propertyName */ - reg::packed(767, 0, 773), /* getUnresolvedPropertyPrototype $scope */ - reg::packed(78, 0, 876), /* getUnresolvedPropertyPrototype return */ - reg::packed(742, MAY_BE_STRING), /* hasInstanceProperty $propertyName */ - reg::packed(78, 0, 480), /* hasInstanceProperty return */ - reg::packed(742, MAY_BE_STRING), /* getInstanceProperty $propertyName */ - reg::packed(767, 0, 773), /* getInstanceProperty $scope */ - reg::packed(78, 0, 818), /* getInstanceProperty return */ - reg::packed(742, MAY_BE_STRING), /* getUnresolvedInstancePropertyPrototype $propertyName */ - reg::packed(767, 0, 773), /* getUnresolvedInstancePropertyPrototype $scope */ - reg::packed(78, 0, 876), /* getUnresolvedInstancePropertyPrototype return */ - reg::packed(742, MAY_BE_STRING), /* hasStaticProperty $propertyName */ - reg::packed(78, 0, 480), /* hasStaticProperty return */ - reg::packed(742, MAY_BE_STRING), /* getStaticProperty $propertyName */ - reg::packed(767, 0, 773), /* getStaticProperty $scope */ - reg::packed(78, 0, 818), /* getStaticProperty return */ - reg::packed(742, MAY_BE_STRING), /* getUnresolvedStaticPropertyPrototype $propertyName */ - reg::packed(767, 0, 773), /* getUnresolvedStaticPropertyPrototype $scope */ - reg::packed(78, 0, 876), /* getUnresolvedStaticPropertyPrototype return */ - reg::packed(78, 0, 480), /* canCallMethods return */ - reg::packed(1136, MAY_BE_STRING), /* hasMethod $methodName */ - reg::packed(78, 0, 480), /* hasMethod return */ - reg::packed(1136, MAY_BE_STRING), /* getMethod $methodName */ - reg::packed(767, 0, 773), /* getMethod $scope */ - reg::packed(78, 0, 1157), /* getMethod return */ - reg::packed(1136, MAY_BE_STRING), /* getUnresolvedMethodPrototype $methodName */ - reg::packed(767, 0, 773), /* getUnresolvedMethodPrototype $scope */ - reg::packed(78, 0, 1211), /* getUnresolvedMethodPrototype return */ - reg::packed(78, 0, 480), /* canAccessConstants return */ - reg::packed(1319, MAY_BE_STRING), /* hasConstant $constantName */ - reg::packed(78, 0, 480), /* hasConstant return */ - reg::packed(1319, MAY_BE_STRING), /* getConstant $constantName */ - reg::packed(78, 0, 1344), /* getConstant return */ - reg::packed(78, 0, 480), /* isIterable return */ - reg::packed(78, 0, 480), /* isIterableAtLeastOnce return */ + reg::packed(78, 0, 497), /* isEnum return */ + reg::packed(78, 0, 497), /* canAccessProperties return */ + reg::packed(759, MAY_BE_STRING), /* hasProperty $propertyName */ + reg::packed(78, 0, 497), /* hasProperty return */ + reg::packed(759, MAY_BE_STRING), /* getProperty $propertyName */ + reg::packed(784, 0, 790), /* getProperty $scope */ + reg::packed(78, 0, 835), /* getProperty return */ + reg::packed(759, MAY_BE_STRING), /* getUnresolvedPropertyPrototype $propertyName */ + reg::packed(784, 0, 790), /* getUnresolvedPropertyPrototype $scope */ + reg::packed(78, 0, 893), /* getUnresolvedPropertyPrototype return */ + reg::packed(759, MAY_BE_STRING), /* hasInstanceProperty $propertyName */ + reg::packed(78, 0, 497), /* hasInstanceProperty return */ + reg::packed(759, MAY_BE_STRING), /* getInstanceProperty $propertyName */ + reg::packed(784, 0, 790), /* getInstanceProperty $scope */ + reg::packed(78, 0, 835), /* getInstanceProperty return */ + reg::packed(759, MAY_BE_STRING), /* getUnresolvedInstancePropertyPrototype $propertyName */ + reg::packed(784, 0, 790), /* getUnresolvedInstancePropertyPrototype $scope */ + reg::packed(78, 0, 893), /* getUnresolvedInstancePropertyPrototype return */ + reg::packed(759, MAY_BE_STRING), /* hasStaticProperty $propertyName */ + reg::packed(78, 0, 497), /* hasStaticProperty return */ + reg::packed(759, MAY_BE_STRING), /* getStaticProperty $propertyName */ + reg::packed(784, 0, 790), /* getStaticProperty $scope */ + reg::packed(78, 0, 835), /* getStaticProperty return */ + reg::packed(759, MAY_BE_STRING), /* getUnresolvedStaticPropertyPrototype $propertyName */ + reg::packed(784, 0, 790), /* getUnresolvedStaticPropertyPrototype $scope */ + reg::packed(78, 0, 893), /* getUnresolvedStaticPropertyPrototype return */ + reg::packed(78, 0, 497), /* canCallMethods return */ + reg::packed(1153, MAY_BE_STRING), /* hasMethod $methodName */ + reg::packed(78, 0, 497), /* hasMethod return */ + reg::packed(1153, MAY_BE_STRING), /* getMethod $methodName */ + reg::packed(784, 0, 790), /* getMethod $scope */ + reg::packed(78, 0, 1174), /* getMethod return */ + reg::packed(1153, MAY_BE_STRING), /* getUnresolvedMethodPrototype $methodName */ + reg::packed(784, 0, 790), /* getUnresolvedMethodPrototype $scope */ + reg::packed(78, 0, 1228), /* getUnresolvedMethodPrototype return */ + reg::packed(78, 0, 497), /* canAccessConstants return */ + reg::packed(1336, MAY_BE_STRING), /* hasConstant $constantName */ + reg::packed(78, 0, 497), /* hasConstant return */ + reg::packed(1336, MAY_BE_STRING), /* getConstant $constantName */ + reg::packed(78, 0, 1361), /* getConstant return */ + reg::packed(78, 0, 497), /* isIterable return */ + reg::packed(78, 0, 497), /* isIterableAtLeastOnce return */ reg::packed(78, 0, 79), /* getArraySize return */ reg::packed(78, 0, 79), /* getIterableKeyType return */ reg::packed(78, 0, 79), /* getFirstIterableKeyType return */ @@ -388,131 +390,131 @@ inline constexpr reg::PackedArg args[] = { reg::packed(78, 0, 79), /* getIterableValueType return */ reg::packed(78, 0, 79), /* getFirstIterableValueType return */ reg::packed(78, 0, 79), /* getLastIterableValueType return */ - reg::packed(78, 0, 480), /* isArray return */ - reg::packed(78, 0, 480), /* isConstantArray return */ - reg::packed(78, 0, 480), /* isOversizedArray return */ - reg::packed(78, 0, 480), /* isList return */ - reg::packed(78, 0, 480), /* isString return */ - reg::packed(78, 0, 480), /* isNumericString return */ - reg::packed(78, 0, 480), /* isDecimalIntegerString return */ - reg::packed(78, 0, 480), /* isNonEmptyString return */ - reg::packed(78, 0, 480), /* isNonFalsyString return */ - reg::packed(78, 0, 480), /* isLiteralString return */ - reg::packed(78, 0, 480), /* isLowercaseString return */ - reg::packed(78, 0, 480), /* isUppercaseString return */ - reg::packed(78, 0, 480), /* isClassString return */ + reg::packed(78, 0, 497), /* isArray return */ + reg::packed(78, 0, 497), /* isConstantArray return */ + reg::packed(78, 0, 497), /* isOversizedArray return */ + reg::packed(78, 0, 497), /* isList return */ + reg::packed(78, 0, 497), /* isString return */ + reg::packed(78, 0, 497), /* isNumericString return */ + reg::packed(78, 0, 497), /* isDecimalIntegerString return */ + reg::packed(78, 0, 497), /* isNonEmptyString return */ + reg::packed(78, 0, 497), /* isNonFalsyString return */ + reg::packed(78, 0, 497), /* isLiteralString return */ + reg::packed(78, 0, 497), /* isLowercaseString return */ + reg::packed(78, 0, 497), /* isUppercaseString return */ + reg::packed(78, 0, 497), /* isClassString return */ reg::packed(78, 0, 79), /* getClassStringObjectType return */ reg::packed(78, 0, 79), /* getObjectTypeOrClassStringObjectType return */ - reg::packed(78, 0, 480), /* isVoid return */ - reg::packed(78, 0, 480), /* isScalar return */ + reg::packed(78, 0, 497), /* isVoid return */ + reg::packed(78, 0, 497), /* isScalar return */ reg::packed(324, 0, 79), /* looseCompare $type */ - reg::packed(1857, 0, 1868), /* looseCompare $phpVersion */ - reg::packed(78, 0, 1891), /* looseCompare return */ - reg::packed(78, 0, 480), /* isOffsetAccessible return */ - reg::packed(78, 0, 480), /* isOffsetAccessLegal return */ - reg::packed(1968, 0, 79), /* hasOffsetValueType $offsetType */ - reg::packed(78, 0, 480), /* hasOffsetValueType return */ - reg::packed(1968, 0, 79), /* getOffsetValueType $offsetType */ + reg::packed(1874, 0, 1885), /* looseCompare $phpVersion */ + reg::packed(78, 0, 1908), /* looseCompare return */ + reg::packed(78, 0, 497), /* isOffsetAccessible return */ + reg::packed(78, 0, 497), /* isOffsetAccessLegal return */ + reg::packed(1985, 0, 79), /* hasOffsetValueType $offsetType */ + reg::packed(78, 0, 497), /* hasOffsetValueType return */ + reg::packed(1985, 0, 79), /* getOffsetValueType $offsetType */ reg::packed(78, 0, 79), /* getOffsetValueType return */ - reg::packed(1968, 0, 79), /* doGetOffsetValueType $offsetType */ + reg::packed(1985, 0, 79), /* doGetOffsetValueType $offsetType */ reg::packed(78, 0, 79), /* doGetOffsetValueType return */ - reg::packed(1968, MAY_BE_NULL, 79), /* setOffsetValueType $offsetType */ - reg::packed(2038, 0, 79), /* setOffsetValueType $valueType */ - reg::packed(2048, MAY_BE_BOOL, reg::NoString, false, false, 2060), /* setOffsetValueType $unionValues */ + reg::packed(1985, MAY_BE_NULL, 79), /* setOffsetValueType $offsetType */ + reg::packed(2055, 0, 79), /* setOffsetValueType $valueType */ + reg::packed(2065, MAY_BE_BOOL, reg::NoString, false, false, 2077), /* setOffsetValueType $unionValues */ reg::packed(78, 0, 79), /* setOffsetValueType return */ - reg::packed(1968, 0, 79), /* setExistingOffsetValueType $offsetType */ - reg::packed(2038, 0, 79), /* setExistingOffsetValueType $valueType */ + reg::packed(1985, 0, 79), /* setExistingOffsetValueType $offsetType */ + reg::packed(2055, 0, 79), /* setExistingOffsetValueType $valueType */ reg::packed(78, 0, 79), /* setExistingOffsetValueType return */ - reg::packed(1968, 0, 79), /* unsetOffset $offsetType */ + reg::packed(1985, 0, 79), /* unsetOffset $offsetType */ reg::packed(78, 0, 79), /* unsetOffset return */ - reg::packed(2123, 0, 79), /* getKeysArrayFiltered $filterValueType */ - reg::packed(2139, 0, 480), /* getKeysArrayFiltered $strict */ + reg::packed(2140, 0, 79), /* getKeysArrayFiltered $filterValueType */ + reg::packed(2156, 0, 497), /* getKeysArrayFiltered $strict */ reg::packed(78, 0, 79), /* getKeysArrayFiltered return */ reg::packed(78, 0, 79), /* getKeysArray return */ reg::packed(78, 0, 79), /* getValuesArray return */ - reg::packed(2195, 0, 79), /* chunkArray $lengthType */ - reg::packed(2206, 0, 480), /* chunkArray $preserveKeys */ + reg::packed(2212, 0, 79), /* chunkArray $lengthType */ + reg::packed(2223, 0, 497), /* chunkArray $preserveKeys */ reg::packed(78, 0, 79), /* chunkArray return */ - reg::packed(2038, 0, 79), /* fillKeysArray $valueType */ + reg::packed(2055, 0, 79), /* fillKeysArray $valueType */ reg::packed(78, 0, 79), /* fillKeysArray return */ reg::packed(78, 0, 79), /* flipArray return */ - reg::packed(2254, 0, 79), /* intersectKeyArray $otherArraysType */ + reg::packed(2271, 0, 79), /* intersectKeyArray $otherArraysType */ reg::packed(78, 0, 79), /* intersectKeyArray return */ reg::packed(78, 0, 79), /* popArray return */ - reg::packed(2206, 0, 480), /* reverseArray $preserveKeys */ + reg::packed(2223, 0, 497), /* reverseArray $preserveKeys */ reg::packed(78, 0, 79), /* reverseArray return */ - reg::packed(2310, 0, 79), /* searchArray $needleType */ - reg::packed(2139, MAY_BE_NULL, 480, false, false, 2321), /* searchArray $strict */ + reg::packed(2327, 0, 79), /* searchArray $needleType */ + reg::packed(2156, MAY_BE_NULL, 497, false, false, 2338), /* searchArray $strict */ reg::packed(78, 0, 79), /* searchArray return */ reg::packed(78, 0, 79), /* shiftArray return */ reg::packed(78, 0, 79), /* shuffleArray return */ - reg::packed(1968, 0, 79), /* sliceArray $offsetType */ - reg::packed(2195, 0, 79), /* sliceArray $lengthType */ - reg::packed(2206, 0, 480), /* sliceArray $preserveKeys */ + reg::packed(1985, 0, 79), /* sliceArray $offsetType */ + reg::packed(2212, 0, 79), /* sliceArray $lengthType */ + reg::packed(2223, 0, 497), /* sliceArray $preserveKeys */ reg::packed(78, 0, 79), /* sliceArray return */ - reg::packed(1968, 0, 79), /* spliceArray $offsetType */ - reg::packed(2195, 0, 79), /* spliceArray $lengthType */ - reg::packed(2373, 0, 79), /* spliceArray $replacementType */ + reg::packed(1985, 0, 79), /* spliceArray $offsetType */ + reg::packed(2212, 0, 79), /* spliceArray $lengthType */ + reg::packed(2390, 0, 79), /* spliceArray $replacementType */ reg::packed(78, 0, 79), /* spliceArray return */ - reg::packed(2401, 0, 79), /* truncateListToSize $sizeType */ + reg::packed(2418, 0, 79), /* truncateListToSize $sizeType */ reg::packed(78, 0, 79), /* truncateListToSize return */ reg::packed(78, 0, 79), /* makeListMaybe return */ - reg::packed(2443, MAY_BE_CALLABLE), /* mapValueType $cb */ + reg::packed(2460, MAY_BE_CALLABLE), /* mapValueType $cb */ reg::packed(78, 0, 79), /* mapValueType return */ - reg::packed(2443, MAY_BE_CALLABLE), /* mapKeyType $cb */ + reg::packed(2460, MAY_BE_CALLABLE), /* mapKeyType $cb */ reg::packed(78, 0, 79), /* mapKeyType return */ reg::packed(78, 0, 79), /* makeAllArrayKeysOptional return */ - reg::packed(2495, MAY_BE_NULL | MAY_BE_LONG), /* changeKeyCaseArray $case */ + reg::packed(2512, MAY_BE_NULL | MAY_BE_LONG), /* changeKeyCaseArray $case */ reg::packed(78, 0, 79), /* changeKeyCaseArray return */ reg::packed(78, 0, 79), /* filterArrayRemovingFalsey return */ reg::packed(78, MAY_BE_ARRAY), /* getEnumCases return */ - reg::packed(78, MAY_BE_NULL, 2558), /* getEnumCaseObject return */ - reg::packed(78, 0, 480), /* isCallable return */ - reg::packed(767, 0, 773), /* getCallableParametersAcceptors $scope */ + reg::packed(78, MAY_BE_NULL, 2575), /* getEnumCaseObject return */ + reg::packed(78, 0, 497), /* isCallable return */ + reg::packed(784, 0, 790), /* getCallableParametersAcceptors $scope */ reg::packed(78, MAY_BE_ARRAY), /* getCallableParametersAcceptors return */ - reg::packed(78, 0, 480), /* isCloneable return */ + reg::packed(78, 0, 497), /* isCloneable return */ reg::packed(376, 0, 79), /* isSmallerThan $otherType */ - reg::packed(1857, 0, 1868), /* isSmallerThan $phpVersion */ - reg::packed(78, 0, 480), /* isSmallerThan return */ + reg::packed(1874, 0, 1885), /* isSmallerThan $phpVersion */ + reg::packed(78, 0, 497), /* isSmallerThan return */ reg::packed(376, 0, 79), /* isSmallerThanOrEqual $otherType */ - reg::packed(1857, 0, 1868), /* isSmallerThanOrEqual $phpVersion */ - reg::packed(78, 0, 480), /* isSmallerThanOrEqual return */ - reg::packed(78, 0, 480), /* isNull return */ - reg::packed(78, 0, 480), /* isConstantValue return */ - reg::packed(78, 0, 480), /* isConstantScalarValue return */ + reg::packed(1874, 0, 1885), /* isSmallerThanOrEqual $phpVersion */ + reg::packed(78, 0, 497), /* isSmallerThanOrEqual return */ + reg::packed(78, 0, 497), /* isNull return */ + reg::packed(78, 0, 497), /* isConstantValue return */ + reg::packed(78, 0, 497), /* isConstantScalarValue return */ reg::packed(78, MAY_BE_ARRAY), /* getConstantScalarTypes return */ reg::packed(78, MAY_BE_ARRAY), /* getConstantScalarValues return */ - reg::packed(78, 0, 480), /* isTrue return */ - reg::packed(78, 0, 480), /* isFalse return */ - reg::packed(78, 0, 480), /* isBoolean return */ - reg::packed(78, 0, 480), /* isFloat return */ - reg::packed(78, 0, 480), /* isInteger return */ - reg::packed(1857, 0, 1868), /* getSmallerType $phpVersion */ + reg::packed(78, 0, 497), /* isTrue return */ + reg::packed(78, 0, 497), /* isFalse return */ + reg::packed(78, 0, 497), /* isBoolean return */ + reg::packed(78, 0, 497), /* isFloat return */ + reg::packed(78, 0, 497), /* isInteger return */ + reg::packed(1874, 0, 1885), /* getSmallerType $phpVersion */ reg::packed(78, 0, 79), /* getSmallerType return */ - reg::packed(1857, 0, 1868), /* getSmallerOrEqualType $phpVersion */ + reg::packed(1874, 0, 1885), /* getSmallerOrEqualType $phpVersion */ reg::packed(78, 0, 79), /* getSmallerOrEqualType return */ - reg::packed(1857, 0, 1868), /* getGreaterType $phpVersion */ + reg::packed(1874, 0, 1885), /* getGreaterType $phpVersion */ reg::packed(78, 0, 79), /* getGreaterType return */ - reg::packed(1857, 0, 1868), /* getGreaterOrEqualType $phpVersion */ + reg::packed(1874, 0, 1885), /* getGreaterOrEqualType $phpVersion */ reg::packed(78, 0, 79), /* getGreaterOrEqualType return */ reg::packed(376, 0, 79), /* isGreaterThan $otherType */ - reg::packed(1857, 0, 1868), /* isGreaterThan $phpVersion */ - reg::packed(78, 0, 480), /* isGreaterThan return */ + reg::packed(1874, 0, 1885), /* isGreaterThan $phpVersion */ + reg::packed(78, 0, 497), /* isGreaterThan return */ reg::packed(376, 0, 79), /* isGreaterThanOrEqual $otherType */ - reg::packed(1857, 0, 1868), /* isGreaterThanOrEqual $phpVersion */ - reg::packed(78, 0, 480), /* isGreaterThanOrEqual return */ - reg::packed(78, 0, 1891), /* toBoolean return */ + reg::packed(1874, 0, 1885), /* isGreaterThanOrEqual $phpVersion */ + reg::packed(78, 0, 497), /* isGreaterThanOrEqual return */ + reg::packed(78, 0, 1908), /* toBoolean return */ reg::packed(78, 0, 79), /* toNumber return */ - reg::packed(78, MAY_BE_NULL, 2965), /* toNumberSet return */ + reg::packed(78, MAY_BE_NULL, 2982), /* toNumberSet return */ reg::packed(78, 0, 79), /* toBitwiseNotType return */ reg::packed(78, 0, 79), /* toGetClassResultType return */ - reg::packed(3038, 0, 3057), /* toClassConstantType $reflectionProvider */ + reg::packed(3055, 0, 3074), /* toClassConstantType $reflectionProvider */ reg::packed(78, 0, 79), /* toClassConstantType return */ - reg::packed(78, 0, 3115), /* toObjectTypeForInstanceofCheck return */ - reg::packed(3187, 0, 79), /* toObjectTypeForIsACheck $objectOrClassType */ - reg::packed(3205, MAY_BE_BOOL), /* toObjectTypeForIsACheck $allowString */ - reg::packed(3217, MAY_BE_BOOL), /* toObjectTypeForIsACheck $allowSameClass */ - reg::packed(78, 0, 3115), /* toObjectTypeForIsACheck return */ + reg::packed(78, 0, 3132), /* toObjectTypeForInstanceofCheck return */ + reg::packed(3204, 0, 79), /* toObjectTypeForIsACheck $objectOrClassType */ + reg::packed(3222, MAY_BE_BOOL), /* toObjectTypeForIsACheck $allowString */ + reg::packed(3234, MAY_BE_BOOL), /* toObjectTypeForIsACheck $allowSameClass */ + reg::packed(78, 0, 3132), /* toObjectTypeForIsACheck return */ reg::packed(78, 0, 79), /* toAbsoluteNumber return */ reg::packed(78, 0, 79), /* toString return */ reg::packed(78, 0, 79), /* toInteger return */ @@ -521,46 +523,46 @@ inline constexpr reg::PackedArg args[] = { reg::packed(78, 0, 79), /* toArrayKey return */ reg::packed(329, MAY_BE_BOOL), /* toCoercedArgumentType $strictTypes */ reg::packed(78, 0, 79), /* toCoercedArgumentType return */ - reg::packed(3341, 0, 79), /* inferTemplateTypes $receivedType */ - reg::packed(78, 0, 3354), /* inferTemplateTypes return */ + reg::packed(3358, 0, 79), /* inferTemplateTypes $receivedType */ + reg::packed(78, 0, 3371), /* inferTemplateTypes return */ reg::packed(324, 0, 79), /* getNakedTemplateType $type */ - reg::packed(78, MAY_BE_NULL, 3410), /* getNakedTemplateType return */ - reg::packed(3465, 0, 3354), /* getAbsorbedTemplateTypes $inferred */ - reg::packed(78, 0, 3354), /* getAbsorbedTemplateTypes return */ - reg::packed(3499, 0, 79), /* inferTemplateTypesOn $templateType */ - reg::packed(78, 0, 3354), /* inferTemplateTypesOn return */ - reg::packed(3533, 0, 3550), /* getReferencedTemplateTypes $positionVariance */ + reg::packed(78, MAY_BE_NULL, 3427), /* getNakedTemplateType return */ + reg::packed(3482, 0, 3371), /* getAbsorbedTemplateTypes $inferred */ + reg::packed(78, 0, 3371), /* getAbsorbedTemplateTypes return */ + reg::packed(3516, 0, 79), /* inferTemplateTypesOn $templateType */ + reg::packed(78, 0, 3371), /* inferTemplateTypesOn return */ + reg::packed(3550, 0, 3567), /* getReferencedTemplateTypes $positionVariance */ reg::packed(78, MAY_BE_ARRAY), /* getReferencedTemplateTypes return */ - reg::packed(2443, MAY_BE_CALLABLE), /* traverse $cb */ + reg::packed(2460, MAY_BE_CALLABLE), /* traverse $cb */ reg::packed(78, 0, 79), /* traverse return */ - reg::packed(3628, 0, 79), /* traverseSimultaneously $right */ - reg::packed(2443, MAY_BE_CALLABLE), /* traverseSimultaneously $cb */ + reg::packed(3645, 0, 79), /* traverseSimultaneously $right */ + reg::packed(2460, MAY_BE_CALLABLE), /* traverseSimultaneously $cb */ reg::packed(78, 0, 79), /* traverseSimultaneously return */ - reg::packed(3657, 0, 79), /* tryRemove $typeToRemove */ + reg::packed(3674, 0, 79), /* tryRemove $typeToRemove */ reg::packed(78, MAY_BE_NULL, 79), /* tryRemove return */ - reg::packed(3680, 0, 79), /* arithmeticPower $exponent */ - reg::packed(1857, 0, 1868), /* arithmeticPower $phpVersion */ + reg::packed(3697, 0, 79), /* arithmeticPower $exponent */ + reg::packed(1874, 0, 1885), /* arithmeticPower $phpVersion */ reg::packed(78, 0, 79), /* arithmeticPower return */ reg::packed(78, MAY_BE_ARRAY), /* getFiniteTypes return */ - reg::packed(3720, MAY_BE_CALLABLE), /* unionResults $getResult */ - reg::packed(78, 0, 480), /* unionResults return */ - reg::packed(3720, MAY_BE_CALLABLE), /* notBenevolentUnionResults $getResult */ - reg::packed(78, 0, 480), /* notBenevolentUnionResults return */ - reg::packed(3769, MAY_BE_CALLABLE), /* unionTypes $getType */ + reg::packed(3737, MAY_BE_CALLABLE), /* unionResults $getResult */ + reg::packed(78, 0, 497), /* unionResults return */ + reg::packed(3737, MAY_BE_CALLABLE), /* notBenevolentUnionResults $getResult */ + reg::packed(78, 0, 497), /* notBenevolentUnionResults return */ + reg::packed(3786, MAY_BE_CALLABLE), /* unionTypes $getType */ reg::packed(78, 0, 79), /* unionTypes return */ - reg::packed(3788, MAY_BE_CALLABLE), /* pickFromTypes $getValues */ - reg::packed(3798, MAY_BE_CALLABLE), /* pickFromTypes $criteria */ + reg::packed(3805, MAY_BE_CALLABLE), /* pickFromTypes $getValues */ + reg::packed(3815, MAY_BE_CALLABLE), /* pickFromTypes $criteria */ reg::packed(78, MAY_BE_ARRAY), /* pickFromTypes return */ - reg::packed(78, 0, 3821), /* toPhpDocNode return */ - reg::packed(3873, 0, 3882), /* toNativePhpTypeNode $position */ - reg::packed(3788, MAY_BE_CALLABLE), /* notBenevolentPickFromTypes $getValues */ + reg::packed(78, 0, 3838), /* toPhpDocNode return */ + reg::packed(3890, 0, 3899), /* toNativePhpTypeNode $position */ + reg::packed(3805, MAY_BE_CALLABLE), /* notBenevolentPickFromTypes $getValues */ reg::packed(78, MAY_BE_ARRAY), /* notBenevolentPickFromTypes return */ reg::packed(78, MAY_BE_BOOL), /* hasTemplateOrLateResolvableType return */ - reg::packed(1857, 0, 1868), /* getPossiblyLooselyEqualType $phpVersion */ + reg::packed(1874, 0, 1885), /* getPossiblyLooselyEqualType $phpVersion */ reg::packed(78, 0, 79), /* getPossiblyLooselyEqualType return */ - reg::packed(1857, 0, 1868), /* getAlwaysLooselyEqualType $phpVersion */ + reg::packed(1874, 0, 1885), /* getAlwaysLooselyEqualType $phpVersion */ reg::packed(78, 0, 79), /* getAlwaysLooselyEqualType return */ - reg::packed(78, 0, 4047), /* toValueSet return */ + reg::packed(78, 0, 4064), /* toValueSet return */ }; using Sig = reg::Sig; } // namespace sigtab @@ -584,147 +586,148 @@ inline constexpr sigtab::Sig accepts = { { 368 /* accepts */, 2, 16, 2, 18, ZEND inline constexpr sigtab::Sig isSuperTypeOf = { { 419 /* isSuperTypeOf */, 1, 19, 1, 20, ZEND_ACC_PUBLIC } }; inline constexpr sigtab::Sig isSubTypeOf = { { 433 /* isSubTypeOf */, 1, 21, 1, 22, ZEND_ACC_PUBLIC } }; inline constexpr sigtab::Sig isAcceptedBy = { { 459 /* isAcceptedBy */, 2, 23, 2, 25, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig finiteTypeSetContainedIn = { { 501 /* finiteTypeSetContainedIn */, 2, 26, 2, 28, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig equals = { { 526 /* equals */, 1, 29, 1, 30, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig describe = { { 567 /* describe */, 1, 31, 1, 32, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasInternal = { { 600 /* hasInternal */, 2, 33, 2, 35, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getInternal = { { 624 /* getInternal */, 2, 36, 2, 38, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig getTemplateType = { { 671 /* getTemplateType */, 2, 39, 2, 41, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isObject = { { 687 /* isObject */, 0, 42, 0, 42, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getClassStringType = { { 696 /* getClassStringType */, 0, 43, 0, 43, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isEnum = { { 715 /* isEnum */, 0, 44, 0, 44, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig canAccessProperties = { { 722 /* canAccessProperties */, 0, 45, 0, 45, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasProperty = { { 755 /* hasProperty */, 1, 46, 1, 47, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getProperty = { { 864 /* getProperty */, 2, 48, 2, 50, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnresolvedPropertyPrototype = { { 938 /* getUnresolvedPropertyPrototype */, 2, 51, 2, 53, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasInstanceProperty = { { 969 /* hasInstanceProperty */, 1, 54, 1, 55, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getInstanceProperty = { { 989 /* getInstanceProperty */, 2, 56, 2, 58, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnresolvedInstancePropertyPrototype = { { 1009 /* getUnresolvedInstancePropertyPrototype */, 2, 59, 2, 61, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasStaticProperty = { { 1048 /* hasStaticProperty */, 1, 62, 1, 63, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getStaticProperty = { { 1066 /* getStaticProperty */, 2, 64, 2, 66, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnresolvedStaticPropertyPrototype = { { 1084 /* getUnresolvedStaticPropertyPrototype */, 2, 67, 2, 69, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig canCallMethods = { { 1121 /* canCallMethods */, 0, 70, 0, 70, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasMethod = { { 1147 /* hasMethod */, 1, 71, 1, 72, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getMethod = { { 1201 /* getMethod */, 2, 73, 2, 75, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getUnresolvedMethodPrototype = { { 1271 /* getUnresolvedMethodPrototype */, 2, 76, 2, 78, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig canAccessConstants = { { 1300 /* canAccessConstants */, 0, 79, 0, 79, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasConstant = { { 1332 /* hasConstant */, 1, 80, 1, 81, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getConstant = { { 1387 /* getConstant */, 1, 82, 1, 83, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isIterable = { { 1399 /* isIterable */, 0, 84, 0, 84, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isIterableAtLeastOnce = { { 1410 /* isIterableAtLeastOnce */, 0, 85, 0, 85, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getArraySize = { { 1432 /* getArraySize */, 0, 86, 0, 86, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getIterableKeyType = { { 1445 /* getIterableKeyType */, 0, 87, 0, 87, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getFirstIterableKeyType = { { 1464 /* getFirstIterableKeyType */, 0, 88, 0, 88, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getLastIterableKeyType = { { 1488 /* getLastIterableKeyType */, 0, 89, 0, 89, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getIterableValueType = { { 1511 /* getIterableValueType */, 0, 90, 0, 90, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getFirstIterableValueType = { { 1532 /* getFirstIterableValueType */, 0, 91, 0, 91, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getLastIterableValueType = { { 1558 /* getLastIterableValueType */, 0, 92, 0, 92, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isArray = { { 1583 /* isArray */, 0, 93, 0, 93, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isConstantArray = { { 1591 /* isConstantArray */, 0, 94, 0, 94, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isOversizedArray = { { 1607 /* isOversizedArray */, 0, 95, 0, 95, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isList = { { 1624 /* isList */, 0, 96, 0, 96, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isString = { { 1631 /* isString */, 0, 97, 0, 97, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNumericString = { { 1640 /* isNumericString */, 0, 98, 0, 98, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isDecimalIntegerString = { { 1656 /* isDecimalIntegerString */, 0, 99, 0, 99, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNonEmptyString = { { 1679 /* isNonEmptyString */, 0, 100, 0, 100, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNonFalsyString = { { 1696 /* isNonFalsyString */, 0, 101, 0, 101, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isLiteralString = { { 1713 /* isLiteralString */, 0, 102, 0, 102, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isLowercaseString = { { 1729 /* isLowercaseString */, 0, 103, 0, 103, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isUppercaseString = { { 1747 /* isUppercaseString */, 0, 104, 0, 104, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isClassString = { { 1765 /* isClassString */, 0, 105, 0, 105, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getClassStringObjectType = { { 1779 /* getClassStringObjectType */, 0, 106, 0, 106, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getObjectTypeOrClassStringObjectType = { { 1804 /* getObjectTypeOrClassStringObjectType */, 0, 107, 0, 107, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isVoid = { { 1841 /* isVoid */, 0, 108, 0, 108, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isScalar = { { 1848 /* isScalar */, 0, 109, 0, 109, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig looseCompare = { { 1916 /* looseCompare */, 2, 110, 2, 112, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isOffsetAccessible = { { 1929 /* isOffsetAccessible */, 0, 113, 0, 113, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isOffsetAccessLegal = { { 1948 /* isOffsetAccessLegal */, 0, 114, 0, 114, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig hasOffsetValueType = { { 1979 /* hasOffsetValueType */, 1, 115, 1, 116, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getOffsetValueType = { { 1998 /* getOffsetValueType */, 1, 117, 1, 118, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig doGetOffsetValueType = { { 2017 /* doGetOffsetValueType */, 1, 119, 1, 120, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig setOffsetValueType = { { 2065 /* setOffsetValueType */, 2, 121, 3, 124, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig setExistingOffsetValueType = { { 2084 /* setExistingOffsetValueType */, 2, 125, 2, 127, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig unsetOffset = { { 2111 /* unsetOffset */, 1, 128, 1, 129, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getKeysArrayFiltered = { { 2146 /* getKeysArrayFiltered */, 2, 130, 2, 132, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getKeysArray = { { 2167 /* getKeysArray */, 0, 133, 0, 133, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getValuesArray = { { 2180 /* getValuesArray */, 0, 134, 0, 134, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig chunkArray = { { 2219 /* chunkArray */, 2, 135, 2, 137, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig fillKeysArray = { { 2230 /* fillKeysArray */, 1, 138, 1, 139, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig flipArray = { { 2244 /* flipArray */, 0, 140, 0, 140, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig intersectKeyArray = { { 2270 /* intersectKeyArray */, 1, 141, 1, 142, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig popArray = { { 2288 /* popArray */, 0, 143, 0, 143, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig reverseArray = { { 2297 /* reverseArray */, 1, 144, 1, 145, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig searchArray = { { 2326 /* searchArray */, 1, 146, 2, 148, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig shiftArray = { { 2338 /* shiftArray */, 0, 149, 0, 149, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig shuffleArray = { { 2349 /* shuffleArray */, 0, 150, 0, 150, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig sliceArray = { { 2362 /* sliceArray */, 3, 151, 3, 154, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig spliceArray = { { 2389 /* spliceArray */, 3, 155, 3, 158, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig truncateListToSize = { { 2410 /* truncateListToSize */, 1, 159, 1, 160, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig makeListMaybe = { { 2429 /* makeListMaybe */, 0, 161, 0, 161, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig mapValueType = { { 2446 /* mapValueType */, 1, 162, 1, 163, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig mapKeyType = { { 2459 /* mapKeyType */, 1, 164, 1, 165, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig makeAllArrayKeysOptional = { { 2470 /* makeAllArrayKeysOptional */, 0, 166, 0, 166, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig changeKeyCaseArray = { { 2500 /* changeKeyCaseArray */, 1, 167, 1, 168, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig filterArrayRemovingFalsey = { { 2519 /* filterArrayRemovingFalsey */, 0, 169, 0, 169, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getEnumCases = { { 2545 /* getEnumCases */, 0, 170, 0, 170, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getEnumCaseObject = { { 2595 /* getEnumCaseObject */, 0, 171, 0, 171, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isCallable = { { 2613 /* isCallable */, 0, 172, 0, 172, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getCallableParametersAcceptors = { { 2624 /* getCallableParametersAcceptors */, 1, 173, 1, 174, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isCloneable = { { 2655 /* isCloneable */, 0, 175, 0, 175, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isSmallerThan = { { 2667 /* isSmallerThan */, 2, 176, 2, 178, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isSmallerThanOrEqual = { { 2681 /* isSmallerThanOrEqual */, 2, 179, 2, 181, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isNull = { { 2702 /* isNull */, 0, 182, 0, 182, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isConstantValue = { { 2709 /* isConstantValue */, 0, 183, 0, 183, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isConstantScalarValue = { { 2725 /* isConstantScalarValue */, 0, 184, 0, 184, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getConstantScalarTypes = { { 2747 /* getConstantScalarTypes */, 0, 185, 0, 185, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getConstantScalarValues = { { 2770 /* getConstantScalarValues */, 0, 186, 0, 186, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isTrue = { { 2794 /* isTrue */, 0, 187, 0, 187, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isFalse = { { 2801 /* isFalse */, 0, 188, 0, 188, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isBoolean = { { 2809 /* isBoolean */, 0, 189, 0, 189, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isFloat = { { 2819 /* isFloat */, 0, 190, 0, 190, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isInteger = { { 2827 /* isInteger */, 0, 191, 0, 191, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getSmallerType = { { 2837 /* getSmallerType */, 1, 192, 1, 193, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getSmallerOrEqualType = { { 2852 /* getSmallerOrEqualType */, 1, 194, 1, 195, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getGreaterType = { { 2874 /* getGreaterType */, 1, 196, 1, 197, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getGreaterOrEqualType = { { 2889 /* getGreaterOrEqualType */, 1, 198, 1, 199, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isGreaterThan = { { 2911 /* isGreaterThan */, 2, 200, 2, 202, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig isGreaterThanOrEqual = { { 2925 /* isGreaterThanOrEqual */, 2, 203, 2, 205, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toBoolean = { { 2946 /* toBoolean */, 0, 206, 0, 206, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toNumber = { { 2956 /* toNumber */, 0, 207, 0, 207, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toNumberSet = { { 2988 /* toNumberSet */, 0, 208, 0, 208, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toBitwiseNotType = { { 3000 /* toBitwiseNotType */, 0, 209, 0, 209, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toGetClassResultType = { { 3017 /* toGetClassResultType */, 0, 210, 0, 210, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toClassConstantType = { { 3095 /* toClassConstantType */, 1, 211, 1, 212, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toObjectTypeForInstanceofCheck = { { 3156 /* toObjectTypeForInstanceofCheck */, 0, 213, 0, 213, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toObjectTypeForIsACheck = { { 3232 /* toObjectTypeForIsACheck */, 3, 214, 3, 217, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toAbsoluteNumber = { { 3256 /* toAbsoluteNumber */, 0, 218, 0, 218, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toString = { { 3273 /* toString */, 0, 219, 0, 219, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toInteger = { { 3282 /* toInteger */, 0, 220, 0, 220, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toFloat = { { 3292 /* toFloat */, 0, 221, 0, 221, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toArray = { { 3300 /* toArray */, 0, 222, 0, 222, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toArrayKey = { { 3308 /* toArrayKey */, 0, 223, 0, 223, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toCoercedArgumentType = { { 3319 /* toCoercedArgumentType */, 1, 224, 1, 225, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig inferTemplateTypes = { { 3391 /* inferTemplateTypes */, 1, 226, 1, 227, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getNakedTemplateType = { { 3444 /* getNakedTemplateType */, 1, 228, 1, 229, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; -inline constexpr sigtab::Sig getAbsorbedTemplateTypes = { { 3474 /* getAbsorbedTemplateTypes */, 1, 230, 1, 231, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig inferTemplateTypesOn = { { 3512 /* inferTemplateTypesOn */, 1, 232, 1, 233, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getReferencedTemplateTypes = { { 3592 /* getReferencedTemplateTypes */, 1, 234, 1, 235, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig traverse = { { 3619 /* traverse */, 1, 236, 1, 237, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig traverseSimultaneously = { { 3634 /* traverseSimultaneously */, 2, 238, 2, 240, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig tryRemove = { { 3670 /* tryRemove */, 1, 241, 1, 242, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig arithmeticPower = { { 3689 /* arithmeticPower */, 2, 243, 2, 245, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getFiniteTypes = { { 3705 /* getFiniteTypes */, 0, 246, 0, 246, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig unionResults = { { 3730 /* unionResults */, 1, 247, 1, 248, ZEND_ACC_PROTECTED } }; -inline constexpr sigtab::Sig notBenevolentUnionResults = { { 3743 /* notBenevolentUnionResults */, 1, 249, 1, 250, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig unionTypes = { { 3777 /* unionTypes */, 1, 251, 1, 252, ZEND_ACC_PROTECTED } }; -inline constexpr sigtab::Sig pickFromTypes = { { 3807 /* pickFromTypes */, 2, 253, 2, 255, ZEND_ACC_PROTECTED } }; -inline constexpr sigtab::Sig toPhpDocNode = { { 3860 /* toPhpDocNode */, 0, 256, 0, 256, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toNativePhpTypeNode = { { 3914 /* toNativePhpTypeNode */, 1, 257, 1, reg::NoArg, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig notBenevolentPickFromTypes = { { 3934 /* notBenevolentPickFromTypes */, 1, 258, 1, 259, ZEND_ACC_PRIVATE } }; -inline constexpr sigtab::Sig hasTemplateOrLateResolvableType = { { 3961 /* hasTemplateOrLateResolvableType */, 0, 260, 0, 260, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getPossiblyLooselyEqualType = { { 3993 /* getPossiblyLooselyEqualType */, 1, 261, 1, 262, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig getAlwaysLooselyEqualType = { { 4021 /* getAlwaysLooselyEqualType */, 1, 263, 1, 264, ZEND_ACC_PUBLIC } }; -inline constexpr sigtab::Sig toValueSet = { { 4069 /* toValueSet */, 0, 265, 0, 265, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasClosureMember = { { 472 /* hasClosureMember */, 0, 26, 0, 26, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig finiteTypeSetContainedIn = { { 518 /* finiteTypeSetContainedIn */, 2, 27, 2, 29, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig equals = { { 543 /* equals */, 1, 30, 1, 31, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig describe = { { 584 /* describe */, 1, 32, 1, 33, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasInternal = { { 617 /* hasInternal */, 2, 34, 2, 36, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getInternal = { { 641 /* getInternal */, 2, 37, 2, 39, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig getTemplateType = { { 688 /* getTemplateType */, 2, 40, 2, 42, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isObject = { { 704 /* isObject */, 0, 43, 0, 43, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getClassStringType = { { 713 /* getClassStringType */, 0, 44, 0, 44, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isEnum = { { 732 /* isEnum */, 0, 45, 0, 45, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig canAccessProperties = { { 739 /* canAccessProperties */, 0, 46, 0, 46, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasProperty = { { 772 /* hasProperty */, 1, 47, 1, 48, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getProperty = { { 881 /* getProperty */, 2, 49, 2, 51, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnresolvedPropertyPrototype = { { 955 /* getUnresolvedPropertyPrototype */, 2, 52, 2, 54, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasInstanceProperty = { { 986 /* hasInstanceProperty */, 1, 55, 1, 56, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getInstanceProperty = { { 1006 /* getInstanceProperty */, 2, 57, 2, 59, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnresolvedInstancePropertyPrototype = { { 1026 /* getUnresolvedInstancePropertyPrototype */, 2, 60, 2, 62, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasStaticProperty = { { 1065 /* hasStaticProperty */, 1, 63, 1, 64, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getStaticProperty = { { 1083 /* getStaticProperty */, 2, 65, 2, 67, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnresolvedStaticPropertyPrototype = { { 1101 /* getUnresolvedStaticPropertyPrototype */, 2, 68, 2, 70, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig canCallMethods = { { 1138 /* canCallMethods */, 0, 71, 0, 71, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasMethod = { { 1164 /* hasMethod */, 1, 72, 1, 73, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getMethod = { { 1218 /* getMethod */, 2, 74, 2, 76, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getUnresolvedMethodPrototype = { { 1288 /* getUnresolvedMethodPrototype */, 2, 77, 2, 79, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig canAccessConstants = { { 1317 /* canAccessConstants */, 0, 80, 0, 80, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasConstant = { { 1349 /* hasConstant */, 1, 81, 1, 82, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getConstant = { { 1404 /* getConstant */, 1, 83, 1, 84, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isIterable = { { 1416 /* isIterable */, 0, 85, 0, 85, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isIterableAtLeastOnce = { { 1427 /* isIterableAtLeastOnce */, 0, 86, 0, 86, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getArraySize = { { 1449 /* getArraySize */, 0, 87, 0, 87, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getIterableKeyType = { { 1462 /* getIterableKeyType */, 0, 88, 0, 88, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getFirstIterableKeyType = { { 1481 /* getFirstIterableKeyType */, 0, 89, 0, 89, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getLastIterableKeyType = { { 1505 /* getLastIterableKeyType */, 0, 90, 0, 90, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getIterableValueType = { { 1528 /* getIterableValueType */, 0, 91, 0, 91, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getFirstIterableValueType = { { 1549 /* getFirstIterableValueType */, 0, 92, 0, 92, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getLastIterableValueType = { { 1575 /* getLastIterableValueType */, 0, 93, 0, 93, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isArray = { { 1600 /* isArray */, 0, 94, 0, 94, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isConstantArray = { { 1608 /* isConstantArray */, 0, 95, 0, 95, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isOversizedArray = { { 1624 /* isOversizedArray */, 0, 96, 0, 96, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isList = { { 1641 /* isList */, 0, 97, 0, 97, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isString = { { 1648 /* isString */, 0, 98, 0, 98, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNumericString = { { 1657 /* isNumericString */, 0, 99, 0, 99, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isDecimalIntegerString = { { 1673 /* isDecimalIntegerString */, 0, 100, 0, 100, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNonEmptyString = { { 1696 /* isNonEmptyString */, 0, 101, 0, 101, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNonFalsyString = { { 1713 /* isNonFalsyString */, 0, 102, 0, 102, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isLiteralString = { { 1730 /* isLiteralString */, 0, 103, 0, 103, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isLowercaseString = { { 1746 /* isLowercaseString */, 0, 104, 0, 104, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isUppercaseString = { { 1764 /* isUppercaseString */, 0, 105, 0, 105, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isClassString = { { 1782 /* isClassString */, 0, 106, 0, 106, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getClassStringObjectType = { { 1796 /* getClassStringObjectType */, 0, 107, 0, 107, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getObjectTypeOrClassStringObjectType = { { 1821 /* getObjectTypeOrClassStringObjectType */, 0, 108, 0, 108, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isVoid = { { 1858 /* isVoid */, 0, 109, 0, 109, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isScalar = { { 1865 /* isScalar */, 0, 110, 0, 110, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig looseCompare = { { 1933 /* looseCompare */, 2, 111, 2, 113, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isOffsetAccessible = { { 1946 /* isOffsetAccessible */, 0, 114, 0, 114, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isOffsetAccessLegal = { { 1965 /* isOffsetAccessLegal */, 0, 115, 0, 115, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig hasOffsetValueType = { { 1996 /* hasOffsetValueType */, 1, 116, 1, 117, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getOffsetValueType = { { 2015 /* getOffsetValueType */, 1, 118, 1, 119, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig doGetOffsetValueType = { { 2034 /* doGetOffsetValueType */, 1, 120, 1, 121, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig setOffsetValueType = { { 2082 /* setOffsetValueType */, 2, 122, 3, 125, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig setExistingOffsetValueType = { { 2101 /* setExistingOffsetValueType */, 2, 126, 2, 128, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig unsetOffset = { { 2128 /* unsetOffset */, 1, 129, 1, 130, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getKeysArrayFiltered = { { 2163 /* getKeysArrayFiltered */, 2, 131, 2, 133, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getKeysArray = { { 2184 /* getKeysArray */, 0, 134, 0, 134, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getValuesArray = { { 2197 /* getValuesArray */, 0, 135, 0, 135, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig chunkArray = { { 2236 /* chunkArray */, 2, 136, 2, 138, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig fillKeysArray = { { 2247 /* fillKeysArray */, 1, 139, 1, 140, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig flipArray = { { 2261 /* flipArray */, 0, 141, 0, 141, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig intersectKeyArray = { { 2287 /* intersectKeyArray */, 1, 142, 1, 143, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig popArray = { { 2305 /* popArray */, 0, 144, 0, 144, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig reverseArray = { { 2314 /* reverseArray */, 1, 145, 1, 146, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig searchArray = { { 2343 /* searchArray */, 1, 147, 2, 149, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig shiftArray = { { 2355 /* shiftArray */, 0, 150, 0, 150, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig shuffleArray = { { 2366 /* shuffleArray */, 0, 151, 0, 151, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig sliceArray = { { 2379 /* sliceArray */, 3, 152, 3, 155, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig spliceArray = { { 2406 /* spliceArray */, 3, 156, 3, 159, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig truncateListToSize = { { 2427 /* truncateListToSize */, 1, 160, 1, 161, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig makeListMaybe = { { 2446 /* makeListMaybe */, 0, 162, 0, 162, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig mapValueType = { { 2463 /* mapValueType */, 1, 163, 1, 164, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig mapKeyType = { { 2476 /* mapKeyType */, 1, 165, 1, 166, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig makeAllArrayKeysOptional = { { 2487 /* makeAllArrayKeysOptional */, 0, 167, 0, 167, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig changeKeyCaseArray = { { 2517 /* changeKeyCaseArray */, 1, 168, 1, 169, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig filterArrayRemovingFalsey = { { 2536 /* filterArrayRemovingFalsey */, 0, 170, 0, 170, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getEnumCases = { { 2562 /* getEnumCases */, 0, 171, 0, 171, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getEnumCaseObject = { { 2612 /* getEnumCaseObject */, 0, 172, 0, 172, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isCallable = { { 2630 /* isCallable */, 0, 173, 0, 173, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getCallableParametersAcceptors = { { 2641 /* getCallableParametersAcceptors */, 1, 174, 1, 175, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isCloneable = { { 2672 /* isCloneable */, 0, 176, 0, 176, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isSmallerThan = { { 2684 /* isSmallerThan */, 2, 177, 2, 179, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isSmallerThanOrEqual = { { 2698 /* isSmallerThanOrEqual */, 2, 180, 2, 182, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isNull = { { 2719 /* isNull */, 0, 183, 0, 183, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isConstantValue = { { 2726 /* isConstantValue */, 0, 184, 0, 184, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isConstantScalarValue = { { 2742 /* isConstantScalarValue */, 0, 185, 0, 185, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getConstantScalarTypes = { { 2764 /* getConstantScalarTypes */, 0, 186, 0, 186, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getConstantScalarValues = { { 2787 /* getConstantScalarValues */, 0, 187, 0, 187, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isTrue = { { 2811 /* isTrue */, 0, 188, 0, 188, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isFalse = { { 2818 /* isFalse */, 0, 189, 0, 189, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isBoolean = { { 2826 /* isBoolean */, 0, 190, 0, 190, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isFloat = { { 2836 /* isFloat */, 0, 191, 0, 191, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isInteger = { { 2844 /* isInteger */, 0, 192, 0, 192, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getSmallerType = { { 2854 /* getSmallerType */, 1, 193, 1, 194, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getSmallerOrEqualType = { { 2869 /* getSmallerOrEqualType */, 1, 195, 1, 196, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getGreaterType = { { 2891 /* getGreaterType */, 1, 197, 1, 198, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getGreaterOrEqualType = { { 2906 /* getGreaterOrEqualType */, 1, 199, 1, 200, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isGreaterThan = { { 2928 /* isGreaterThan */, 2, 201, 2, 203, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig isGreaterThanOrEqual = { { 2942 /* isGreaterThanOrEqual */, 2, 204, 2, 206, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toBoolean = { { 2963 /* toBoolean */, 0, 207, 0, 207, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toNumber = { { 2973 /* toNumber */, 0, 208, 0, 208, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toNumberSet = { { 3005 /* toNumberSet */, 0, 209, 0, 209, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toBitwiseNotType = { { 3017 /* toBitwiseNotType */, 0, 210, 0, 210, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toGetClassResultType = { { 3034 /* toGetClassResultType */, 0, 211, 0, 211, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toClassConstantType = { { 3112 /* toClassConstantType */, 1, 212, 1, 213, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toObjectTypeForInstanceofCheck = { { 3173 /* toObjectTypeForInstanceofCheck */, 0, 214, 0, 214, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toObjectTypeForIsACheck = { { 3249 /* toObjectTypeForIsACheck */, 3, 215, 3, 218, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toAbsoluteNumber = { { 3273 /* toAbsoluteNumber */, 0, 219, 0, 219, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toString = { { 3290 /* toString */, 0, 220, 0, 220, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toInteger = { { 3299 /* toInteger */, 0, 221, 0, 221, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toFloat = { { 3309 /* toFloat */, 0, 222, 0, 222, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toArray = { { 3317 /* toArray */, 0, 223, 0, 223, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toArrayKey = { { 3325 /* toArrayKey */, 0, 224, 0, 224, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toCoercedArgumentType = { { 3336 /* toCoercedArgumentType */, 1, 225, 1, 226, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig inferTemplateTypes = { { 3408 /* inferTemplateTypes */, 1, 227, 1, 228, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getNakedTemplateType = { { 3461 /* getNakedTemplateType */, 1, 229, 1, 230, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC } }; +inline constexpr sigtab::Sig getAbsorbedTemplateTypes = { { 3491 /* getAbsorbedTemplateTypes */, 1, 231, 1, 232, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig inferTemplateTypesOn = { { 3529 /* inferTemplateTypesOn */, 1, 233, 1, 234, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getReferencedTemplateTypes = { { 3609 /* getReferencedTemplateTypes */, 1, 235, 1, 236, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig traverse = { { 3636 /* traverse */, 1, 237, 1, 238, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig traverseSimultaneously = { { 3651 /* traverseSimultaneously */, 2, 239, 2, 241, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig tryRemove = { { 3687 /* tryRemove */, 1, 242, 1, 243, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig arithmeticPower = { { 3706 /* arithmeticPower */, 2, 244, 2, 246, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getFiniteTypes = { { 3722 /* getFiniteTypes */, 0, 247, 0, 247, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig unionResults = { { 3747 /* unionResults */, 1, 248, 1, 249, ZEND_ACC_PROTECTED } }; +inline constexpr sigtab::Sig notBenevolentUnionResults = { { 3760 /* notBenevolentUnionResults */, 1, 250, 1, 251, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig unionTypes = { { 3794 /* unionTypes */, 1, 252, 1, 253, ZEND_ACC_PROTECTED } }; +inline constexpr sigtab::Sig pickFromTypes = { { 3824 /* pickFromTypes */, 2, 254, 2, 256, ZEND_ACC_PROTECTED } }; +inline constexpr sigtab::Sig toPhpDocNode = { { 3877 /* toPhpDocNode */, 0, 257, 0, 257, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toNativePhpTypeNode = { { 3931 /* toNativePhpTypeNode */, 1, 258, 1, reg::NoArg, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig notBenevolentPickFromTypes = { { 3951 /* notBenevolentPickFromTypes */, 1, 259, 1, 260, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig hasTemplateOrLateResolvableType = { { 3978 /* hasTemplateOrLateResolvableType */, 0, 261, 0, 261, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getPossiblyLooselyEqualType = { { 4010 /* getPossiblyLooselyEqualType */, 1, 262, 1, 263, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig getAlwaysLooselyEqualType = { { 4038 /* getAlwaysLooselyEqualType */, 1, 264, 1, 265, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig toValueSet = { { 4086 /* toValueSet */, 0, 266, 0, 266, ZEND_ACC_PUBLIC } }; } // namespace sig } // namespace ptdecl::UnionType From 747548e4fa30628dd1280d0c90c5c377d4e63e36 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Wed, 11 Nov 2026 06:57:35 +0000 Subject: [PATCH 11/20] Mark closures of static methods and partial applications of functions static PHP binds no object to the closure of a static method, nor to a partial application of a function: bindTo() with an object returns null for them. A function's first-class callable stays bindable, and the closure of an instance method keeps its $this, so they stay as they were. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- .../InitializerExprTypeResolver.php | 5 ++ tests/PHPStan/Analyser/nsrt/bug-11421.php | 10 +-- .../Analyser/nsrt/bug-15169-callables.php | 4 +- .../first-class-callable-native-template.php | 2 +- ...t-class-callables-constant-expressions.php | 2 +- .../Analyser/nsrt/first-class-callables.php | 28 ++++++- ...partial-function-application-signature.php | 80 +++++++++++-------- .../Reflection/AttributeReflectionTest.php | 2 +- .../backed-enum-from-parameter-type-off.php | 8 +- turbo-ext/src/InitializerExprTypeResolver.cpp | 12 +++ 10 files changed, 102 insertions(+), 51 deletions(-) diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index 20d46fbf889..7cf697c64a1 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -948,6 +948,11 @@ public function createFirstClassCallable( $acceptsNamedArguments = $function->acceptsNamedArguments(); $mustUseReturnValue = $function->mustUseReturnValue(); + // binding an object to the closure of a static method, or to a partial + // application of a function, fails; a function's first-class callable can be bound + if ($function instanceof ExtendedMethodReflection ? $function->isStatic() : $partialApplicationArgs !== null) { + $isStaticClosure = TrinaryLogic::createYes(); + } } $parameters = $variant->getParameters(); diff --git a/tests/PHPStan/Analyser/nsrt/bug-11421.php b/tests/PHPStan/Analyser/nsrt/bug-11421.php index 27ca5dda64f..83599c28a10 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-11421.php +++ b/tests/PHPStan/Analyser/nsrt/bug-11421.php @@ -18,9 +18,9 @@ enum WordEnum: string } function (): void { - assertType('Closure(int): Bug11421Types\NumberEnum', NumberEnum::from(...)); - assertNativeType('Closure(int): mixed', NumberEnum::from(...)); - assertType('Closure(int): (Bug11421Types\NumberEnum|null)', NumberEnum::tryFrom(...)); - assertType('Closure(string): Bug11421Types\WordEnum', WordEnum::from(...)); - assertType('Closure(string): (Bug11421Types\WordEnum|null)', WordEnum::tryFrom(...)); + assertType('static-Closure(int): Bug11421Types\NumberEnum', NumberEnum::from(...)); + assertNativeType('static-Closure(int): mixed', NumberEnum::from(...)); + assertType('static-Closure(int): (Bug11421Types\NumberEnum|null)', NumberEnum::tryFrom(...)); + assertType('static-Closure(string): Bug11421Types\WordEnum', WordEnum::from(...)); + assertType('static-Closure(string): (Bug11421Types\WordEnum|null)', WordEnum::tryFrom(...)); }; diff --git a/tests/PHPStan/Analyser/nsrt/bug-15169-callables.php b/tests/PHPStan/Analyser/nsrt/bug-15169-callables.php index 3b377889675..ecae92a3da3 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-15169-callables.php +++ b/tests/PHPStan/Analyser/nsrt/bug-15169-callables.php @@ -45,8 +45,8 @@ function firstClassCallables(C $c): void assertType('Closure(): array{a: int}', $c->info(...)); assertNativeType('Closure(): array', $c->info(...)); - assertType('Closure(): array{a: int}', C::staticInfo(...)); - assertNativeType('Closure(): array', C::staticInfo(...)); + assertType('static-Closure(): array{a: int}', C::staticInfo(...)); + assertNativeType('static-Closure(): array', C::staticInfo(...)); assertType('Closure(): array{a: int}', info(...)); assertNativeType('Closure(): array', info(...)); diff --git a/tests/PHPStan/Analyser/nsrt/first-class-callable-native-template.php b/tests/PHPStan/Analyser/nsrt/first-class-callable-native-template.php index 583929d2d39..d3e97ea67ea 100644 --- a/tests/PHPStan/Analyser/nsrt/first-class-callable-native-template.php +++ b/tests/PHPStan/Analyser/nsrt/first-class-callable-native-template.php @@ -15,7 +15,7 @@ function (PDOStatement $stmt, Foo $foo): void { assertType('Closure>(TArray, int=): true', sort(...)); $create = WeakReference::create(...); - assertType('Closure(TIn): WeakReference', $create); + assertType('static-Closure(TIn): WeakReference', $create); assertType('WeakReference', $create($foo)); $fetch = $stmt->fetchObject(...); diff --git a/tests/PHPStan/Analyser/nsrt/first-class-callables-constant-expressions.php b/tests/PHPStan/Analyser/nsrt/first-class-callables-constant-expressions.php index bc917a7c1d4..569b3f2c35d 100644 --- a/tests/PHPStan/Analyser/nsrt/first-class-callables-constant-expressions.php +++ b/tests/PHPStan/Analyser/nsrt/first-class-callables-constant-expressions.php @@ -26,7 +26,7 @@ public function doFoo(): void assertType('3', (LENGTH)('abc')); assertType('Closure(string): uppercase-string', self::UPPER); assertType("'A'", (self::UPPER)('a')); - assertType('Closure(int): int', self::SELF); + assertType('static-Closure(int): int', self::SELF); assertType('int', (self::SELF)(2)); } diff --git a/tests/PHPStan/Analyser/nsrt/first-class-callables.php b/tests/PHPStan/Analyser/nsrt/first-class-callables.php index 4d965bbf3eb..ab483407103 100644 --- a/tests/PHPStan/Analyser/nsrt/first-class-callables.php +++ b/tests/PHPStan/Analyser/nsrt/first-class-callables.php @@ -12,7 +12,7 @@ class Foo public function doFoo(string $foo): void { assertType('Closure(string): void', $this->doFoo(...)); - assertType('Closure(): void', self::doBar(...)); + assertType('static-Closure(): void', self::doBar(...)); assertType('Closure', self::$foo(...)); assertType('Closure', $this->nonexistent(...)); assertType('Closure', $this->$foo(...)); @@ -140,7 +140,7 @@ public function __call(string $name, array $args): mixed public function doFoo(): void { - assertType('Closure(int): string', self::magicStatic(...)); + assertType('static-Closure(int): string', self::magicStatic(...)); assertType('string', self::magicStatic(...)(1)); assertType('Closure(int): string', $this->magic(...)); assertType('string', $this->magic(...)(1)); @@ -217,3 +217,27 @@ public function doFoo(array $strings, array $ints): void } } + +class BindCallables +{ + + public static function doStatic(): int + { + return 1; + } + + public function doInstance(): int + { + return 1; + } + + public function doFoo(object $o): void + { + assertType('((Closure(string): int<0, max>)|null)', strlen(...)->bindTo($o)); + assertType('null', self::doStatic(...)->bindTo($o)); + assertType('null', \Closure::bind(self::doStatic(...), $o)); + assertType('static-Closure(): int', self::doStatic(...)->bindTo(null)); + assertType('((Closure(): int)|null)', $this->doInstance(...)->bindTo($o)); + } + +} diff --git a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php index 7a3aa178c46..08ef8d48c5d 100644 --- a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php +++ b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php @@ -108,34 +108,34 @@ class Constants function functions(): void { // the cases checked against PHP 8.6 - assertType('Closure(float, bool ...): string', doFoo(1, 'b', ...)); - assertType('Closure(string, float, bool ...): string', doFoo(1, ?, ...)); - assertType('Closure(string, bool ...): string', doFoo(1, ?, 3.0, ...)); - assertType('Closure(string, bool ...): string', doFoo(1, ?, 3.0, true, ...)); - assertType('Closure(bool ...): string', doFoo(1, 'b', 3.0, ...)); - assertType('Closure(string): string', doFoo(1, ?, 3.0)); - assertType('Closure(string): string', doFoo(1, ?, 3.0, true)); - assertType('Closure(bool): string', doFoo(1, 'b', 3.0, true, ?)); - assertType('Closure(bool, bool): string', doFoo(1, 'b', 3.0, ?, ?)); - assertType('Closure(bool, bool ...): string', doFoo(1, 'b', 3.0, ?, ...)); - assertType('Closure(bool ...): string', doFoo(1, 'b', 3.0, x: true, ...)); + assertType('static-Closure(float, bool ...): string', doFoo(1, 'b', ...)); + assertType('static-Closure(string, float, bool ...): string', doFoo(1, ?, ...)); + assertType('static-Closure(string, bool ...): string', doFoo(1, ?, 3.0, ...)); + assertType('static-Closure(string, bool ...): string', doFoo(1, ?, 3.0, true, ...)); + assertType('static-Closure(bool ...): string', doFoo(1, 'b', 3.0, ...)); + assertType('static-Closure(string): string', doFoo(1, ?, 3.0)); + assertType('static-Closure(string): string', doFoo(1, ?, 3.0, true)); + assertType('static-Closure(bool): string', doFoo(1, 'b', 3.0, true, ?)); + assertType('static-Closure(bool, bool): string', doFoo(1, 'b', 3.0, ?, ?)); + assertType('static-Closure(bool, bool ...): string', doFoo(1, 'b', 3.0, ?, ...)); + assertType('static-Closure(bool ...): string', doFoo(1, 'b', 3.0, x: true, ...)); // a placeholder is required even for an optional parameter, ... keeps the optionality - assertType('Closure(int): int', opt(?)); - assertType('Closure(int, string): int', opt(?, ?)); - assertType('Closure(string=, float=): int', opt(1, ...)); - assertType('Closure(): int', opt(1, 'b', 2.0, ...)); - assertType('Closure(int|null, string ...): void', withNullableDefault(?, ...)); + assertType('static-Closure(int): int', opt(?)); + assertType('static-Closure(int, string): int', opt(?, ?)); + assertType('static-Closure(string=, float=): int', opt(1, ...)); + assertType('static-Closure(): int', opt(1, 'b', 2.0, ...)); + assertType('static-Closure(int|null, string ...): void', withNullableDefault(?, ...)); // named placeholders come after the positional ones, in the order they are written, // and before what ... adds - assertType('Closure(float, int, string): string', doFoo(c: ?, a: ?, b: ?)); - assertType('Closure(int, float, string, bool ...): string', doFoo(?, c: ?, ...)); - assertType('Closure(string, int, float=): int', opt(b: ?, ...)); - assertType('Closure(int): int', opt(?, c: 2.0)); + assertType('static-Closure(float, int, string): string', doFoo(c: ?, a: ?, b: ?)); + assertType('static-Closure(int, float, string, bool ...): string', doFoo(?, c: ?, ...)); + assertType('static-Closure(string, int, float=): int', opt(b: ?, ...)); + assertType('static-Closure(int): int', opt(?, c: 2.0)); // by-ref is kept - assertType('Closure(int, string): void', byRef(?, ?)); + assertType('static-Closure(int, string): void', byRef(?, ?)); // the partial application throws when it is created assertType('Closure', doFoo(1, ?)); @@ -148,17 +148,17 @@ function functions(): void assertType('Closure', opt(a: ?, a: ?)); // built-ins - assertType('Closure(string): (non-empty-string|false)', strtok(?)); - assertType('Closure(string, string): (non-empty-string|false)', strtok(?, ?)); - assertType('Closure(string): int<0, max>', strlen(?)); + assertType('static-Closure(string): (non-empty-string|false)', strtok(?)); + assertType('static-Closure(string, string): (non-empty-string|false)', strtok(?, ?)); + assertType('static-Closure(string): int<0, max>', strlen(?)); assertType('Closure', mt_rand(?)); // templates - assertType('Closure(T): T', identity(?)); - assertType('Closure(int): list<\'a\'>', repeat('a', ?)); - assertType('Closure(T): list', repeat(?, 3)); + assertType('static-Closure(T): T', identity(?)); + assertType('static-Closure(int): list<\'a\'>', repeat('a', ?)); + assertType('static-Closure(T): list', repeat(?, 3)); // a template a closure parameter still mentions gets what the bound arguments bring to it - assertType('Closure(T): list<\'x\'|T>', pair(?, 'x')); + assertType('static-Closure(T): list<\'x\'|T>', pair(?, 'x')); $pair = pair(?, 'x'); assertType('list<1|\'x\'>', $pair(1)); } @@ -183,9 +183,9 @@ function methods(Foo $foo): void assertType('Closure(string, float ...): bool', $foo->doFoo(1, ...)); assertType('Closure', $foo->doFoo(?)); - assertType('Closure(int): int', Foo::doStatic(?)); - assertType('Closure(int, string=): int', Foo::doStatic(?, ...)); - assertType('Closure(string): int', Foo::doStatic(1, ?)); + assertType('static-Closure(int): int', Foo::doStatic(?)); + assertType('static-Closure(int, string=): int', Foo::doStatic(?, ...)); + assertType('static-Closure(string): int', Foo::doStatic(1, ?)); assertType('Closure', Foo::doStatic(1, 'b', ?)); } @@ -193,8 +193,8 @@ function closures(Invokable $i): void { assertType('Closure(string): bool', $i(1, ?)); assertType('Closure(int): bool', $i->__invoke(?, 'x')); - assertType('Closure(string, float, bool ...): string', Constants::PARTIAL); - assertType('Closure(int): list<\'a\'>', Constants::REPEATED); + assertType('static-Closure(string, float, bool ...): string', Constants::PARTIAL); + assertType('static-Closure(int): list<\'a\'>', Constants::REPEATED); $c = fn (int $a, string $b, float $c = 1.0): int => 1; assertType('Closure(string): 1', $c(1, ?)); @@ -202,6 +202,16 @@ function closures(Invokable $i): void assertType('Closure', $c(?)); $d = doFoo(1, ?, ...); - assertType('Closure(string): string', $d(?, 3.0)); - assertType('Closure(bool): string', $d('b', 3.0, ?)); + assertType('static-Closure(string): string', $d(?, 3.0)); + assertType('static-Closure(bool): string', $d('b', 3.0, ?)); +} + +function bind(Foo $foo, Invokable $i, object $o): void +{ + assertType('null', doFoo(1, ?, ...)->bindTo($o)); + assertType('null', strlen(?)->bindTo($o)); + assertType('static-Closure(string): string', doFoo(1, ?, 3.0)->bindTo(null)); + assertType('null', Foo::doStatic(1, ?)->bindTo($o)); + assertType('((Closure(string, float ...): bool)|null)', $foo->doFoo(1, ...)->bindTo($o)); + assertType('((Closure(string): bool)|null)', $i(1, ?)->bindTo($o)); } diff --git a/tests/PHPStan/Reflection/AttributeReflectionTest.php b/tests/PHPStan/Reflection/AttributeReflectionTest.php index c23fc3d485c..35144c2f75a 100644 --- a/tests/PHPStan/Reflection/AttributeReflectionTest.php +++ b/tests/PHPStan/Reflection/AttributeReflectionTest.php @@ -161,7 +161,7 @@ public static function dataAttributeReflections(): iterable [ 'ClosureInAttribute\\AttrWithCallback', [ - 'callback' => 'Closure(int): void', + 'callback' => 'static-Closure(int): void', ], ], ], diff --git a/tests/PHPStan/Reflection/Php/data/backed-enum-from-parameter-type-off.php b/tests/PHPStan/Reflection/Php/data/backed-enum-from-parameter-type-off.php index 0309fe076b2..e3f0bd568ae 100644 --- a/tests/PHPStan/Reflection/Php/data/backed-enum-from-parameter-type-off.php +++ b/tests/PHPStan/Reflection/Php/data/backed-enum-from-parameter-type-off.php @@ -17,8 +17,8 @@ enum WordEnum: string } function (): void { - assertType('Closure(int|string): BackedEnumFromParameterTypeOff\NumberEnum', NumberEnum::from(...)); - assertType('Closure(int|string): (BackedEnumFromParameterTypeOff\NumberEnum|null)', NumberEnum::tryFrom(...)); - assertType('Closure(int|string): BackedEnumFromParameterTypeOff\WordEnum', WordEnum::from(...)); - assertType('Closure(int|string): (BackedEnumFromParameterTypeOff\WordEnum|null)', WordEnum::tryFrom(...)); + assertType('static-Closure(int|string): BackedEnumFromParameterTypeOff\NumberEnum', NumberEnum::from(...)); + assertType('static-Closure(int|string): (BackedEnumFromParameterTypeOff\NumberEnum|null)', NumberEnum::tryFrom(...)); + assertType('static-Closure(int|string): BackedEnumFromParameterTypeOff\WordEnum', WordEnum::from(...)); + assertType('static-Closure(int|string): (BackedEnumFromParameterTypeOff\WordEnum|null)', WordEnum::tryFrom(...)); }; diff --git a/turbo-ext/src/InitializerExprTypeResolver.cpp b/turbo-ext/src/InitializerExprTypeResolver.cpp index c62994b41f7..ae1a8b8c2f4 100644 --- a/turbo-ext/src/InitializerExprTypeResolver.cpp +++ b/turbo-ext/src/InitializerExprTypeResolver.cpp @@ -2496,6 +2496,18 @@ class InitializerExprTypeResolver if (UNEXPECTED(acceptsNamedArguments.isUndef())) return zv::Val(); mustUseReturnValue = callOn(function, mMustUseReturnValue); if (UNEXPECTED(mustUseReturnValue.isUndef())) return zv::Val(); + // binding an object to the closure of a static method, or to a partial + // application of a function, fails; a function's first-class callable can be bound + zend_class_entry *methodReflectionCe = pt_class(PT_CLASS_EXTENDED_METHOD_REFLECTION); + if (UNEXPECTED(methodReflectionCe == NULL)) return zv::Val(); + bool staticClosure = partialApplication; + if (instanceof_function(Z_OBJCE_P(function), methodReflectionCe)) { + IETR_VAL(isStaticMethod, callOn(function, mIsStatic)); + staticClosure = zend_is_true(isStaticMethod.raw()); + } + if (staticClosure) { + isStaticClosure = zv::Val::copyOf(zv::Ref(pt_trinary_singleton(PT_TRI_YES))); + } } IETR_VAL(variantParameters, callOn(variant, mGetParameters)); From 67a98ae5f2f6d54ad4b49eb982df30d55dce3438 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Wed, 11 Nov 2026 07:25:46 +0000 Subject: [PATCH 12/20] Report placeholder placements PHP refuses to compile whatever the callee is A variadic placeholder before another argument, and partial application combined with unpacking, are compile errors in PHP, but they were only reported once the callee resolved: undefinedFn(..., ?) or $mixed(..., ?) went unreported. The callable rules now check the placements first and report only them, since nothing else about such a call matters. A second variadic placeholder is reported like PHP does, "Variadic placeholder may only appear once.", and no closure signature is inferred for it. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- .../PartialFunctionApplicationParameters.php | 10 ++-- src/Rules/FunctionCallParametersCheck.php | 55 +++++++++++++++---- src/Rules/Functions/FunctionCallableRule.php | 5 ++ src/Rules/Methods/MethodCallableRule.php | 5 ++ .../Methods/StaticMethodCallableRule.php | 5 ++ ...partial-function-application-signature.php | 1 + .../Functions/FunctionCallableRuleTest.php | 24 ++++++++ ...partial-function-application-arguments.php | 16 ++++++ .../Rules/Methods/MethodCallableRuleTest.php | 12 ++++ .../Methods/StaticMethodCallableRuleTest.php | 12 ++++ ...-function-application-method-arguments.php | 16 ++++++ 11 files changed, 147 insertions(+), 14 deletions(-) diff --git a/src/Reflection/PartialFunctionApplicationParameters.php b/src/Reflection/PartialFunctionApplicationParameters.php index 340d1b30014..efe060c3234 100644 --- a/src/Reflection/PartialFunctionApplicationParameters.php +++ b/src/Reflection/PartialFunctionApplicationParameters.php @@ -17,6 +17,8 @@ use PHPStan\Type\TypeTraverser; use function array_key_exists; use function count; +use function max; +use function min; /** * Maps the parameters of a callee to the parameters of the closure its partial @@ -166,14 +168,14 @@ private static function map(array $parameters, array $args): ?array $seenNamed = false; $bound = []; foreach ($args as $argIndex => $arg) { + if ($hasVariadicPlaceholder) { + // the variadic placeholder must be last and may only appear once + return null; + } if ($arg instanceof VariadicPlaceholder) { $hasVariadicPlaceholder = true; continue; } - if ($hasVariadicPlaceholder) { - // the variadic placeholder must be last - return null; - } if ($arg instanceof Arg && $arg->unpack) { // cannot combine partial application and unpacking diff --git a/src/Rules/FunctionCallParametersCheck.php b/src/Rules/FunctionCallParametersCheck.php index d5511a1da4e..249c3ecc340 100644 --- a/src/Rules/FunctionCallParametersCheck.php +++ b/src/Rules/FunctionCallParametersCheck.php @@ -162,11 +162,7 @@ public function check( $errors = []; foreach ($args as $arg) { if ($hasVariadicPlaceholder) { - $errors[] = RuleErrorBuilder::message('Variadic placeholder must be last.') - ->identifier('argument.variadicPlaceholderNotLast') - ->line($arg->getStartLine()) - ->nonIgnorable() - ->build(); + // reported by checkPartialApplicationSyntax() break; } if ($arg instanceof Node\VariadicPlaceholder) { @@ -184,11 +180,7 @@ public function check( } if ($isPartialApplication && $arg->unpack) { - $errors[] = RuleErrorBuilder::message('Cannot combine partial application and unpacking.') - ->identifier('argument.unpackInPartialApplication') - ->line($arg->getStartLine()) - ->nonIgnorable() - ->build(); + // reported by checkPartialApplicationSyntax() continue; } @@ -757,6 +749,49 @@ static function (Type $type, callable $traverse) use (&$returnTemplateTypes): Ty return $errors; } + /** + * The placements of placeholders PHP refuses to compile, whatever the callee is. + * + * @return list + */ + public function checkPartialApplicationSyntax(Node\Expr\CallLike $call): array + { + $errors = []; + $hasVariadicPlaceholder = false; + foreach ($call->getRawArgs() as $arg) { + if ($hasVariadicPlaceholder) { + // PHP judges the argument right after the variadic placeholder + if ($arg instanceof Node\VariadicPlaceholder) { + $errorBuilder = RuleErrorBuilder::message('Variadic placeholder may only appear once.') + ->identifier('argument.duplicateVariadicPlaceholder'); + } else { + $errorBuilder = RuleErrorBuilder::message('Variadic placeholder must be last.') + ->identifier('argument.variadicPlaceholderNotLast'); + } + $errors[] = $errorBuilder + ->line($arg->getStartLine()) + ->nonIgnorable() + ->build(); + break; + } + if ($arg instanceof Node\VariadicPlaceholder) { + $hasVariadicPlaceholder = true; + continue; + } + if (!$arg instanceof Node\Arg || !$arg->unpack) { + continue; + } + + $errors[] = RuleErrorBuilder::message('Cannot combine partial application and unpacking.') + ->identifier('argument.unpackInPartialApplication') + ->line($arg->getStartLine()) + ->nonIgnorable() + ->build(); + } + + return $errors; + } + /** * Checks the bound arguments and placeholders of a partial function application * against the callee: PHP throws when such a closure is created from arguments diff --git a/src/Rules/Functions/FunctionCallableRule.php b/src/Rules/Functions/FunctionCallableRule.php index 7f1430d3a34..13cedad8e63 100644 --- a/src/Rules/Functions/FunctionCallableRule.php +++ b/src/Rules/Functions/FunctionCallableRule.php @@ -76,6 +76,11 @@ public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataE ->build(), ]; } + // compile errors, even when the callee is unknown + $syntaxErrors = $this->parametersCheck->checkPartialApplicationSyntax($node->getOriginalNode()); + if ($syntaxErrors !== []) { + return $syntaxErrors; + } } elseif (!$scope->getPhpVersion()->supportsFirstClassCallables()->yes()) { return [ RuleErrorBuilder::message('First-class callables are supported only on PHP 8.1 and later.') diff --git a/src/Rules/Methods/MethodCallableRule.php b/src/Rules/Methods/MethodCallableRule.php index 13133f7fb2d..7eb5c3a172a 100644 --- a/src/Rules/Methods/MethodCallableRule.php +++ b/src/Rules/Methods/MethodCallableRule.php @@ -45,6 +45,11 @@ public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataE ->build(), ]; } + // compile errors, even when the callee is unknown + $syntaxErrors = $this->parametersCheck->checkPartialApplicationSyntax($node->getOriginalNode()); + if ($syntaxErrors !== []) { + return $syntaxErrors; + } } elseif (!$scope->getPhpVersion()->supportsFirstClassCallables()->yes()) { return [ RuleErrorBuilder::message('First-class callables are supported only on PHP 8.1 and later.') diff --git a/src/Rules/Methods/StaticMethodCallableRule.php b/src/Rules/Methods/StaticMethodCallableRule.php index 73098347ac5..1b947da8991 100644 --- a/src/Rules/Methods/StaticMethodCallableRule.php +++ b/src/Rules/Methods/StaticMethodCallableRule.php @@ -45,6 +45,11 @@ public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataE ->build(), ]; } + // compile errors, even when the callee is unknown + $syntaxErrors = $this->parametersCheck->checkPartialApplicationSyntax($node->getOriginalNode()); + if ($syntaxErrors !== []) { + return $syntaxErrors; + } } elseif (!$scope->getPhpVersion()->supportsFirstClassCallables()->yes()) { return [ RuleErrorBuilder::message('First-class callables are supported only on PHP 8.1 and later.') diff --git a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php index 08ef8d48c5d..8579daaaa73 100644 --- a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php +++ b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php @@ -146,6 +146,7 @@ function functions(): void assertType('Closure', doFoo(1, 'b', 3.0, d: ?)); assertType('Closure', opt(?, a: 1)); assertType('Closure', opt(a: ?, a: ?)); + assertType('Closure', doFoo(?, ..., ...)); // built-ins assertType('static-Closure(string): (non-empty-string|false)', strtok(?)); diff --git a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php index 2e05afb4abb..0aa63dbcc19 100644 --- a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php +++ b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php @@ -240,6 +240,30 @@ public function testPartialFunctionApplicationArguments(): void 'Parameter #1 $a of function PartialFunctionApplicationArguments\\intOnly expects int, string given.', 75, ], + [ + 'Variadic placeholder must be last.', + 82, + ], + [ + 'Cannot combine partial application and unpacking.', + 83, + ], + [ + 'Variadic placeholder must be last.', + 84, + ], + [ + 'Variadic placeholder may only appear once.', + 89, + ], + [ + 'Variadic placeholder may only appear once.', + 90, + ], + [ + 'Variadic placeholder must be last.', + 91, + ], ]); } diff --git a/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php b/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php index 393d9e2e053..3395a1e7e34 100644 --- a/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php +++ b/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php @@ -74,3 +74,19 @@ function templates(): void intOnly(1, ...); intOnly('x', ...); } + +/** @param array $ints */ +function placementsWithUnknownCallees(mixed $cb, array $ints): void +{ + // compile errors whatever the callee is + undefinedFunction(..., ?); + undefinedFunction(?, ...$ints); + $cb(..., ?); +} + +function variadicPlaceholderPlacements(): void +{ + doFoo(?, ..., ...); + doFoo(1, ..., ..., ?); + doFoo(1, ..., c: 5.0); +} diff --git a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php index 1ded97619c1..ef957d5908d 100644 --- a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php @@ -132,6 +132,18 @@ public function testPartialFunctionApplicationArguments(): void 'Cannot use named placeholder for unknown or variadic parameter $c.', 30, ], + [ + 'Variadic placeholder must be last.', + 42, + ], + [ + 'Cannot combine partial application and unpacking.', + 43, + ], + [ + 'Variadic placeholder may only appear once.', + 50, + ], ]); } diff --git a/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php index f312967b65c..fd7b34cbd14 100644 --- a/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php @@ -155,6 +155,18 @@ public function testPartialFunctionApplicationArguments(): void 'Argument for parameter $a has already been passed.', 33, ], + [ + 'Variadic placeholder must be last.', + 44, + ], + [ + 'Cannot combine partial application and unpacking.', + 45, + ], + [ + 'Variadic placeholder may only appear once.', + 51, + ], ]); } diff --git a/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php b/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php index b70498b4b2c..a272bbb66fe 100644 --- a/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php +++ b/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php @@ -34,3 +34,19 @@ public function test(): void } } + +/** @param array $ints */ +function placementsWithUnknownCallees(Foo $foo, array $ints): void +{ + // compile errors whatever the callee is + $foo->undefinedMethod(..., ?); + $foo->undefinedMethod(?, ...$ints); + Foo::undefinedStatic(..., ?); + Foo::undefinedStatic(?, ...$ints); +} + +function variadicPlaceholderPlacements(Foo $foo): void +{ + $foo->doFoo(?, ..., ...); + Foo::doStatic(?, ..., ...); +} From 8cd32a1b44eb0e070582c16059f9c19debe18fce Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Wed, 11 Nov 2026 07:25:55 +0000 Subject: [PATCH 13/20] Give Closure::__invoke() the signature of the closure it is called on Calling $closure->__invoke() returned mixed and took any arguments, and its first-class callable and partial applications, $closure->__invoke(...) and $closure->__invoke(1, ?), lost the closure's parameters. __invoke() now takes the closure's parameters and returns its return type, like call() does after the object it binds. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- .../Php/ClosureCallMethodReflection.php | 21 ++++++++++--------- ...allUnresolvedMethodPrototypeReflection.php | 11 ++++++---- src/Type/ClosureType.php | 4 +++- .../Analyser/nsrt/first-class-callables.php | 10 +++++++++ ...partial-function-application-signature.php | 1 + .../Rules/Methods/CallMethodsRuleTest.php | 4 ++++ turbo-ext/src/ClosureType.cpp | 13 ++++++------ 7 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/Reflection/Php/ClosureCallMethodReflection.php b/src/Reflection/Php/ClosureCallMethodReflection.php index a65a321a4c4..cae15b9d9ea 100644 --- a/src/Reflection/Php/ClosureCallMethodReflection.php +++ b/src/Reflection/Php/ClosureCallMethodReflection.php @@ -28,6 +28,7 @@ final class ClosureCallMethodReflection implements ExtendedMethodReflection public function __construct( private ExtendedMethodReflection $nativeMethodReflection, private ClosureType $closureType, + private bool $takesNewThis = true, ) { } @@ -70,16 +71,16 @@ public function getPrototype(): ClassMemberReflection public function getVariants(): array { $parameters = $this->closureType->getParameters(); - $newThis = new NativeParameterReflection( - 'newThis', - optional: false, - type: new ObjectWithoutClassType(), - passedByReference: PassedByReference::createNo(), - variadic: false, - defaultValue: null, - ); - - array_unshift($parameters, $newThis); + if ($this->takesNewThis) { + array_unshift($parameters, new NativeParameterReflection( + 'newThis', + optional: false, + type: new ObjectWithoutClassType(), + passedByReference: PassedByReference::createNo(), + variadic: false, + defaultValue: null, + )); + } return [ new ExtendedFunctionVariant( diff --git a/src/Reflection/Php/ClosureCallUnresolvedMethodPrototypeReflection.php b/src/Reflection/Php/ClosureCallUnresolvedMethodPrototypeReflection.php index 58ef40513d9..91073ba2b32 100644 --- a/src/Reflection/Php/ClosureCallUnresolvedMethodPrototypeReflection.php +++ b/src/Reflection/Php/ClosureCallUnresolvedMethodPrototypeReflection.php @@ -12,13 +12,16 @@ final class ClosureCallUnresolvedMethodPrototypeReflection implements UnresolvedMethodPrototypeReflection { - public function __construct(private UnresolvedMethodPrototypeReflection $prototype, private ClosureType $closure) + /** + * @param bool $takesNewThis whether the method takes the object to bind first, like call() and unlike __invoke() + */ + public function __construct(private UnresolvedMethodPrototypeReflection $prototype, private ClosureType $closure, private bool $takesNewThis = true) { } public function doNotResolveTemplateTypeMapToBounds(): UnresolvedMethodPrototypeReflection { - return new self($this->prototype->doNotResolveTemplateTypeMapToBounds(), $this->closure); + return new self($this->prototype->doNotResolveTemplateTypeMapToBounds(), $this->closure, $this->takesNewThis); } public function getNakedMethod(): ExtendedMethodReflection @@ -28,12 +31,12 @@ public function getNakedMethod(): ExtendedMethodReflection public function getTransformedMethod(): ExtendedMethodReflection { - return new ClosureCallMethodReflection($this->prototype->getTransformedMethod(), $this->closure); + return new ClosureCallMethodReflection($this->prototype->getTransformedMethod(), $this->closure, $this->takesNewThis); } public function withCalledOnType(Type $type): UnresolvedMethodPrototypeReflection { - return new self($this->prototype->withCalledOnType($type), $this->closure); + return new self($this->prototype->withCalledOnType($type), $this->closure, $this->takesNewThis); } } diff --git a/src/Type/ClosureType.php b/src/Type/ClosureType.php index 70e8f5f203d..3e0731026f9 100644 --- a/src/Type/ClosureType.php +++ b/src/Type/ClosureType.php @@ -57,6 +57,7 @@ use function array_map; use function array_merge; use function count; +use function in_array; /** @api */ #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/ClosureType.cpp')] @@ -507,10 +508,11 @@ public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope): public function getUnresolvedMethodPrototype(string $methodName, ClassMemberAccessAnswerer $scope): UnresolvedMethodPrototypeReflection { - if ($methodName === 'call') { + if (in_array($methodName, ['call', '__invoke'], true)) { return new ClosureCallUnresolvedMethodPrototypeReflection( $this->objectType->getUnresolvedMethodPrototype($methodName, $scope), $this, + $methodName === 'call', ); } diff --git a/tests/PHPStan/Analyser/nsrt/first-class-callables.php b/tests/PHPStan/Analyser/nsrt/first-class-callables.php index ab483407103..4953a0e0ae7 100644 --- a/tests/PHPStan/Analyser/nsrt/first-class-callables.php +++ b/tests/PHPStan/Analyser/nsrt/first-class-callables.php @@ -240,4 +240,14 @@ public function doFoo(object $o): void assertType('((Closure(): int)|null)', $this->doInstance(...)->bindTo($o)); } + public function doInvoke(): void + { + $c = function (int $a, string $b, ?float $c = null): int { + return 1; + }; + assertType('1', $c->__invoke(1, 'x')); + assertType('Closure(int, string, float|null=): 1', $c->__invoke(...)); + assertType('((Closure(int, string, float|null=): 1)|null)', $c->__invoke(...)->bindTo(null)); + } + } diff --git a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php index 8579daaaa73..381f1446825 100644 --- a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php +++ b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php @@ -199,6 +199,7 @@ function closures(Invokable $i): void $c = fn (int $a, string $b, float $c = 1.0): int => 1; assertType('Closure(string): 1', $c(1, ?)); + assertType('Closure(string): 1', $c->__invoke(1, ?)); assertType('Closure(string, float=): 1', $c(1, ...)); assertType('Closure', $c(?)); diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index 62658809769..f89498c3be5 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -231,6 +231,10 @@ public function testCallMethods(): void 'Method PDO::query() invoked with 0 parameters, 1-4 required.', 113, ], + [ + 'Method Closure::__invoke() invoked with 3 parameters, 0 required.', + 139, + ], [ 'Parameter #1 $bar of method Test\ClassWithNullableProperty::doBar() is passed by reference, so it expects variables only.', 167, diff --git a/turbo-ext/src/ClosureType.cpp b/turbo-ext/src/ClosureType.cpp index 2744a9474fe..deb3769e126 100644 --- a/turbo-ext/src/ClosureType.cpp +++ b/turbo-ext/src/ClosureType.cpp @@ -610,17 +610,18 @@ class ClosureType return pt_type_transformed_member(self, PT_LC("getunresolvedmethodprototype"), true, methodName, scope); } - /* the object type's prototype, wrapped for `call` in a - * ClosureCallUnresolvedMethodPrototypeReflection over $this; UNDEF = - * pending exception */ + /* the object type's prototype, wrapped for `call` and `__invoke` in a + * ClosureCallUnresolvedMethodPrototypeReflection over $this (taking the + * new $this first for `call` only); UNDEF = pending exception */ zv::Val getUnresolvedMethodPrototype(zval *methodName, zval *scope) const { zv::Args args{methodName, scope}; - if (zv::Ref(methodName).stringEquals("call")) { + bool isCall = zv::Ref(methodName).stringEquals("call"); + if (isCall || zv::Ref(methodName).stringEquals("__invoke")) { zv::Val prototype = delegate(PT_LC("getunresolvedmethodprototype"), 2, args); if (UNEXPECTED(prototype.isUndef())) return zv::Val(); - zv::Args wrapArgs{prototype.raw(), self}; - return pt_type_new(PT_CLASS_CLOSURE_CALL_UNRESOLVED_METHOD_PROTOTYPE_REFLECTION, 2, wrapArgs); + zv::Args wrapArgs{prototype.raw(), self, isCall}; + return pt_type_new(PT_CLASS_CLOSURE_CALL_UNRESOLVED_METHOD_PROTOTYPE_REFLECTION, 3, wrapArgs); } return delegate(PT_LC("getunresolvedmethodprototype"), 2, args); } From fb7e9db5d65091eeacbbd762816a61fd8ee04153 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Wed, 11 Nov 2026 07:26:03 +0000 Subject: [PATCH 14/20] Infer null from unbinding the closure of an instance method PHP keeps the object a method was called on as the $this of its closure: $object->method(...)->bindTo(null), like the same of a partial application, returns null with a warning. Closure::__invoke(...) is the closure itself, so it stays unbindable or not like the closure is. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- src/Type/ClosureOrigin.php | 13 +++++++++++++ .../Php/ClosureBindDynamicReturnTypeExtension.php | 7 ++++++- .../Php/ClosureBindToDynamicReturnTypeExtension.php | 9 +++++++-- .../PHPStan/Analyser/nsrt/first-class-callables.php | 8 +++++++- .../nsrt/partial-function-application-signature.php | 1 + 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/Type/ClosureOrigin.php b/src/Type/ClosureOrigin.php index 2a84ae23efe..2748baaf9b9 100644 --- a/src/Type/ClosureOrigin.php +++ b/src/Type/ClosureOrigin.php @@ -2,6 +2,7 @@ namespace PHPStan\Type; +use Closure; use PhpParser\Node\Arg; use PhpParser\Node\ArgPlaceholder; use PhpParser\Node\Expr\CallLike; @@ -100,6 +101,18 @@ public function getBoundParameterNames(): array return $this->boundParameterNames; } + /** + * Whether the closure is one of a method called on an object, bound to that object for + * good: unbinding it fails. Closure::__invoke(...) is the closure itself, so it does not count. + */ + public function keepsCalledOnObject(): bool + { + return $this->methodName !== null + && !$this->isStaticCall + && $this->calledOnType !== null + && (new ObjectType(Closure::class))->isSuperTypeOf($this->calledOnType)->no(); + } + /** * The answers of a union's members combined per closure the union can hold. Closures * created from the same callable with the same arguments are one closure, overloaded diff --git a/src/Type/Php/ClosureBindDynamicReturnTypeExtension.php b/src/Type/Php/ClosureBindDynamicReturnTypeExtension.php index 1234067633d..d07ec840917 100644 --- a/src/Type/Php/ClosureBindDynamicReturnTypeExtension.php +++ b/src/Type/Php/ClosureBindDynamicReturnTypeExtension.php @@ -40,8 +40,8 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, return null; } + $newThisIsNull = isset($args[1]) ? $scope->getType($args[1]->value)->isNull() : TrinaryLogic::createYes(); if ($closureType->isStaticClosure()->yes()) { - $newThisIsNull = isset($args[1]) ? $scope->getType($args[1]->value)->isNull() : TrinaryLogic::createYes(); if ($newThisIsNull->yes()) { return $closureType; } @@ -52,6 +52,11 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, return new BenevolentUnionType([$closureType, new NullType()]); } + $origin = $closureType->getOrigin(); + if ($newThisIsNull->yes() && $origin !== null && $origin->keepsCalledOnObject()) { + return new NullType(); + } + return new BenevolentUnionType([$closureType, new NullType()]); } diff --git a/src/Type/Php/ClosureBindToDynamicReturnTypeExtension.php b/src/Type/Php/ClosureBindToDynamicReturnTypeExtension.php index dc9aaf33a6f..1517b1b5b84 100644 --- a/src/Type/Php/ClosureBindToDynamicReturnTypeExtension.php +++ b/src/Type/Php/ClosureBindToDynamicReturnTypeExtension.php @@ -35,9 +35,9 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method return null; } + $args = $methodCall->getArgs(); + $newThisIsNull = isset($args[0]) ? $scope->getType($args[0]->value)->isNull() : TrinaryLogic::createYes(); if ($closureType->isStaticClosure()->yes()) { - $args = $methodCall->getArgs(); - $newThisIsNull = isset($args[0]) ? $scope->getType($args[0]->value)->isNull() : TrinaryLogic::createYes(); if ($newThisIsNull->yes()) { return $closureType; } @@ -48,6 +48,11 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method return new BenevolentUnionType([$closureType, new NullType()]); } + $origin = $closureType->getOrigin(); + if ($newThisIsNull->yes() && $origin !== null && $origin->keepsCalledOnObject()) { + return new NullType(); + } + return new BenevolentUnionType([$closureType, new NullType()]); } diff --git a/tests/PHPStan/Analyser/nsrt/first-class-callables.php b/tests/PHPStan/Analyser/nsrt/first-class-callables.php index 4953a0e0ae7..b9392e2d8b8 100644 --- a/tests/PHPStan/Analyser/nsrt/first-class-callables.php +++ b/tests/PHPStan/Analyser/nsrt/first-class-callables.php @@ -231,13 +231,19 @@ public function doInstance(): int return 1; } - public function doFoo(object $o): void + public function doFoo(object $o, ?object $maybe): void { assertType('((Closure(string): int<0, max>)|null)', strlen(...)->bindTo($o)); assertType('null', self::doStatic(...)->bindTo($o)); assertType('null', \Closure::bind(self::doStatic(...), $o)); assertType('static-Closure(): int', self::doStatic(...)->bindTo(null)); assertType('((Closure(): int)|null)', $this->doInstance(...)->bindTo($o)); + // the closure of an instance method keeps its object + assertType('null', $this->doInstance(...)->bindTo(null)); + assertType('null', \Closure::bind($this->doInstance(...), null)); + // only unbinding it for sure returns null + assertType('((Closure(): int)|null)', $this->doInstance(...)->bindTo($maybe)); + assertType('((Closure(): int)|null)', \Closure::bind($this->doInstance(...), $maybe)); } public function doInvoke(): void diff --git a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php index 381f1446825..a55afeb0c00 100644 --- a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php +++ b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php @@ -215,5 +215,6 @@ function bind(Foo $foo, Invokable $i, object $o): void assertType('static-Closure(string): string', doFoo(1, ?, 3.0)->bindTo(null)); assertType('null', Foo::doStatic(1, ?)->bindTo($o)); assertType('((Closure(string, float ...): bool)|null)', $foo->doFoo(1, ...)->bindTo($o)); + assertType('null', $foo->doFoo(1, ...)->bindTo(null)); assertType('((Closure(string): bool)|null)', $i(1, ?)->bindTo($o)); } From c25af9b4ca8e6be80ea9da6eb7212ea8d6f6ad03 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Wed, 11 Nov 2026 07:26:14 +0000 Subject: [PATCH 15/20] Keep a partial application with ... variadic when its callee is A function calling func_get_args() takes more arguments than its parameters, and the variadic placeholder forwards a call's extra arguments to it, so f(?, ...)(1, 2, 3) is a call PHP passes all three to. The closure was variadic only when the callee had a variadic parameter. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- src/Reflection/InitializerExprTypeResolver.php | 2 +- .../PartialFunctionApplicationParameters.php | 12 +++++++----- .../partial-function-application-closure-calls.php | 11 +++++++++++ turbo-ext/src/InitializerExprTypeResolver.cpp | 4 ++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index 7cf697c64a1..0ccf6e9120c 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -963,7 +963,7 @@ public function createFirstClassCallable( $templateTypeMap = $variant->getTemplateTypeMap(); $variantOrigin = $origin; if ($partialApplicationArgs !== null) { - $partialApplication = PartialFunctionApplicationParameters::apply($parameters, $partialApplicationArgs, $boundArgTypes, $returnType, $templateTypeMap); + $partialApplication = PartialFunctionApplicationParameters::apply($parameters, $isVariadic, $partialApplicationArgs, $boundArgTypes, $returnType, $templateTypeMap); if ($partialApplication === null) { // creating the closure from this variant throws continue; diff --git a/src/Reflection/PartialFunctionApplicationParameters.php b/src/Reflection/PartialFunctionApplicationParameters.php index efe060c3234..3c134ecc474 100644 --- a/src/Reflection/PartialFunctionApplicationParameters.php +++ b/src/Reflection/PartialFunctionApplicationParameters.php @@ -51,13 +51,14 @@ final class PartialFunctionApplicationParameters * still mentions is joined with it, since a call unions what both bring to it. * * @param list $parameters + * @param bool $isVariadic whether the callee takes more arguments than its parameters, like one calling func_get_args() * @param array $args * @param array $boundArgTypes the types of the bound arguments, keyed like $args * @return array{list, bool, Type, TemplateTypeMap, list}|null null when creating the closure throws */ - public static function apply(array $parameters, array $args, array $boundArgTypes, Type $returnType, TemplateTypeMap $templateTypeMap): ?array + public static function apply(array $parameters, bool $isVariadic, array $args, array $boundArgTypes, Type $returnType, TemplateTypeMap $templateTypeMap): ?array { - $mapped = self::map($parameters, $args); + $mapped = self::map($parameters, $isVariadic, $args); if ($mapped === null) { return null; } @@ -145,7 +146,7 @@ private static function isOwnTemplate(Type $type, TemplateTypeMap $templateTypeM * @return array{list, bool, list}|null the closure's parameters, * whether it is variadic and the parameters the bound arguments go to, null when creating the closure throws */ - private static function map(array $parameters, array $args): ?array + private static function map(array $parameters, bool $isVariadic, array $args): ?array { $variadicParameter = null; $declared = $parameters; @@ -259,7 +260,8 @@ private static function map(array $parameters, array $args): ?array $closureParameters[] = $variadicParameter; } - return [$closureParameters, $variadicParameter !== null, $bound]; + // the variadic placeholder forwards the extra arguments to the callee + return [$closureParameters, $isVariadic, $bound]; } /** @@ -303,7 +305,7 @@ public static function selectVariant(array $args, array $variants, ?array $named $fitting = []; foreach ($variants as $variant) { - if (self::map($variant->getParameters(), $args) === null) { + if (self::map($variant->getParameters(), $variant->isVariadic(), $args) === null) { continue; } $fitting[] = $variant; diff --git a/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php b/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php index 0f9dede417d..0f88ccca11b 100644 --- a/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php +++ b/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php @@ -61,3 +61,14 @@ function bound(bool $flag): void $m = $flag ? doFoo(1, 'b', ?, ...) : static fn (float $c, bool ...$d): string => ''; $m(1.0, a: true); } + +function forwardsToFuncGetArgs($a): array +{ + return func_get_args(); +} + +function forwardedArguments(): void +{ + // the variadic placeholder forwards the extra arguments to func_get_args() + forwardsToFuncGetArgs(?, ...)(1, 2, 3); +} diff --git a/turbo-ext/src/InitializerExprTypeResolver.cpp b/turbo-ext/src/InitializerExprTypeResolver.cpp index ae1a8b8c2f4..d0583018e69 100644 --- a/turbo-ext/src/InitializerExprTypeResolver.cpp +++ b/turbo-ext/src/InitializerExprTypeResolver.cpp @@ -2523,8 +2523,8 @@ class InitializerExprTypeResolver zv::Val variantOrigin = zv::Val::copyOf(zv::Ref(origin.raw())); if (partialApplication) { static pt_method_site applySite; - zv::Args applyArgv{parameters.raw(), partialApplicationArgs, boundArgTypes, returnType.raw(), templateTypeMap.raw()}; - IETR_VAL(applied, pt_call_static_cached(applySite, PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS, PT_LC("apply"), 5, applyArgv)); + zv::Args applyArgv{parameters.raw(), isVariadic, partialApplicationArgs, boundArgTypes, returnType.raw(), templateTypeMap.raw()}; + IETR_VAL(applied, pt_call_static_cached(applySite, PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS, PT_LC("apply"), 6, applyArgv)); if (Z_TYPE_P(applied.raw()) == IS_NULL) { // creating the closure from this variant throws continue; From 4d328c9b30e9b3cd87e10610a57eaa876b4fd754 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Wed, 11 Nov 2026 07:26:24 +0000 Subject: [PATCH 16/20] Name the parameters of a magic method's partial application like PHP does PHP calls a method it does not declare through the __call() or __callStatic() trampoline, (mixed ...$arguments), so the closure of its partial application takes its placeholders as $arguments0, $arguments1..., whatever names @method gives the parameters, and a named placeholder makes creating it throw. Calling the closure with the @method names was accepted although PHP rejects them as unknown. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- .../InitializerExprTypeResolver.php | 5 +++ .../PartialFunctionApplicationParameters.php | 36 +++++++++++++++++++ src/Rules/FunctionCallParametersCheck.php | 18 ++++++++++ .../Rules/Functions/CallCallablesRuleTest.php | 8 +++++ ...ial-function-application-closure-calls.php | 21 +++++++++++ .../Rules/Methods/MethodCallableRuleTest.php | 6 +++- .../Methods/StaticMethodCallableRuleTest.php | 6 +++- ...-function-application-method-arguments.php | 28 +++++++++++++++ turbo-ext/src/InitializerExprTypeResolver.cpp | 9 +++++ 9 files changed, 135 insertions(+), 2 deletions(-) diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index 0ccf6e9120c..eb2598947b9 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -969,6 +969,11 @@ public function createFirstClassCallable( continue; } [$parameters, $isVariadic, $returnType, $templateTypeMap, $boundParameterNames] = $partialApplication; + $magicMethodParameterNames = PartialFunctionApplicationParameters::getMagicMethodParameterNames($function, $partialApplicationArgs); + if ($magicMethodParameterNames === null) { + continue; + } + $parameters = self::renameParameters($parameters, $magicMethodParameterNames); if ($variantOrigin !== null) { $variantOrigin = $variantOrigin->withBoundParameterNames($boundParameterNames); } diff --git a/src/Reflection/PartialFunctionApplicationParameters.php b/src/Reflection/PartialFunctionApplicationParameters.php index 3c134ecc474..1d7655c9a90 100644 --- a/src/Reflection/PartialFunctionApplicationParameters.php +++ b/src/Reflection/PartialFunctionApplicationParameters.php @@ -127,6 +127,42 @@ public static function apply(array $parameters, bool $isVariadic, array $args, a return [$closureParameters, $isVariadic, $returnType, new TemplateTypeMap($closureTemplateTypes), $boundNames]; } + /** + * PHP calls a method it does not declare through __call() or __callStatic(), so the + * closure of its partial application is one of that trampoline, (mixed ...$arguments): + * the placeholders become $arguments0, $arguments1..., and a named one throws. + * + * @param array $args + * @return list|null the names of the closure's first parameters, the ones of its + * positional placeholders; null when creating the closure throws + */ + public static function getMagicMethodParameterNames(FunctionReflection|MethodReflection|null $function, array $args): ?array + { + if (!self::isMagicMethod($function)) { + return []; + } + + $names = []; + foreach ($args as $arg) { + if (!$arg instanceof ArgPlaceholder) { + continue; + } + if ($arg->name !== null) { + return null; + } + $names[] = 'arguments' . count($names); + } + + return $names; + } + + /** @phpstan-assert-if-true MethodReflection $function */ + public static function isMagicMethod(FunctionReflection|MethodReflection|null $function): bool + { + return $function instanceof MethodReflection + && !$function->getDeclaringClass()->hasNativeMethod($function->getName()); + } + /** * @phpstan-assert-if-true TemplateType $type */ diff --git a/src/Rules/FunctionCallParametersCheck.php b/src/Rules/FunctionCallParametersCheck.php index 249c3ecc340..4c2a0b69637 100644 --- a/src/Rules/FunctionCallParametersCheck.php +++ b/src/Rules/FunctionCallParametersCheck.php @@ -20,6 +20,7 @@ use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParameterReflection; use PHPStan\Reflection\ParametersAcceptor; +use PHPStan\Reflection\PartialFunctionApplicationParameters; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Reflection\ResolvedFunctionVariant; use PHPStan\Rules\Methods\NamedArgumentParameterMethodCallsCollector; @@ -812,6 +813,23 @@ public function checkPartialApplication( FunctionReflection|MethodReflection|null $calleeReflection, ): array { + if (PartialFunctionApplicationParameters::isMagicMethod($calleeReflection)) { + // the __call() trampoline it calls only has a variadic parameter + $errors = []; + foreach ($call->getRawArgs() as $arg) { + if (!$arg instanceof Node\ArgPlaceholder || $arg->name === null) { + continue; + } + $errors[] = RuleErrorBuilder::message(sprintf('Cannot use named placeholder for unknown or variadic parameter $%s.', $arg->name->toString())) + ->identifier('argument.unknown') + ->line($arg->getStartLine()) + ->build(); + } + if ($errors !== []) { + return $errors; + } + } + // templates are resolved from the bound arguments, as in a call; // the ones only the placeholders determine stay unresolved $argTypes = []; diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index 6b3a3091072..1d60be45bf5 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -561,6 +561,14 @@ public function testPartialFunctionApplicationClosureCalls(): void 'Argument for parameter $a has already been bound by the partial function application.', 60, ], + [ + 'Missing parameter $arguments0 (string) in call to closure.', + 93, + ], + [ + 'Unknown parameter $x in call to closure.', + 93, + ], ]); } diff --git a/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php b/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php index 0f88ccca11b..d1dae02f014 100644 --- a/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php +++ b/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php @@ -72,3 +72,24 @@ function forwardedArguments(): void // the variadic placeholder forwards the extra arguments to func_get_args() forwardsToFuncGetArgs(?, ...)(1, 2, 3); } + +/** + * @method int magic(string $x, int $y) + */ +class Magic +{ + + /** @param array $arguments */ + public function __call(string $name, array $arguments): int + { + return 1; + } + +} + +function magicMethods(Magic $magic): void +{ + // a method called through __call() takes its placeholders as $arguments0, $arguments1... + $magic->magic(?, 1)(x: 'a'); + $magic->magic(?, ?)(arguments0: 'a', arguments1: 1); +} diff --git a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php index ef957d5908d..ba7696d1684 100644 --- a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php @@ -140,9 +140,13 @@ public function testPartialFunctionApplicationArguments(): void 'Cannot combine partial application and unpacking.', 43, ], + [ + 'Cannot use named placeholder for unknown or variadic parameter $x.', + 72, + ], [ 'Variadic placeholder may only appear once.', - 50, + 78, ], ]); } diff --git a/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php index fd7b34cbd14..6b5a025ee9f 100644 --- a/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php @@ -163,9 +163,13 @@ public function testPartialFunctionApplicationArguments(): void 'Cannot combine partial application and unpacking.', 45, ], + [ + 'Cannot use named placeholder for unknown or variadic parameter $y.', + 73, + ], [ 'Variadic placeholder may only appear once.', - 51, + 79, ], ]); } diff --git a/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php b/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php index a272bbb66fe..99ead9728b0 100644 --- a/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php +++ b/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php @@ -45,6 +45,34 @@ function placementsWithUnknownCallees(Foo $foo, array $ints): void Foo::undefinedStatic(?, ...$ints); } +/** + * @method int magic(string $x, int $y) + * @method static int staticMagic(string $x, int $y) + */ +class Magic +{ + + /** @param array $arguments */ + public function __call(string $name, array $arguments): int + { + return 1; + } + + /** @param array $arguments */ + public static function __callStatic(string $name, array $arguments): int + { + return 1; + } + +} + +function magicMethods(Magic $magic): void +{ + // the __call() trampoline only has a variadic parameter + $magic->magic(x: ?); + Magic::staticMagic(?, y: ?); +} + function variadicPlaceholderPlacements(Foo $foo): void { $foo->doFoo(?, ..., ...); diff --git a/turbo-ext/src/InitializerExprTypeResolver.cpp b/turbo-ext/src/InitializerExprTypeResolver.cpp index d0583018e69..b073d786637 100644 --- a/turbo-ext/src/InitializerExprTypeResolver.cpp +++ b/turbo-ext/src/InitializerExprTypeResolver.cpp @@ -2543,6 +2543,15 @@ class InitializerExprTypeResolver isVariadic = zend_is_true(appliedIsVariadic); returnType = zv::Val::copyOf(zv::Ref(appliedReturnType)); templateTypeMap = zv::Val::copyOf(zv::Ref(appliedTemplateTypeMap)); + static pt_method_site magicNamesSite; + zv::Args magicNamesArgv{function, partialApplicationArgs}; + IETR_VAL(magicMethodParameterNames, pt_call_static_cached(magicNamesSite, PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS, PT_LC("getmagicmethodparameternames"), 2, magicNamesArgv)); + if (Z_TYPE_P(magicMethodParameterNames.raw()) == IS_NULL) { + // creating the closure of a method called through __call() throws + continue; + } + IETR_VAL(renamedForMagicMethod, renameParameters(parameters.raw(), magicMethodParameterNames.raw())); + parameters = std::move(renamedForMagicMethod); if (Z_TYPE_P(variantOrigin.raw()) == IS_OBJECT) { IETR_VAL(withBoundNames, pt_type_call(Z_OBJ_P(variantOrigin.raw()), PT_LC("withboundparameternames"), 1, appliedBoundParameterNames)); variantOrigin = std::move(withBoundNames); From 07f6786eba0dad62af1164d25adcfba80bc4817d Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Fri, 13 Nov 2026 11:41:59 +0000 Subject: [PATCH 17/20] Check a partial application no variant fits against the closest variant Combining the variants () and ($min, $max) of mt_rand() accepted mt_rand(?), so the count is checked against the closest variant, as for a call. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- .../PartialFunctionApplicationParameters.php | 72 +++++++++++++++++++ ...partial-function-application-signature.php | 1 + .../Functions/FunctionCallableRuleTest.php | 8 +++ ...partial-function-application-arguments.php | 9 +++ 4 files changed, 90 insertions(+) diff --git a/src/Reflection/PartialFunctionApplicationParameters.php b/src/Reflection/PartialFunctionApplicationParameters.php index 1d7655c9a90..f59e5f9af3c 100644 --- a/src/Reflection/PartialFunctionApplicationParameters.php +++ b/src/Reflection/PartialFunctionApplicationParameters.php @@ -351,9 +351,81 @@ public static function selectVariant(array $args, array $variants, ?array $named return $fitting[0]; } + if (count($fitting) === 0) { + $closestVariant = self::selectVariantClosestToArgumentsCount($args, $variants); + if ($closestVariant !== null) { + return $closestVariant; + } + } + return ParametersAcceptorSelector::combineAcceptors(count($fitting) > 0 ? $fitting : $variants); } + /** + * Combining the variants () and ($min, $max) of mt_rand() would accept mt_rand(?), + * so like a call, a count of positional arguments that the combined variants + * accept but no variant does is checked against the variant closest to it. + * + * @param array $args + * @param list $variants + */ + private static function selectVariantClosestToArgumentsCount(array $args, array $variants): ?ParametersAcceptor + { + $argsCount = 0; + $hasVariadicPlaceholder = false; + foreach ($args as $arg) { + if ($hasVariadicPlaceholder || ($arg instanceof Arg && $arg->unpack) || (!$arg instanceof VariadicPlaceholder && $arg->name !== null)) { + return null; + } + if ($arg instanceof VariadicPlaceholder) { + $hasVariadicPlaceholder = true; + continue; + } + $argsCount++; + } + + $closestVariant = null; + $closestDistance = null; + $combinedMinCount = null; + $combinedMaxCount = 0; + foreach ($variants as $variant) { + $minCount = 0; + foreach ($variant->getParameters() as $parameter) { + if ($parameter->isOptional()) { + continue; + } + $minCount++; + } + $maxCount = $variant->isVariadic() ? null : count($variant->getParameters()); + $combinedMinCount = min($combinedMinCount ?? $minCount, $minCount); + $combinedMaxCount = $maxCount === null || $combinedMaxCount === null ? null : max($combinedMaxCount, $maxCount); + + // the variadic placeholder fills in the parameters left + $isInsufficient = !$hasVariadicPlaceholder && $argsCount < $minCount; + if (!$isInsufficient && ($maxCount === null || $argsCount <= $maxCount)) { + // the count fits, the arguments do not for another reason + return null; + } + + $distance = $isInsufficient ? $minCount - $argsCount : $argsCount - $maxCount; + if ($closestDistance !== null && ($distance > $closestDistance || ($distance === $closestDistance && !$isInsufficient))) { + continue; + } + + $closestVariant = $variant; + $closestDistance = $distance; + } + + if ( + (!$hasVariadicPlaceholder && $argsCount < $combinedMinCount) + || ($combinedMaxCount !== null && $argsCount > $combinedMaxCount) + ) { + return null; + } + + return $closestVariant; + } + private static function required(ParameterReflection $parameter, string $name): ParameterReflection { if ($parameter instanceof ExtendedParameterReflection) { diff --git a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php index a55afeb0c00..f659e49e860 100644 --- a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php +++ b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php @@ -152,6 +152,7 @@ function functions(): void assertType('static-Closure(string): (non-empty-string|false)', strtok(?)); assertType('static-Closure(string, string): (non-empty-string|false)', strtok(?, ?)); assertType('static-Closure(string): int<0, max>', strlen(?)); + // PHP creates it from the declared mt_rand(int $min = UNKNOWN, int $max = UNKNOWN), calling it throws assertType('Closure', mt_rand(?)); // templates diff --git a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php index 0aa63dbcc19..a30d67d73b3 100644 --- a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php +++ b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php @@ -264,6 +264,14 @@ public function testPartialFunctionApplicationArguments(): void 'Variadic placeholder must be last.', 91, ], + [ + 'Function mt_rand partially applied with 1 argument, 2 required.', + 97, + ], + [ + 'Function mt_rand partially applied with 3 arguments, 0-2 required.', + 98, + ], ]); } diff --git a/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php b/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php index 3395a1e7e34..ecaa662ea60 100644 --- a/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php +++ b/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php @@ -90,3 +90,12 @@ function variadicPlaceholderPlacements(): void doFoo(1, ..., ..., ?); doFoo(1, ..., c: 5.0); } + +function multiVariant(): void +{ + // no variant of mt_rand() takes 1 or 3 arguments + mt_rand(?); + mt_rand(?, ?, ?, ...); + mt_rand(1, ?); + mt_rand(...); +} From b53bb1bbc15a5b15442a3bd00e8d8d9a51696a47 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Fri, 13 Nov 2026 11:41:59 +0000 Subject: [PATCH 18/20] Test placeholder misuse in instantiations, nullsafe calls and by-ref parameters Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- Makefile | 1 + build/collision-detector.json | 3 ++- .../Classes/InstantiationCallableRuleTest.php | 16 ++++++++++++++++ ...tantiation-partial-function-application.php | 18 ++++++++++++++++++ .../Rules/Functions/CallCallablesRuleTest.php | 4 ++++ ...tial-function-application-closure-calls.php | 13 +++++++++++++ .../Rules/Methods/MethodCallableRuleTest.php | 4 ++++ ...l-function-application-method-arguments.php | 3 ++- 8 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tests/PHPStan/Rules/Classes/data/instantiation-partial-function-application.php diff --git a/Makefile b/Makefile index e935b2ad1f9..9d5cff7a01a 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,7 @@ lint: --exclude tests/PHPStan/Rules/Properties/data/intersection-types.php \ --exclude tests/PHPStan/Rules/Classes/data/first-class-instantiation-callable.php \ --exclude tests/PHPStan/Rules/Classes/data/instantiation-callable.php \ + --exclude tests/PHPStan/Rules/Classes/data/instantiation-partial-function-application.php \ --exclude tests/PHPStan/Rules/Classes/data/bug-9402.php \ --exclude tests/PHPStan/Rules/Constants/data/class-as-class-constant.php \ --exclude tests/PHPStan/Rules/Constants/data/value-assigned-to-class-constant-native-type.php \ diff --git a/build/collision-detector.json b/build/collision-detector.json index 00effcc7aaa..9f285d628c9 100644 --- a/build/collision-detector.json +++ b/build/collision-detector.json @@ -35,6 +35,7 @@ "../tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php", "../tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php", "../tests/PHPStan/Rules/Functions/data/partial-function-application-callbacks.php", - "../tests/PHPStan/Analyser/nsrt/partial-function-application-replay.php" + "../tests/PHPStan/Analyser/nsrt/partial-function-application-replay.php", + "../tests/PHPStan/Rules/Classes/data/instantiation-partial-function-application.php" ] } diff --git a/tests/PHPStan/Rules/Classes/InstantiationCallableRuleTest.php b/tests/PHPStan/Rules/Classes/InstantiationCallableRuleTest.php index d30f3a29f65..adcce7f0b84 100644 --- a/tests/PHPStan/Rules/Classes/InstantiationCallableRuleTest.php +++ b/tests/PHPStan/Rules/Classes/InstantiationCallableRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -26,4 +27,19 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.6.0-dev')] + public function testPartialFunctionApplication(): void + { + $this->analyse([__DIR__ . '/data/instantiation-partial-function-application.php'], [ + [ + 'Cannot create callable from the new operator.', + 14, + ], + [ + 'Cannot create callable from the new operator.', + 15, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Classes/data/instantiation-partial-function-application.php b/tests/PHPStan/Rules/Classes/data/instantiation-partial-function-application.php new file mode 100644 index 00000000000..91b4cb625c7 --- /dev/null +++ b/tests/PHPStan/Rules/Classes/data/instantiation-partial-function-application.php @@ -0,0 +1,18 @@ += 8.6 + +namespace InstantiationPartialFunctionApplication; + +class Foo +{ + + public function __construct(int $a, string $b) + { + } + + public function doFoo(): void + { + $f = new self(?, ?); + $g = new self(1, ...); + } + +} diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index 1d60be45bf5..2ff785a6e90 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -569,6 +569,10 @@ public function testPartialFunctionApplicationClosureCalls(): void 'Unknown parameter $x in call to closure.', 93, ], + [ + 'Parameter #1 $a of closure is passed by reference, so it expects variables only.', + 105, + ], ]); } diff --git a/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php b/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php index d1dae02f014..3450f12c49b 100644 --- a/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php +++ b/tests/PHPStan/Rules/Functions/data/partial-function-application-closure-calls.php @@ -93,3 +93,16 @@ function magicMethods(Magic $magic): void $magic->magic(?, 1)(x: 'a'); $magic->magic(?, ?)(arguments0: 'a', arguments1: 1); } + +function byRef(int &$a, string $b): void +{ +} + +function byRefPlaceholder(): void +{ + // the closure keeps the by-ref parameter its placeholder stands for + $f = byRef(?, ?); + $f(1, 'b'); + $i = 1; + $f($i, 'b'); +} diff --git a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php index ba7696d1684..456f2dea08c 100644 --- a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php @@ -148,6 +148,10 @@ public function testPartialFunctionApplicationArguments(): void 'Variadic placeholder may only appear once.', 78, ], + [ + 'Cannot combine nullsafe operator with Closure creation.', + 80, + ], ]); } diff --git a/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php b/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php index 99ead9728b0..1105a66a1ba 100644 --- a/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php +++ b/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php @@ -73,8 +73,9 @@ function magicMethods(Magic $magic): void Magic::staticMagic(?, y: ?); } -function variadicPlaceholderPlacements(Foo $foo): void +function variadicPlaceholderPlacements(Foo $foo, ?Foo $nullableFoo): void { $foo->doFoo(?, ..., ...); Foo::doStatic(?, ..., ...); + $nullableFoo?->doFoo(1, ?); } From 3295957e24568687eca076af4223d3c8d40ce1a4 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Fri, 13 Nov 2026 12:30:40 +0000 Subject: [PATCH 19/20] Report leaving out a parameter whose default PHP does not know php-src stubs declare parameters like mt_rand()'s $min or array_keys()'s $filter_value with the default UNKNOWN. PHP throws "must be passed explicitly, because the default value is not known" when a later named argument skips such a parameter, or when ... of a partial application leaves it out. The default is now an ErrorType that every variant keeps, so calls, closure calls and partial applications report it, and such a partial application infers Closure. Calls like mt_rand(max: 5) crashed ArgumentsNormalizer before. A named argument now only selects the variants that have its parameter, so session_set_save_handler($open, read: $read) is checked against the signature with $close instead of the one with SessionHandlerInterface. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- src/Analyser/ArgumentsNormalizer.php | 5 +- .../InitializerExprTypeResolver.php | 5 ++ src/Reflection/ParameterReflection.php | 4 ++ src/Reflection/ParametersAcceptorSelector.php | 35 +++++++++- .../PartialFunctionApplicationParameters.php | 63 ++++++++++++++++++ .../SignatureMap/Php8SignatureMapProvider.php | 64 +++++++++++++++++-- src/Rules/FunctionCallParametersCheck.php | 24 +++++++ .../Analyser/AnalyserIntegrationTest.php | 14 ++++ .../unknown-default-value-named-arguments.php | 10 +++ ...partial-function-application-signature.php | 7 ++ .../Rules/Classes/InstantiationRuleTest.php | 11 ++++ .../Rules/Functions/CallCallablesRuleTest.php | 15 +++++ .../CallToFunctionParametersRuleTest.php | 19 ++++++ .../Functions/FunctionCallableRuleTest.php | 16 +++++ ...partial-function-application-arguments.php | 15 +++++ .../Functions/data/unknown-default-value.php | 31 +++++++++ .../Rules/Methods/CallMethodsRuleTest.php | 14 ++++ .../Rules/Methods/MethodCallableRuleTest.php | 8 +++ ...-function-application-method-arguments.php | 9 +++ turbo-ext/src/ArgumentsNormalizer.cpp | 15 +---- turbo-ext/src/InitializerExprTypeResolver.cpp | 9 +++ turbo-ext/src/ParametersAcceptorSelector.cpp | 43 ++++++++++++- 22 files changed, 410 insertions(+), 26 deletions(-) create mode 100644 tests/PHPStan/Analyser/data/unknown-default-value-named-arguments.php create mode 100644 tests/PHPStan/Rules/Functions/data/unknown-default-value.php diff --git a/src/Analyser/ArgumentsNormalizer.php b/src/Analyser/ArgumentsNormalizer.php index 126383c4bd7..e720fa68311 100644 --- a/src/Analyser/ArgumentsNormalizer.php +++ b/src/Analyser/ArgumentsNormalizer.php @@ -16,7 +16,6 @@ use PHPStan\Node\Printer\ExprPrinter; use PHPStan\Reflection\ParametersAcceptor; use PHPStan\Reflection\ParametersAcceptorSelector; -use PHPStan\ShouldNotHappenException; use PHPStan\TrinaryLogic; use PHPStan\Turbo\ShadowedByTurboExtension; use PHPStan\Type\Constant\ConstantArrayType; @@ -29,7 +28,6 @@ use function key; use function ksort; use function max; -use function sprintf; /** * @api @@ -443,7 +441,8 @@ public static function reorderArgs(ParametersAcceptor $parametersAcceptor, array $defaultValue = $parameter->getDefaultValue(); if ($defaultValue === null) { if (!$parameter->isVariadic()) { - throw new ShouldNotHappenException(sprintf('An optional parameter $%s must have a default value', $parameter->getName())); + // like an optional parameter combined from variants that do not all have it + return null; } $defaultValue = new ConstantArrayType([], []); } diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index eb2598947b9..ee7767ab88d 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -892,6 +892,11 @@ public function createFirstClassCallable( $origin = $origin->withPartialApplication($partialApplicationArgs, $boundArgTypes); } + if ($partialApplicationArgs !== null && PartialFunctionApplicationParameters::leavesUnknownDefaultValue($variants, $partialApplicationArgs)) { + // creating the closure throws + return new ObjectType(Closure::class); + } + // variants of multi-variant built-ins carry functionMap parameter names, // but the closure accepts the native names as named arguments $namedArgumentNames = []; diff --git a/src/Reflection/ParameterReflection.php b/src/Reflection/ParameterReflection.php index bebd231c945..33708f06a61 100644 --- a/src/Reflection/ParameterReflection.php +++ b/src/Reflection/ParameterReflection.php @@ -30,6 +30,10 @@ public function passedByReference(): PassedByReference; public function isVariadic(): bool; + /** + * An ErrorType for a parameter of a built-in function whose default PHP does not know, + * like mt_rand()'s $min: it must be passed explicitly when a later parameter is. + */ public function getDefaultValue(): ?Type; } diff --git a/src/Reflection/ParametersAcceptorSelector.php b/src/Reflection/ParametersAcceptorSelector.php index 309e70dd1eb..8f50d221b22 100644 --- a/src/Reflection/ParametersAcceptorSelector.php +++ b/src/Reflection/ParametersAcceptorSelector.php @@ -31,6 +31,7 @@ use PHPStan\Type\CallableType; use PHPStan\Type\Constant\ConstantArrayTypeBuilder; use PHPStan\Type\Constant\ConstantIntegerType; +use PHPStan\Type\ErrorType; use PHPStan\Type\Generic\TemplateTypeMap; use PHPStan\Type\Generic\TemplateTypeVarianceMap; use PHPStan\Type\IntegerType; @@ -46,6 +47,7 @@ use function array_is_list; use function array_key_exists; use function array_key_last; +use function array_keys; use function array_last; use function array_map; use function array_merge; @@ -685,6 +687,10 @@ public static function selectFromTypes( $typesCount = count($types); $acceptableAcceptors = []; + // a named argument only fits a variant that has its parameter, like + // session_set_save_handler($open, read: $read), unless no variant has it + $acceptableAcceptorsWithNames = []; + $someAcceptorHasNames = false; foreach ($parametersAcceptors as $parametersAcceptor) { if ($unpack) { @@ -694,14 +700,27 @@ public static function selectFromTypes( $functionParametersMinCount = 0; $functionParametersMaxCount = 0; + $parameterNames = []; foreach ($parametersAcceptor->getParameters() as $parameter) { if (!$parameter->isOptional()) { $functionParametersMinCount++; } $functionParametersMaxCount++; + $parameterNames[$parameter->getName()] = true; } + $hasNames = true; + if (!$parametersAcceptor->isVariadic()) { + foreach (array_keys($types) as $key) { + if (is_string($key) && !array_key_exists($key, $parameterNames)) { + $hasNames = false; + break; + } + } + } + $someAcceptorHasNames = $someAcceptorHasNames || $hasNames; + if ($typesCount < $functionParametersMinCount) { continue; } @@ -714,6 +733,15 @@ public static function selectFromTypes( } $acceptableAcceptors[] = $parametersAcceptor; + if (!$hasNames) { + continue; + } + + $acceptableAcceptorsWithNames[] = $parametersAcceptor; + } + + if ($someAcceptorHasNames) { + $acceptableAcceptors = $acceptableAcceptorsWithNames; } if (count($acceptableAcceptors) === 0) { @@ -892,7 +920,12 @@ public static function combineAcceptors(array $acceptors): ExtendedParametersAcc $isParameterVariadic = $parameters[$i]->isVariadic() || $parameter->isVariadic(); $defaultValueLeft = $parameters[$i]->getDefaultValue(); $defaultValueRight = $parameter->getDefaultValue(); - if ($defaultValueLeft !== null && $defaultValueRight !== null) { + if ($defaultValueLeft instanceof ErrorType) { + // the parameter of the real signature keeps its unknown default + $defaultValue = $defaultValueLeft; + } elseif ($defaultValueRight instanceof ErrorType) { + $defaultValue = $defaultValueRight; + } elseif ($defaultValueLeft !== null && $defaultValueRight !== null) { $defaultValue = TypeCombinator::union($defaultValueLeft, $defaultValueRight); } else { $defaultValue = null; diff --git a/src/Reflection/PartialFunctionApplicationParameters.php b/src/Reflection/PartialFunctionApplicationParameters.php index f59e5f9af3c..07d12dae6f8 100644 --- a/src/Reflection/PartialFunctionApplicationParameters.php +++ b/src/Reflection/PartialFunctionApplicationParameters.php @@ -10,12 +10,14 @@ use PHPStan\Reflection\Php\DummyParameter; use PHPStan\Reflection\Php\ExtendedDummyParameter; use PHPStan\Turbo\ReferencedByTurboExtension; +use PHPStan\Type\ErrorType; use PHPStan\Type\Generic\TemplateType; use PHPStan\Type\Generic\TemplateTypeMap; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; use PHPStan\Type\TypeTraverser; use function array_key_exists; +use function array_keys; use function count; use function max; use function min; @@ -274,6 +276,17 @@ private static function map(array $parameters, bool $isVariadic, array $args): ? $named[] = self::required($declared[$index], $nameString); } + $lastCovered = $covered === [] ? -1 : max(array_keys($covered)); + foreach ($declared as $i => $parameter) { + if (isset($covered[$i]) || !$parameter->getDefaultValue() instanceof ErrorType) { + continue; + } + if ($hasVariadicPlaceholder || ($i < $lastCovered && $parameter->isOptional())) { + // PHP refuses to fill in a default it does not know + return null; + } + } + $closureParameters = [...$positional, ...$named]; if (!$hasVariadicPlaceholder) { foreach ($declared as $i => $parameter) { @@ -335,6 +348,12 @@ public static function selectVariant(array $args, array $variants, ?array $named } } + foreach ($variants as $variant) { + if (self::leavesUnknownDefaultValue([$variant], $args)) { + return $variant; + } + } + if (count($variants) === 1) { return $variants[0]; } @@ -361,6 +380,50 @@ public static function selectVariant(array $args, array $variants, ?array $named return ParametersAcceptorSelector::combineAcceptors(count($fitting) > 0 ? $fitting : $variants); } + /** + * The variants of a built-in describe one real signature, so when ... leaves out a parameter + * whose default PHP does not know in any of them, like $value of ReflectionProperty::setValue(?, ...), + * creating the closure throws whichever variant the arguments fit. + * + * @param ParametersAcceptor[] $variants + * @param array $args + */ + public static function leavesUnknownDefaultValue(array $variants, array $args): bool + { + $positionalCount = 0; + $names = []; + $hasVariadicPlaceholder = false; + foreach ($args as $arg) { + if ($arg instanceof VariadicPlaceholder) { + $hasVariadicPlaceholder = true; + continue; + } + if ($arg->name !== null) { + $names[$arg->name->toString()] = true; + continue; + } + $positionalCount++; + } + if (!$hasVariadicPlaceholder) { + return false; + } + + foreach ($variants as $variant) { + foreach ($variant->getParameters() as $i => $parameter) { + if ( + $i >= $positionalCount + && !$parameter->isVariadic() + && !array_key_exists($parameter->getName(), $names) + && $parameter->getDefaultValue() instanceof ErrorType + ) { + return true; + } + } + } + + return false; + } + /** * Combining the variants () and ($min, $max) of mt_rand() would accept mt_rand(?), * so like a call, a count of positional arguments that the combined variants diff --git a/src/Reflection/SignatureMap/Php8SignatureMapProvider.php b/src/Reflection/SignatureMap/Php8SignatureMapProvider.php index 6468bdd6f40..0d8e22d9d1a 100644 --- a/src/Reflection/SignatureMap/Php8SignatureMapProvider.php +++ b/src/Reflection/SignatureMap/Php8SignatureMapProvider.php @@ -20,6 +20,7 @@ use PHPStan\Reflection\PassedByReference; use PHPStan\Reflection\ReflectionProvider\ReflectionProviderProvider; use PHPStan\ShouldNotHappenException; +use PHPStan\Type\ErrorType; use PHPStan\Type\FileTypeMapper; use PHPStan\Type\MixedType; use PHPStan\Type\ParserNodeTypeToPHPStanType; @@ -418,7 +419,7 @@ private function getMergedSignatures(FunctionSignature $nativeSignature, array $ $functionParam->getNativeType(), $functionParam->passedByReference(), $functionParam->isVariadic(), - $functionParam->getDefaultValue() ?? $nativeParam->getDefaultValue(), + $nativeParam->getDefaultValue() instanceof ErrorType ? $nativeParam->getDefaultValue() : $functionParam->getDefaultValue() ?? $nativeParam->getDefaultValue(), $functionParam->getOutType() ?? $nativeParam->getOutType(), ); } @@ -435,7 +436,50 @@ private function getMergedSignatures(FunctionSignature $nativeSignature, array $ $namedArgumentsVariants = null; } - return ['positional' => $functionMapSignatures['positional'], 'named' => $namedArgumentsVariants]; + return [ + 'positional' => array_map(fn (FunctionSignature $signature): FunctionSignature => $this->withUnknownDefaultValues($nativeSignature, $signature), $functionMapSignatures['positional']), + 'named' => $namedArgumentsVariants, + ]; + } + + /** + * A parameter of a function map variant like mt_rand(int $min, int $max) keeps the unknown default + * of the parameter it stands for, also over a default the PhpStorm stubs make up for it, + * so that combining the variants knows that $min must be passed explicitly before $max. + */ + private function withUnknownDefaultValues(FunctionSignature $nativeSignature, FunctionSignature $signature): FunctionSignature + { + $nativeParameters = $nativeSignature->getParameters(); + $parameters = []; + foreach ($signature->getParameters() as $i => $parameter) { + $nativeParameter = $nativeParameters[$i] ?? null; + if ( + $nativeParameter === null + || $nativeParameter->getName() !== $parameter->getName() + || !$nativeParameter->getDefaultValue() instanceof ErrorType + ) { + $parameters[] = $parameter; + continue; + } + + $parameters[] = new ParameterSignature( + $parameter->getName(), + $parameter->isOptional(), + $parameter->getType(), + $parameter->getNativeType(), + $parameter->passedByReference(), + $parameter->isVariadic(), + $nativeParameter->getDefaultValue(), + $parameter->getOutType(), + ); + } + + return new FunctionSignature( + $parameters, + $signature->getReturnType(), + $signature->getNativeReturnType(), + $signature->isVariadic(), + ); } private function mergeSignatures(FunctionSignature $nativeSignature, FunctionSignature $functionMapSignature): FunctionSignature @@ -570,6 +614,17 @@ private function getSignature( } } + $defaultValue = null; + if ($param->default instanceof ConstFetch && $param->default->name->toString() === 'UNKNOWN') { + // see ParameterReflection::getDefaultValue() + $defaultValue = new ErrorType(); + } elseif ($param->default !== null) { + $defaultValue = $this->initializerExprTypeResolver->getType( + $param->default, + InitializerExprContext::fromStubParameter($className, $stubFile, $function), + ); + } + $parameters[] = new ParameterSignature( $name->name, $param->default !== null || $param->variadic, @@ -577,10 +632,7 @@ private function getSignature( $parameterType, $param->byRef ? PassedByReference::createCreatesNewVariable() : PassedByReference::createNo(), $param->variadic, - $param->default !== null ? $this->initializerExprTypeResolver->getType( - $param->default, - InitializerExprContext::fromStubParameter($className, $stubFile, $function), - ) : null, + $defaultValue, null, ); diff --git a/src/Rules/FunctionCallParametersCheck.php b/src/Rules/FunctionCallParametersCheck.php index 4c2a0b69637..92200264c91 100644 --- a/src/Rules/FunctionCallParametersCheck.php +++ b/src/Rules/FunctionCallParametersCheck.php @@ -1015,6 +1015,30 @@ private function processArguments( unset($unusedParametersByName[$parameter->getName()]); } + // PHP refuses to fill in a default it does not know: for a parameter + // skipped by a later named argument, or left to ... of a partial application + $lastPassedPosition = -1; + foreach ($parameters as $i => $parameter) { + if ($parameter->isVariadic() || array_key_exists($parameter->getName(), $unusedParametersByName)) { + continue; + } + $lastPassedPosition = $i; + } + foreach ($parameters as $i => $parameter) { + if ( + !array_key_exists($parameter->getName(), $unusedParametersByName) + || !$parameter->getDefaultValue() instanceof ErrorType + || ($checkMissingParameters && (!$hasNamedArguments || !$parameter->isOptional() || $i > $lastPassedPosition)) + ) { + continue; + } + + $errors[] = RuleErrorBuilder::message(sprintf('Argument #%d ($%s) must be passed explicitly, because the default value is not known.', $i + 1, $parameter->getName())) + ->identifier('argument.unknownDefaultValue') + ->line($line) + ->build(); + } + if ($hasNamedArguments && $checkMissingParameters) { foreach ($unusedParametersByName as $parameter) { if ($parameter->isOptional()) { diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 4976071022b..394a50d2487 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1718,6 +1718,20 @@ public function testBug9746(): void $this->assertSame(9, $errors[1]->getLine()); } + #[RequiresPhp('>= 8.1.0')] + public function testUnknownDefaultValueNamedArguments(): void + { + // crash + $errors = $this->runAnalyse(__DIR__ . '/data/unknown-default-value-named-arguments.php'); + $this->assertCount(3, $errors); + $this->assertSame('Argument #1 ($min) must be passed explicitly, because the default value is not known.', $errors[0]->getMessage()); + $this->assertSame(7, $errors[0]->getLine()); + $this->assertSame('Argument #1 ($min) must be passed explicitly, because the default value is not known.', $errors[1]->getMessage()); + $this->assertSame(8, $errors[1]->getLine()); + $this->assertSame('Argument #2 ($close) must be passed explicitly, because the default value is not known.', $errors[2]->getMessage()); + $this->assertSame(9, $errors[2]->getLine()); + } + public function testBug15364(): void { // crash diff --git a/tests/PHPStan/Analyser/data/unknown-default-value-named-arguments.php b/tests/PHPStan/Analyser/data/unknown-default-value-named-arguments.php new file mode 100644 index 00000000000..0cf8bba5bce --- /dev/null +++ b/tests/PHPStan/Analyser/data/unknown-default-value-named-arguments.php @@ -0,0 +1,10 @@ += 8.1 + +namespace UnknownDefaultValueNamedArguments; + +function doFoo(callable $open, callable $read): void +{ + mt_rand(max: 5); + (mt_rand(...))(max: 5); + (session_set_save_handler(...))($open, read: $read); +} diff --git a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php index f659e49e860..6ac9a99ab37 100644 --- a/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php +++ b/tests/PHPStan/Analyser/nsrt/partial-function-application-signature.php @@ -154,6 +154,13 @@ function functions(): void assertType('static-Closure(string): int<0, max>', strlen(?)); // PHP creates it from the declared mt_rand(int $min = UNKNOWN, int $max = UNKNOWN), calling it throws assertType('Closure', mt_rand(?)); + // PHP throws when ... or a later named argument leaves out a parameter whose default it does not know + assertType('Closure', array_keys(?, ...)); + assertType('Closure', array_keys(?, strict: ?)); + assertType('Closure', mt_rand(?, ...)); + assertType('Closure', array_walk(?, ?, ...)); + assertType('static-Closure(array, mixed, bool=): list', array_keys(?, ?, ...)); + assertType('static-Closure(array|object, callable): true', array_walk(?, ?)); // templates assertType('static-Closure(T): T', identity(?)); diff --git a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php index cc27c26e7f4..7ba694444fc 100644 --- a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php +++ b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php @@ -826,4 +826,15 @@ public function testBug14002Part2(): void $this->analyse([__DIR__ . '/data/bug-14002-2.php'], []); } + #[RequiresPhp('>= 8.1.0')] + public function testUnknownDefaultValue(): void + { + $this->analyse([__DIR__ . '/../Functions/data/unknown-default-value.php'], [ + [ + 'Argument #2 ($interval) must be passed explicitly, because the default value is not known.', + 19, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index 2ff785a6e90..a2d10154ae5 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -598,4 +598,19 @@ public function testBug11935WithCheckExplicitMixed(): void ]); } + #[RequiresPhp('>= 8.1.0')] + public function testUnknownDefaultValue(): void + { + $this->analyse([__DIR__ . '/data/unknown-default-value.php'], [ + [ + 'Argument #2 ($filter_value) must be passed explicitly, because the default value is not known.', + 27, + ], + [ + 'Argument #1 ($min) must be passed explicitly, because the default value is not known.', + 28, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 6ae46c1996f..18bf131bdf3 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -3615,4 +3615,23 @@ public function testPartialFunctionApplicationCallbacks(): void ]); } + #[RequiresPhp('>= 8.1.0')] + public function testUnknownDefaultValue(): void + { + $this->analyse([__DIR__ . '/data/unknown-default-value.php'], [ + [ + 'Argument #2 ($filter_value) must be passed explicitly, because the default value is not known.', + 7, + ], + [ + 'Argument #1 ($min) must be passed explicitly, because the default value is not known.', + 8, + ], + [ + 'Argument #2 ($close) must be passed explicitly, because the default value is not known.', + 9, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php index a30d67d73b3..c285bf1a35e 100644 --- a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php +++ b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php @@ -272,6 +272,22 @@ public function testPartialFunctionApplicationArguments(): void 'Function mt_rand partially applied with 3 arguments, 0-2 required.', 98, ], + [ + 'Argument #2 ($filter_value) must be passed explicitly, because the default value is not known.', + 106, + ], + [ + 'Argument #2 ($filter_value) must be passed explicitly, because the default value is not known.', + 107, + ], + [ + 'Argument #2 ($max) must be passed explicitly, because the default value is not known.', + 108, + ], + [ + 'Argument #3 ($arg) must be passed explicitly, because the default value is not known.', + 109, + ], ]); } diff --git a/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php b/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php index ecaa662ea60..d951bb9cfdf 100644 --- a/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php +++ b/tests/PHPStan/Rules/Functions/data/partial-function-application-arguments.php @@ -99,3 +99,18 @@ function multiVariant(): void mt_rand(1, ?); mt_rand(...); } + +function unknownDefaults(): void +{ + // PHP does not know the default of $filter_value, mt_rand()'s $max or array_walk()'s $arg + array_keys(?, ...); + array_keys(?, strict: ?); + mt_rand(1, ...); + array_walk(?, ?, ...); + + array_keys(?); + array_keys(?, ?, ...); + array_keys(?, ?, strict: ?); + mt_rand(?, ?); + array_walk(?, ?); +} diff --git a/tests/PHPStan/Rules/Functions/data/unknown-default-value.php b/tests/PHPStan/Rules/Functions/data/unknown-default-value.php new file mode 100644 index 00000000000..ab0a8d82534 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/unknown-default-value.php @@ -0,0 +1,31 @@ += 8.1 + +namespace UnknownDefaultValue; + +function functions(array $a, callable $open, callable $read): void +{ + array_keys($a, strict: true); + mt_rand(max: 5); + session_set_save_handler($open, read: $read); + + array_keys($a, 1, strict: true); + mt_rand(min: 1, max: 5); + array_keys(array: $a); +} + +function methods(\IntlCalendar $calendar, \DateTimeImmutable $start, \DateTimeImmutable $end): void +{ + $calendar->set(2020, 1, hour: 5); + new \DatePeriod($start, end: $end); + + $calendar->set(2020, 1, 1, hour: 5); +} + +function closures(array $a): void +{ + $keys = array_keys(...); + $keys($a, strict: true); + (mt_rand(...))(max: 5); + + $keys($a, 1, strict: true); +} diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index f89498c3be5..f4d2d5532f6 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -4663,4 +4663,18 @@ public function testDeadCatch(): void ]); } + #[RequiresPhp('>= 8.1.0')] + public function testUnknownDefaultValue(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->analyse([__DIR__ . '/../Functions/data/unknown-default-value.php'], [ + [ + 'Argument #3 ($dayOfMonth) must be passed explicitly, because the default value is not known.', + 18, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php index 456f2dea08c..1d3d02ab358 100644 --- a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php @@ -152,6 +152,14 @@ public function testPartialFunctionApplicationArguments(): void 'Cannot combine nullsafe operator with Closure creation.', 80, ], + [ + 'Argument #2 ($value) must be passed explicitly, because the default value is not known.', + 86, + ], + [ + 'Argument #2 ($default) must be passed explicitly, because the default value is not known.', + 87, + ], ]); } diff --git a/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php b/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php index 1105a66a1ba..016525bb8f0 100644 --- a/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php +++ b/tests/PHPStan/Rules/Methods/data/partial-function-application-method-arguments.php @@ -79,3 +79,12 @@ function variadicPlaceholderPlacements(Foo $foo, ?Foo $nullableFoo): void Foo::doStatic(?, ..., ...); $nullableFoo?->doFoo(1, ?); } + +function unknownDefaults(\ReflectionProperty $rp, \ReflectionClass $rc): void +{ + // PHP does not know the default of $value or $default + $rp->setValue(?, ...); + $rc->getStaticPropertyValue(?, ...); + $rp->setValue(?, ?); + $rp->setValue(?); +} diff --git a/turbo-ext/src/ArgumentsNormalizer.cpp b/turbo-ext/src/ArgumentsNormalizer.cpp index 8ab0753d140..f13ec4931b2 100644 --- a/turbo-ext/src/ArgumentsNormalizer.cpp +++ b/turbo-ext/src/ArgumentsNormalizer.cpp @@ -730,19 +730,8 @@ class ArgumentsNormalizer bool variadic = false; if (UNEXPECTED(!parameterIsVariadic(parameter, variadic))) return zv::Val(); if (!variadic) { - zv::Val name = parameterGetName(parameter); - if (UNEXPECTED(name.isUndef())) return zv::Val(); - zend_string *nameString = zval_get_string(name.raw()); - zend_string *message = zend_strpprintf(0, "An optional parameter $%s must have a default value", ZSTR_VAL(nameString)); - zend_string_release(nameString); - zval messageZv; - ZVAL_STR(&messageZv, message); - zv::Val exception = pt_type_new(PT_CLASS_SHOULD_NOT_HAPPEN, 1, &messageZv); - zend_string_release(message); - if (UNEXPECTED(exception.isUndef())) return zv::Val(); - zval raw = exception.take(); - zend_throw_exception_object(&raw); - return zv::Val(); + // like an optional parameter combined from variants that do not all have it + return zv::Val::null(); } zval emptyKeys, emptyValues, constantArray; ZVAL_EMPTY_ARRAY(&emptyKeys); diff --git a/turbo-ext/src/InitializerExprTypeResolver.cpp b/turbo-ext/src/InitializerExprTypeResolver.cpp index b073d786637..07700666852 100644 --- a/turbo-ext/src/InitializerExprTypeResolver.cpp +++ b/turbo-ext/src/InitializerExprTypeResolver.cpp @@ -2381,6 +2381,15 @@ class InitializerExprTypeResolver origin = pt_type_call(Z_OBJ_P(originIn), PT_LC("withpartialapplication"), 2, withArgv); if (UNEXPECTED(origin.isUndef())) return zv::Val(); } + if (partialApplication) { + static pt_method_site leavesUnknownDefaultValueSite; + zv::Args leavesArgv{variants, partialApplicationArgs}; + IETR_VAL(leavesUnknownDefaultValue, pt_call_static_cached(leavesUnknownDefaultValueSite, PT_CLASS_PARTIAL_FUNCTION_APPLICATION_PARAMETERS, PT_LC("leavesunknowndefaultvalue"), 2, leavesArgv)); + if (zend_is_true(leavesUnknownDefaultValue.raw())) { + // creating the closure throws + return newObjectTypeLiteral(PT_LC("Closure")); + } + } if (UNEXPECTED(Z_TYPE_P(variants) != IS_ARRAY)) { zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(variants)); if (UNEXPECTED(EG(exception) != NULL)) return zv::Val(); diff --git a/turbo-ext/src/ParametersAcceptorSelector.cpp b/turbo-ext/src/ParametersAcceptorSelector.cpp index 4fb98b1eca2..5fe4bb41658 100644 --- a/turbo-ext/src/ParametersAcceptorSelector.cpp +++ b/turbo-ext/src/ParametersAcceptorSelector.cpp @@ -791,6 +791,10 @@ class ParametersAcceptorSelector HashTable *typesTable = Z_ARRVAL_P(types); zend_long typesCount = zend_hash_num_elements(typesTable); zv::Arr acceptableAcceptors = zv::Arr::empty(); + // a named argument only fits a variant that has its parameter, like + // session_set_save_handler($open, read: $read), unless no variant has it + zv::Arr acceptableAcceptorsWithNames = zv::Arr::empty(); + bool someAcceptorHasNames = false; for (zv::ArrayEntry entry : zv::TableRef(acceptors)) { zval *parametersAcceptor = entry.value().deref().raw(); @@ -801,6 +805,7 @@ class ParametersAcceptorSelector zend_long functionParametersMinCount = 0; zend_long functionParametersMaxCount = 0; + zv::Arr parameterNames = zv::Arr::create(0); zv::Val parameters = acceptorParameters(parametersAcceptor); if (UNEXPECTED(parameters.isUndef())) return zv::Val(); for (zv::ArrayEntry parameterEntry : zv::ArrRef(parameters.raw())) { @@ -811,15 +816,42 @@ class ParametersAcceptorSelector } functionParametersMaxCount++; + zv::Val parameterName = parameterGet(parameterEntry.value().deref().raw(), PG_NAME); + if (UNEXPECTED(parameterName.isUndef())) return zv::Val(); + if (Z_TYPE_P(parameterName.raw()) == IS_STRING) { + zval trueValue; + ZVAL_TRUE(&trueValue); + zend_symtable_update(parameterNames.table(), Z_STR_P(parameterName.raw()), &trueValue); + } } - if (typesCount < functionParametersMinCount) continue; - bool isVariadic = false; if (UNEXPECTED(!acceptorIsVariadic(parametersAcceptor, isVariadic))) return zv::Val(); + + bool hasNames = true; + if (!isVariadic) { + for (zv::ArrayEntry typeEntry : zv::TableRef(typesTable)) { + zend_string *key = typeEntry.stringKeyOrNull(); + if (key != NULL && zend_symtable_find(parameterNames.table(), key) == NULL) { + hasNames = false; + break; + } + } + } + someAcceptorHasNames = someAcceptorHasNames || hasNames; + + if (typesCount < functionParametersMinCount) continue; + if (!isVariadic && typesCount > functionParametersMaxCount) continue; acceptableAcceptors.push(zv::Ref(parametersAcceptor)); + if (!hasNames) continue; + + acceptableAcceptorsWithNames.push(zv::Ref(parametersAcceptor)); + } + + if (someAcceptorHasNames) { + acceptableAcceptors = std::move(acceptableAcceptorsWithNames); } uint32_t acceptableCount = zend_hash_num_elements(acceptableAcceptors.table()); @@ -1217,7 +1249,12 @@ class ParametersAcceptorSelector zv::Val defaultValueRight = parameterGet(parameter, PG_DEFAULT_VALUE); if (UNEXPECTED(defaultValueRight.isUndef())) return zv::Val(); zv::Val defaultValue = zv::Val::null(); - if (!defaultValueLeft.isNull() && !defaultValueRight.isNull()) { + if (Z_TYPE_P(defaultValueLeft.raw()) == IS_OBJECT && instanceof_function(Z_OBJCE_P(defaultValueLeft.raw()), pt_ce_error_type)) { + // the parameter of the real signature keeps its unknown default + defaultValue = std::move(defaultValueLeft); + } else if (Z_TYPE_P(defaultValueRight.raw()) == IS_OBJECT && instanceof_function(Z_OBJCE_P(defaultValueRight.raw()), pt_ce_error_type)) { + defaultValue = std::move(defaultValueRight); + } else if (!defaultValueLeft.isNull() && !defaultValueRight.isNull()) { defaultValue = union2(defaultValueLeft.raw(), defaultValueRight.raw()); if (UNEXPECTED(defaultValue.isUndef())) return zv::Val(); } From a16fa0bb767aed1ab0f05978d084d6c284fe83b6 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Fri, 13 Nov 2026 13:08:12 +0000 Subject: [PATCH 20/20] Resolve named arguments of multi-variant built-ins against their php-src signature PHP resolves named arguments against the one arginfo generated from the function's stub, so a named call to a multi-variant built-in resolves against its php-8-stubs signature instead of a renamed copy of each functionMap variant. Its argument count is then checked against the variants like a positional call's, which reports mt_rand(min: 1). First-class callables of such functions and methods resolve named arguments the same way when the closure is called. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c541-317f-7386-a2ed-9cbd66178685 --- src/Reflection/ParametersAcceptorSelector.php | 35 +------- .../SignatureMap/Php8SignatureMapProvider.php | 61 +------------- src/Rules/FunctionCallParametersCheck.php | 83 +++++++++++++++++++ src/Rules/Functions/CallCallablesRule.php | 57 ++++++++++++- .../CallToFunctionParametersRule.php | 1 + src/Type/ClosureOrigin.php | 5 ++ .../Rules/Classes/InstantiationRuleTest.php | 6 +- .../Rules/Functions/CallCallablesRuleTest.php | 20 +++++ .../CallToFunctionParametersRuleTest.php | 19 +++++ ...ction-named-params-multivariant-errors.php | 8 ++ ...allables-named-arguments-multi-variant.php | 15 ++++ .../Rules/Methods/CallMethodsRuleTest.php | 2 +- turbo-ext/src/ParametersAcceptorSelector.cpp | 43 +--------- 13 files changed, 215 insertions(+), 140 deletions(-) create mode 100644 tests/PHPStan/Rules/Functions/data/call-to-function-named-params-multivariant-errors.php create mode 100644 tests/PHPStan/Rules/Functions/data/callables-named-arguments-multi-variant.php diff --git a/src/Reflection/ParametersAcceptorSelector.php b/src/Reflection/ParametersAcceptorSelector.php index 8f50d221b22..309e70dd1eb 100644 --- a/src/Reflection/ParametersAcceptorSelector.php +++ b/src/Reflection/ParametersAcceptorSelector.php @@ -31,7 +31,6 @@ use PHPStan\Type\CallableType; use PHPStan\Type\Constant\ConstantArrayTypeBuilder; use PHPStan\Type\Constant\ConstantIntegerType; -use PHPStan\Type\ErrorType; use PHPStan\Type\Generic\TemplateTypeMap; use PHPStan\Type\Generic\TemplateTypeVarianceMap; use PHPStan\Type\IntegerType; @@ -47,7 +46,6 @@ use function array_is_list; use function array_key_exists; use function array_key_last; -use function array_keys; use function array_last; use function array_map; use function array_merge; @@ -687,10 +685,6 @@ public static function selectFromTypes( $typesCount = count($types); $acceptableAcceptors = []; - // a named argument only fits a variant that has its parameter, like - // session_set_save_handler($open, read: $read), unless no variant has it - $acceptableAcceptorsWithNames = []; - $someAcceptorHasNames = false; foreach ($parametersAcceptors as $parametersAcceptor) { if ($unpack) { @@ -700,27 +694,14 @@ public static function selectFromTypes( $functionParametersMinCount = 0; $functionParametersMaxCount = 0; - $parameterNames = []; foreach ($parametersAcceptor->getParameters() as $parameter) { if (!$parameter->isOptional()) { $functionParametersMinCount++; } $functionParametersMaxCount++; - $parameterNames[$parameter->getName()] = true; } - $hasNames = true; - if (!$parametersAcceptor->isVariadic()) { - foreach (array_keys($types) as $key) { - if (is_string($key) && !array_key_exists($key, $parameterNames)) { - $hasNames = false; - break; - } - } - } - $someAcceptorHasNames = $someAcceptorHasNames || $hasNames; - if ($typesCount < $functionParametersMinCount) { continue; } @@ -733,15 +714,6 @@ public static function selectFromTypes( } $acceptableAcceptors[] = $parametersAcceptor; - if (!$hasNames) { - continue; - } - - $acceptableAcceptorsWithNames[] = $parametersAcceptor; - } - - if ($someAcceptorHasNames) { - $acceptableAcceptors = $acceptableAcceptorsWithNames; } if (count($acceptableAcceptors) === 0) { @@ -920,12 +892,7 @@ public static function combineAcceptors(array $acceptors): ExtendedParametersAcc $isParameterVariadic = $parameters[$i]->isVariadic() || $parameter->isVariadic(); $defaultValueLeft = $parameters[$i]->getDefaultValue(); $defaultValueRight = $parameter->getDefaultValue(); - if ($defaultValueLeft instanceof ErrorType) { - // the parameter of the real signature keeps its unknown default - $defaultValue = $defaultValueLeft; - } elseif ($defaultValueRight instanceof ErrorType) { - $defaultValue = $defaultValueRight; - } elseif ($defaultValueLeft !== null && $defaultValueRight !== null) { + if ($defaultValueLeft !== null && $defaultValueRight !== null) { $defaultValue = TypeCombinator::union($defaultValueLeft, $defaultValueRight); } else { $defaultValue = null; diff --git a/src/Reflection/SignatureMap/Php8SignatureMapProvider.php b/src/Reflection/SignatureMap/Php8SignatureMapProvider.php index 0d8e22d9d1a..34e69363775 100644 --- a/src/Reflection/SignatureMap/Php8SignatureMapProvider.php +++ b/src/Reflection/SignatureMap/Php8SignatureMapProvider.php @@ -378,67 +378,10 @@ private function getMergedSignatures(FunctionSignature $nativeSignature, array $ return ['positional' => [], 'named' => null]; } - $nativeParams = $nativeSignature->getParameters(); - $namedArgumentsVariants = []; - $allParamNamesMatchNative = true; - foreach ($functionMapSignatures['positional'] as $functionMapSignature) { - $isPrevParamVariadic = false; - $hasMiddleVariadicParam = false; - // avoid weird functions like array_diff_uassoc - foreach ($functionMapSignature->getParameters() as $i => $functionParam) { - $nativeParam = $nativeParams[$i] ?? null; - $allParamNamesMatchNative = $allParamNamesMatchNative && $nativeParam !== null && $functionParam->getName() === $nativeParam->getName(); - $hasMiddleVariadicParam = $hasMiddleVariadicParam || $isPrevParamVariadic; - $isPrevParamVariadic = $functionParam->isVariadic() || ( - $nativeParam !== null - ? $nativeParam->isVariadic() - : false - ); - } - - if ($hasMiddleVariadicParam) { - continue; - } - - $parameters = []; - foreach ($functionMapSignature->getParameters() as $i => $functionParam) { - if (!array_key_exists($i, $nativeParams)) { - continue 2; - } - - // it seems that variadic parameters cannot be named in native functions/methods. - $nativeParam = $nativeParams[$i]; - if ($nativeParam->isVariadic()) { - break; - } - - $parameters[] = new ParameterSignature( - $nativeParam->getName(), - $functionParam->isOptional(), - $functionParam->getType(), - $functionParam->getNativeType(), - $functionParam->passedByReference(), - $functionParam->isVariadic(), - $nativeParam->getDefaultValue() instanceof ErrorType ? $nativeParam->getDefaultValue() : $functionParam->getDefaultValue() ?? $nativeParam->getDefaultValue(), - $functionParam->getOutType() ?? $nativeParam->getOutType(), - ); - } - - $namedArgumentsVariants[] = new FunctionSignature( - $parameters, - $functionMapSignature->getReturnType(), - $functionMapSignature->getNativeReturnType(), - $functionMapSignature->isVariadic(), - ); - } - - if ($allParamNamesMatchNative || count($namedArgumentsVariants) === 0) { - $namedArgumentsVariants = null; - } - return [ 'positional' => array_map(fn (FunctionSignature $signature): FunctionSignature => $this->withUnknownDefaultValues($nativeSignature, $signature), $functionMapSignatures['positional']), - 'named' => $namedArgumentsVariants, + // PHP resolves named arguments against the one signature php-src stubs declare + 'named' => [$nativeSignature], ]; } diff --git a/src/Rules/FunctionCallParametersCheck.php b/src/Rules/FunctionCallParametersCheck.php index 92200264c91..c5a44e7d254 100644 --- a/src/Rules/FunctionCallParametersCheck.php +++ b/src/Rules/FunctionCallParametersCheck.php @@ -20,6 +20,7 @@ use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParameterReflection; use PHPStan\Reflection\ParametersAcceptor; +use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\PartialFunctionApplicationParameters; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Reflection\ResolvedFunctionVariant; @@ -42,6 +43,7 @@ use PHPStan\Type\VerbosityLevel; use function array_fill; use function array_key_exists; +use function array_keys; use function array_last; use function array_merge; use function count; @@ -88,6 +90,7 @@ public function __construct( /** * @param 'attribute'|'callable'|'method'|'staticMethod'|'function'|'new' $nodeType * @param array{class-string, string}|null $renamedNamedArgumentParameterData + * @param list $namedCallVariants positional variants of a callee whose named arguments resolve against its php-src signature * @return list */ public function check( @@ -117,6 +120,7 @@ public function check( string $bitmaskNotAllowedMessage, ?array $renamedNamedArgumentParameterData, FunctionReflection|MethodReflection|null $calleeReflection = null, + array $namedCallVariants = [], ): array { if ($funcCall instanceof Node\Expr\MethodCall || $funcCall instanceof Node\Expr\StaticCall || $funcCall instanceof Node\Expr\FuncCall) { @@ -312,6 +316,7 @@ public function check( ->build(); } + $argumentsCount = null; if (!$hasNamedArguments) { $invokedParametersCount = count($arguments); foreach ($arguments as [2 => $unpack]) { @@ -320,7 +325,13 @@ public function check( break; } } + $argumentsCount = [$invokedParametersCount, $functionParametersMinCount, $functionParametersMaxCount]; + } elseif (!$isPartialApplication) { + $argumentsCount = self::getNamedArgumentsCount($arguments, $parametersAcceptor, $namedCallVariants); + } + if ($argumentsCount !== null) { + [$invokedParametersCount, $functionParametersMinCount, $functionParametersMaxCount] = $argumentsCount; if ( // ... of a partial application fills in the parameters left ($invokedParametersCount < $functionParametersMinCount && !$hasVariadicPlaceholder) @@ -1312,6 +1323,78 @@ public static function getVariantForArgumentsCount(array $args, array $variants, return null; } + return self::getClosestVariant($argsCount, $variants); + } + + /** + * PHP resolves named arguments against the one signature php-src stubs declare, + * passes the default of each parameter they skip, and then the function checks + * the number of arguments like for a positional call: mt_rand(min: 1) throws. + * So the count is checked against the variants like a positional call's. + * + * @param array $arguments + * @param list $variants + * @return array{int, int, int}|null the arguments count and the minimum and maximum (-1 when variadic) to report it against, null when a variant accepts it + */ + private static function getNamedArgumentsCount(array $arguments, ParametersAcceptor $namedArgumentsVariant, array $variants): ?array + { + if (count($variants) < 2) { + return null; + } + + $positionsByName = []; + foreach ($namedArgumentsVariant->getParameters() as $i => $parameter) { + if ($parameter->isVariadic()) { + continue; + } + $positionsByName[$parameter->getName()] = $i; + } + + $passedPositions = []; + foreach ($arguments as $i => [, , $unpack, $argumentName]) { + if ($unpack) { + return null; + } + if ($argumentName === null) { + $passedPositions[$i] = true; + continue; + } + if (!array_key_exists($argumentName, $positionsByName)) { + // reported as an unknown parameter + return null; + } + $passedPositions[$positionsByName[$argumentName]] = true; + } + + $argsCount = $passedPositions === [] ? 0 : max(array_keys($passedPositions)) + 1; + foreach ($namedArgumentsVariant->getParameters() as $i => $parameter) { + if ($i >= $argsCount) { + break; + } + if (!array_key_exists($i, $passedPositions) && $parameter->getDefaultValue() instanceof ErrorType) { + // PHP throws before the function checks the count + return null; + } + } + + $combinedVariant = ParametersAcceptorSelector::combineAcceptors($variants); + $variant = self::acceptsArgumentsCount($combinedVariant, $argsCount) + ? self::getClosestVariant($argsCount, $variants) + : $combinedVariant; + if ($variant === null) { + return null; + } + + [$minCount, $maxCount] = self::getArgumentsCountRange($variant); + + return [$argsCount, $minCount, $maxCount ?? -1]; + } + + /** + * @param list $variants + */ + private static function getClosestVariant(int $argsCount, array $variants): ?ParametersAcceptor + { $closestVariant = null; $closestDistance = null; foreach ($variants as $variant) { diff --git a/src/Rules/Functions/CallCallablesRule.php b/src/Rules/Functions/CallCallablesRule.php index ec0c9cd0656..4d1227726b8 100644 --- a/src/Rules/Functions/CallCallablesRule.php +++ b/src/Rules/Functions/CallCallablesRule.php @@ -10,8 +10,11 @@ use PHPStan\DependencyInjection\AutowiredParameter; use PHPStan\DependencyInjection\RegisteredRule; use PHPStan\Internal\SprintfHelper; +use PHPStan\Node\Expr\TypeExpr; use PHPStan\Reflection\InaccessibleMethod; +use PHPStan\Reflection\ParametersAcceptor; use PHPStan\Reflection\ParametersAcceptorSelector; +use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; @@ -38,6 +41,7 @@ final class CallCallablesRule implements Rule public function __construct( private FunctionCallParametersCheck $check, private RuleLevelHelper $ruleLevelHelper, + private ReflectionProvider $reflectionProvider, #[AutowiredParameter] private bool $reportMaybes, ) @@ -106,11 +110,12 @@ public function processNode( ))->identifier('callable.inaccessibleMethod')->build(); } + $namedArgumentsVariants = $this->getCalleeNamedArgumentsVariants($type, $node, $scope); $parametersAcceptor = ParametersAcceptorSelector::selectFromArgs( $scope, $node->getArgs(), $parametersAcceptors, - null, + $namedArgumentsVariants, ); foreach ($node->getArgs() as $arg) { @@ -158,10 +163,60 @@ public function processNode( 'Combining constants with | is not allowed for %s of ' . $callableDescription . '.', null, null, + $namedArgumentsVariants !== null ? $parametersAcceptors : [], ), ); } + /** + * A first-class callable of a multi-variant built-in is a union of closures, one per variant, + * but PHP resolves named arguments against the one signature of its callee. + * + * @return list|null + */ + private function getCalleeNamedArgumentsVariants(Type $type, Node\Expr\FuncCall $node, Scope $scope): ?array + { + $members = $type instanceof UnionType ? $type->getTypes() : [$type]; + $origin = null; + foreach ($members as $member) { + if (!$member instanceof ClosureType) { + return null; + } + $memberOrigin = $member->getOrigin(); + if ($memberOrigin === null || !$memberOrigin->isFirstClassCallable()) { + return null; + } + if ($origin !== null && !$origin->equals($memberOrigin)) { + return null; + } + $origin = $memberOrigin; + } + if ($origin === null) { + return null; + } + + $call = $origin->createCall($node, $members[0]); + if ($call instanceof Node\Expr\FuncCall && $call->name instanceof Node\Name) { + if (!$this->reflectionProvider->hasFunction($call->name, $scope)) { + return null; + } + + return $this->reflectionProvider->getFunction($call->name, $scope)->getNamedArgumentsVariants(); + } + if ($call instanceof Node\Expr\MethodCall) { + $calledOn = $call->var; + } elseif ($call instanceof Node\Expr\StaticCall) { + $calledOn = $call->class; + } else { + return null; + } + if (!$calledOn instanceof TypeExpr || !$call->name instanceof Node\Identifier) { + return null; + } + + return $scope->getMethodReflection($calledOn->getExprType(), $call->name->toString())?->getNamedArgumentsVariants(); + } + /** * Whether every closure the type can be is a variadic one a partial function application * created with the parameter bound - its call then throws "Named parameter overwrites diff --git a/src/Rules/Functions/CallToFunctionParametersRule.php b/src/Rules/Functions/CallToFunctionParametersRule.php index dca5ec06e86..3e9b133c5a0 100644 --- a/src/Rules/Functions/CallToFunctionParametersRule.php +++ b/src/Rules/Functions/CallToFunctionParametersRule.php @@ -77,6 +77,7 @@ public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataE 'Combining constants with | is not allowed for %s of function ' . $functionName . '.', null, $function, + $function->getNamedArgumentsVariants() !== null ? $function->getVariants() : [], ); } diff --git a/src/Type/ClosureOrigin.php b/src/Type/ClosureOrigin.php index 2748baaf9b9..bb072684e4a 100644 --- a/src/Type/ClosureOrigin.php +++ b/src/Type/ClosureOrigin.php @@ -101,6 +101,11 @@ public function getBoundParameterNames(): array return $this->boundParameterNames; } + public function isFirstClassCallable(): bool + { + return $this->partialApplicationArgs === null; + } + /** * Whether the closure is one of a method called on an object, bound to that object for * good: unbinding it fails. Closure::__invoke(...) is the closure itself, so it does not count. diff --git a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php index 7ba694444fc..497936b5bce 100644 --- a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php +++ b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php @@ -464,16 +464,12 @@ public function testBug7048(): void 'Unknown parameter $recurrences in call to DatePeriod constructor.', 21, ], - [ - 'Missing parameter $end (int|TEnd of DateTimeInterface) in call to DatePeriod constructor.', - 18, - ], [ 'Unknown parameter $isostr in call to DatePeriod constructor.', 25, ], [ - 'Missing parameter $start (string) in call to DatePeriod constructor.', + 'Missing parameter $start (string|TDate of DateTimeInterface) in call to DatePeriod constructor.', 24, ], [ diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index a2d10154ae5..8ee0a598f32 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -49,6 +49,7 @@ protected function getRule(): Rule checkMissingTypehints: true, ), $ruleLevelHelper, + $reflectionProvider, reportMaybes: true, ); } @@ -200,6 +201,25 @@ public function testNamedArguments(): void ]); } + #[RequiresPhp('>= 8.1.0')] + public function testNamedArgumentsOfMultiVariantFirstClassCallable(): void + { + $this->analyse([__DIR__ . '/data/callables-named-arguments-multi-variant.php'], [ + [ + 'Callable (Closure(): int)|(Closure(int, int): int) invoked with 1 parameter, 2 required.', + 7, + ], + [ + 'Argument #2 ($close) must be passed explicitly, because the default value is not known.', + 11, + ], + [ + 'Callable (Closure(array<(int&TK)|(string&TK), TV>, array<(int&TK)|(string&TK), TV>, array, array|callable(mixed, mixed): int, array|callable(mixed, mixed): int ...): array<(int&TK)|(string&TK), TV>)|(Closure(array<(int&TK)|(string&TK), TV>, array<(int&TK)|(string&TK), TV>, callable(TV, TV): int): array<(int&TK)|(string&TK), TV>) invoked with 1 parameter, at least 3 required.', + 14, + ], + ]); + } + public static function dataBug3566(): array { return [ diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 18bf131bdf3..43e424ce46b 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -1868,6 +1868,25 @@ public function testNamedParametersForMultiVariantFunctions(): void $this->analyse([__DIR__ . '/data/call-to-function-named-params-multivariant.php'], []); } + #[RequiresPhp('>= 8.0.0')] + public function testNamedArgumentsCountOfMultiVariantFunctions(): void + { + $this->analyse([__DIR__ . '/data/call-to-function-named-params-multivariant-errors.php'], [ + [ + 'Function mt_rand invoked with 1 parameter, 2 required.', + 5, + ], + [ + 'Argument #1 ($min) must be passed explicitly, because the default value is not known.', + 6, + ], + [ + 'Function array_udiff invoked with 1 parameter, at least 3 required.', + 8, + ], + ]); + } + public function testBug9793(): void { $errors = []; diff --git a/tests/PHPStan/Rules/Functions/data/call-to-function-named-params-multivariant-errors.php b/tests/PHPStan/Rules/Functions/data/call-to-function-named-params-multivariant-errors.php new file mode 100644 index 00000000000..130139c5abf --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/call-to-function-named-params-multivariant-errors.php @@ -0,0 +1,8 @@ += 8.0 + +namespace CallToFunctionNamedParamsMultiVariantErrors; + +mt_rand(min: 1); +mt_rand(max: 1); +mt_rand(min: 1, max: 2); +array_udiff(array: [1]); diff --git a/tests/PHPStan/Rules/Functions/data/callables-named-arguments-multi-variant.php b/tests/PHPStan/Rules/Functions/data/callables-named-arguments-multi-variant.php new file mode 100644 index 00000000000..465a37e2d77 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/callables-named-arguments-multi-variant.php @@ -0,0 +1,15 @@ += 8.1 + +namespace CallablesNamedArgumentsMultiVariant; + +function (callable $open, callable $read): void { + $f = mt_rand(...); + $f(min: 1); + $f(min: 1, max: 2); + + $g = session_set_save_handler(...); + $g($open, read: $read); + + $h = array_udiff(...); + $h(array: [1]); +}; diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index f4d2d5532f6..fac7245ac79 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -3338,7 +3338,7 @@ public function testNamedParametersForMultiVariantFunctions(): void 10, ], [ - 'Missing parameter $name (array) in call to method XSLTProcessor::setParameter().', + 'Missing parameter $name (array|string) in call to method XSLTProcessor::setParameter().', 10, ], [ diff --git a/turbo-ext/src/ParametersAcceptorSelector.cpp b/turbo-ext/src/ParametersAcceptorSelector.cpp index 5fe4bb41658..4fb98b1eca2 100644 --- a/turbo-ext/src/ParametersAcceptorSelector.cpp +++ b/turbo-ext/src/ParametersAcceptorSelector.cpp @@ -791,10 +791,6 @@ class ParametersAcceptorSelector HashTable *typesTable = Z_ARRVAL_P(types); zend_long typesCount = zend_hash_num_elements(typesTable); zv::Arr acceptableAcceptors = zv::Arr::empty(); - // a named argument only fits a variant that has its parameter, like - // session_set_save_handler($open, read: $read), unless no variant has it - zv::Arr acceptableAcceptorsWithNames = zv::Arr::empty(); - bool someAcceptorHasNames = false; for (zv::ArrayEntry entry : zv::TableRef(acceptors)) { zval *parametersAcceptor = entry.value().deref().raw(); @@ -805,7 +801,6 @@ class ParametersAcceptorSelector zend_long functionParametersMinCount = 0; zend_long functionParametersMaxCount = 0; - zv::Arr parameterNames = zv::Arr::create(0); zv::Val parameters = acceptorParameters(parametersAcceptor); if (UNEXPECTED(parameters.isUndef())) return zv::Val(); for (zv::ArrayEntry parameterEntry : zv::ArrRef(parameters.raw())) { @@ -816,42 +811,15 @@ class ParametersAcceptorSelector } functionParametersMaxCount++; - zv::Val parameterName = parameterGet(parameterEntry.value().deref().raw(), PG_NAME); - if (UNEXPECTED(parameterName.isUndef())) return zv::Val(); - if (Z_TYPE_P(parameterName.raw()) == IS_STRING) { - zval trueValue; - ZVAL_TRUE(&trueValue); - zend_symtable_update(parameterNames.table(), Z_STR_P(parameterName.raw()), &trueValue); - } } - bool isVariadic = false; - if (UNEXPECTED(!acceptorIsVariadic(parametersAcceptor, isVariadic))) return zv::Val(); - - bool hasNames = true; - if (!isVariadic) { - for (zv::ArrayEntry typeEntry : zv::TableRef(typesTable)) { - zend_string *key = typeEntry.stringKeyOrNull(); - if (key != NULL && zend_symtable_find(parameterNames.table(), key) == NULL) { - hasNames = false; - break; - } - } - } - someAcceptorHasNames = someAcceptorHasNames || hasNames; - if (typesCount < functionParametersMinCount) continue; + bool isVariadic = false; + if (UNEXPECTED(!acceptorIsVariadic(parametersAcceptor, isVariadic))) return zv::Val(); if (!isVariadic && typesCount > functionParametersMaxCount) continue; acceptableAcceptors.push(zv::Ref(parametersAcceptor)); - if (!hasNames) continue; - - acceptableAcceptorsWithNames.push(zv::Ref(parametersAcceptor)); - } - - if (someAcceptorHasNames) { - acceptableAcceptors = std::move(acceptableAcceptorsWithNames); } uint32_t acceptableCount = zend_hash_num_elements(acceptableAcceptors.table()); @@ -1249,12 +1217,7 @@ class ParametersAcceptorSelector zv::Val defaultValueRight = parameterGet(parameter, PG_DEFAULT_VALUE); if (UNEXPECTED(defaultValueRight.isUndef())) return zv::Val(); zv::Val defaultValue = zv::Val::null(); - if (Z_TYPE_P(defaultValueLeft.raw()) == IS_OBJECT && instanceof_function(Z_OBJCE_P(defaultValueLeft.raw()), pt_ce_error_type)) { - // the parameter of the real signature keeps its unknown default - defaultValue = std::move(defaultValueLeft); - } else if (Z_TYPE_P(defaultValueRight.raw()) == IS_OBJECT && instanceof_function(Z_OBJCE_P(defaultValueRight.raw()), pt_ce_error_type)) { - defaultValue = std::move(defaultValueRight); - } else if (!defaultValueLeft.isNull() && !defaultValueRight.isNull()) { + if (!defaultValueLeft.isNull() && !defaultValueRight.isNull()) { defaultValue = union2(defaultValueLeft.raw(), defaultValueRight.raw()); if (UNEXPECTED(defaultValue.isUndef())) return zv::Val(); }