Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Analyser/ArgumentsNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ public static function reorderArgs(ParametersAcceptor $parametersAcceptor, array
return array_values($callArgs);
}

foreach ($callArgs as $arg) {
if ($arg->unpack) {
// the number of parameters an unpacked argument fills is unknown here,
// so the positions of the named arguments that follow it cannot be determined
return null;
}
}

$hasVariadic = false;
$argumentPositions = [];
$signatureParameters = $parametersAcceptor->getParameters();
Expand Down
58 changes: 58 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-15778.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php // lint >= 8.1

declare(strict_types=1);

namespace Bug15778;

use function PHPStan\Testing\assertType;

/** @return ($key is null ? null : string) */
function label(?string $key = null, ?string $locale = null): ?string
{
return $key;
}

/** @return ($b is null ? null : string) */
function second(?string $a = null, ?string $b = null, ?string $key = null): ?string
{
return $b;
}

class Foo
{

/** @return ($key is null ? null : string) */
public function label(?string $key = null, ?string $locale = null): ?string
{
return $key;
}

/** @return ($key is null ? null : string) */
public static function staticLabel(?string $key = null, ?string $locale = null): ?string
{
return $key;
}

/** @return ($b is null ? null : string) */
public function second(?string $a = null, ?string $b = null, ?string $key = null): ?string
{
return $b;
}

}

function doFoo(Foo $foo): void
{
assertType('string', label(locale: 'en', key: 'welcome'));
assertType('string', label(...['locale' => 'en'], key: 'welcome'));
assertType('string', label(...[], key: 'welcome'));
assertType('string', second(...['x', 'y'], key: 'welcome'));
assertType('null', second(...['x'], key: 'welcome'));
assertType('array', array_slice(...[[1, 2, 3]], offset: 1));

assertType('string', $foo->label(...['locale' => 'en'], key: 'welcome'));
assertType('string', $foo->label(...[], key: 'welcome'));
assertType('string', $foo->second(...['x', 'y'], key: 'welcome'));
assertType('string', Foo::staticLabel(...['locale' => 'en'], key: 'welcome'));
assertType('string', Foo::staticLabel(...[], key: 'welcome'));
}
2 changes: 1 addition & 1 deletion tests/bench/ArgumentsNormalizerBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function boot(bool $named): void
*/
#[DataProvider(method: 'calls')]
#[ExpectedFor(dataSet: 'named', instructions: '24.75K', cycles: '99.67K', memory: '2.516KiB')]
#[ExpectedFor(dataSet: 'positional', instructions: '2.670K', cycles: '21.83K', memory: '0B')]
#[ExpectedFor(dataSet: 'positional', instructions: '2.729K', cycles: '22.86K', memory: '0B')]
public function benchReorderFuncArguments(bool $named): ?FuncCall
{
if ($this->acceptor === null || $this->call === null) {
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/FileCacheStorageBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function boot(int $entries): void
* @throws DirectoryCreatorException
*/
#[DataProvider(method: 'entries')]
#[ExpectedFor(dataSet: 'entries-100', instructions: '234.2K', cycles: '550.6K', memory: '17.29KiB')]
#[ExpectedFor(dataSet: 'entries-100', instructions: '246.5K', cycles: '582.7K', memory: '17.29KiB')]
#[ExpectedFor(dataSet: 'entries-10000', instructions: '18.84M', cycles: '29.57M', memory: '1.345MiB')]
public function benchSave(int $entries): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/bench/NullsafeOperatorHelperBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function boot(int $depth, bool $nullsafe): void
*/
#[DataProvider(method: 'levelsWithoutNullsafe')]
#[ExpectedFor(dataSet: 'levels-16', instructions: '74.18K', cycles: '124.6K', memory: '6.242KiB')]
#[ExpectedFor(dataSet: 'levels-64', instructions: '283.4K', cycles: '379.1K', memory: '23.87KiB')]
#[ExpectedFor(dataSet: 'levels-64', instructions: '289.2K', cycles: '373.1K', memory: '23.87KiB')]
public function benchGetNullsafeShortcircuitedExprOfEveryLevel(int $depth, bool $nullsafe): int
{
$unchanged = 0;
Expand All @@ -104,7 +104,7 @@ public function benchGetNullsafeShortcircuitedExprOfEveryLevel(int $depth, bool
*/
#[DataProvider(method: 'chains')]
#[ExpectedFor(dataSet: 'innermost-nullsafe-64', instructions: '263.0K', cycles: '363.3K', memory: '9.609KiB')]
#[ExpectedFor(dataSet: 'without-nullsafe-64', instructions: '173.3K', cycles: '258.8K', memory: '23.87KiB')]
#[ExpectedFor(dataSet: 'without-nullsafe-64', instructions: '177.1K', cycles: '255.0K', memory: '23.87KiB')]
public function benchGetNullsafeShortcircuitedExpr(int $depth, bool $nullsafe): Expr
{
if ($this->chain === null) {
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/OperatorTypeSpecifyingExtensionBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function boot(string $extension, string $operands): void
#[ExpectedFor(dataSet: 'bcmath-integers', instructions: '317.4K', cycles: '383.8K', memory: '0B')]
#[ExpectedFor(dataSet: 'bcmath-objects', instructions: '665.4K', cycles: '781.7K', memory: '216B')]
#[ExpectedFor(dataSet: 'gmp-integers', instructions: '302.1K', cycles: '367.6K', memory: '0B')]
#[ExpectedFor(dataSet: 'gmp-objects', instructions: '593.5K', cycles: '718.6K', memory: '216B')]
#[ExpectedFor(dataSet: 'gmp-objects', instructions: '606.5K', cycles: '721.9K', memory: '216B')]
public function benchSpecify(string $extension, string $operands): int
{
if ($this->extension === null) {
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/RuleBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function boot(string $rule, string $code, ?int $phpVersion): void
#[ExpectedFor(dataSet: 'function-conditional-return-type-without-conditional-types', instructions: '148.3K', cycles: '159.0K', memory: '376B')]
#[ExpectedFor(dataSet: 'impossible-check-type-function-call', instructions: '6.250M', cycles: '8.182M', memory: '5.758KiB')]
#[ExpectedFor(dataSet: 'instantiation-restricted-constructor', instructions: '3.628M', cycles: '5.050M', memory: '6.742KiB')]
#[ExpectedFor(dataSet: 'node-connecting-visitor-attributes-no-arguments', instructions: '38.75K', cycles: '40.87K', memory: '40B')]
#[ExpectedFor(dataSet: 'node-connecting-visitor-attributes-no-arguments', instructions: '39.53K', cycles: '41.61K', memory: '40B')]
#[ExpectedFor(dataSet: 'old-php-parser4-class-outside-class', instructions: '20.96K', cycles: '22.23K', memory: '0B')]
#[ExpectedFor(dataSet: 'parameter-castable-to-string-diff-assoc', instructions: '6.028M', cycles: '6.950M', memory: '3.172KiB')]
#[ExpectedFor(dataSet: 'restricted-function-usage', instructions: '287.9K', cycles: '355.2K', memory: '848B')]
Expand Down
4 changes: 2 additions & 2 deletions tests/bench/TrinaryLogicBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function boot(int $count): void
}

#[DataProvider(method: 'operands')]
#[ExpectedFor(dataSet: 'operands-1', instructions: '1.111M', cycles: '1.135M', memory: '0B')]
#[ExpectedFor(dataSet: 'operands-1', instructions: '1.134M', cycles: '1.154M', memory: '0B')]
#[ExpectedFor(dataSet: 'operands-4', instructions: '2.427M', cycles: '2.450M', memory: '216B')]
public function benchAnd(int $operands): TrinaryLogic
{
Expand All @@ -75,7 +75,7 @@ public function benchAnd(int $operands): TrinaryLogic
}

#[DataProvider(method: 'operands')]
#[ExpectedFor(dataSet: 'operands-1', instructions: '1.111M', cycles: '1.136M', memory: '0B')]
#[ExpectedFor(dataSet: 'operands-1', instructions: '1.134M', cycles: '1.155M', memory: '0B')]
#[ExpectedFor(dataSet: 'operands-4', instructions: '2.427M', cycles: '2.451M', memory: '216B')]
public function benchOr(int $operands): TrinaryLogic
{
Expand Down
9 changes: 9 additions & 0 deletions turbo-ext/src/ArgumentsNormalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ class ArgumentsNormalizer
}
if (EXPECTED(!hasNamedArgs)) return arrayValues(callArgs);

for (zv::ArrayEntry entry : zv::TableRef(args)) {
zv::Val unpackHold;
zval *unpack = readProperty(pt_an_arg_unpack_site, entry.value().deref().raw(), PT_LC("unpack"), unpackHold);
if (UNEXPECTED(unpack == NULL)) return zv::Val();
// the number of parameters an unpacked argument fills is unknown here,
// so the positions of the named arguments that follow it cannot be determined
if (zend_is_true(unpack)) return zv::Val::null();
}

return reorderNamedArgs(parametersAcceptor, args);
}

Expand Down
Loading