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
2 changes: 1 addition & 1 deletion src/Analyser/ArgumentsNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public static function reorderArgs(ParametersAcceptor $parametersAcceptor, array
continue;
}
if (!array_key_exists($j, $signatureParameters)) {
throw new ShouldNotHappenException('Parameter signatures cannot have holes');
return null;
}

$parameter = $signatureParameters[$j];
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,13 @@ public function testBug14550(): void
$this->assertNotEmpty($errors);
}

public function testBug14596(): void
{
// crash
$errors = $this->runAnalyse(__DIR__ . '/data/bug-14596.php');
$this->assertNotEmpty($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return list<Error>
Expand Down
27 changes: 27 additions & 0 deletions tests/PHPStan/Analyser/ArgumentsNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,33 @@ public static function dataReorderInvalid(): iterable
[new StringType(), 'three'],
],
];

// positional arg after named arg with variadic parameter
yield [
[
['value', false, false, null],
['values', true, true, new StringType()],
],
[
[new IntegerType(), null],
[new IntegerType(), null],
[new IntegerType(), null],
[new StringType(), 'd'],
[new IntegerType(), null],
],
];

// positional arg after named arg without variadic parameter
yield [
[
['one', false, false, null],
],
[
[new IntegerType(), null],
[new StringType(), 'd'],
[new IntegerType(), null],
],
];
}

/**
Expand Down
34 changes: 34 additions & 0 deletions tests/PHPStan/Analyser/data/bug-14596.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Bug14596;

function foo(int $a, int $b, int $c, string ...$rest): void {}

class Foo {
public function bar(int $a, int $b, int $c, string ...$rest): void {}
public static function baz(int $a, int $b, int $c, string ...$rest): void {}
public function __construct(int $a, int $b, int $c, string ...$rest) {}
}

// built-in function
\PHPStan\dumpType(1, 2, 3, d: 'foo', 5);

// user-defined function
foo(1, 2, 3, d: 'foo', 5);

// method call
$obj = new Foo(1, 2, 3);
$obj->bar(1, 2, 3, d: 'foo', 5);

// static method call
Foo::baz(1, 2, 3, d: 'foo', 5);

// constructor
new Foo(1, 2, 3, d: 'foo', 5);

// closure
$closure = function (int $a, int $b, int $c, string ...$rest): void {};
$closure(1, 2, 3, d: 'foo', 5);

// call_user_func
call_user_func('Bug14596\foo', 1, 2, 3, d: 'foo', 5);
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4102,4 +4102,18 @@ public function testBug8048(): void
$this->analyse([__DIR__ . '/data/bug-8048.php'], []);
}

#[RequiresPhp('>= 8.0.0')]
public function testBug14596(): void
{
$this->checkThisOnly = false;
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->analyse([__DIR__ . '/data/bug-14596.php'], [
[
'Named argument cannot be followed by a positional argument.',
11,
],
]);
}

}
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1037,4 +1037,16 @@ public function testBug11894(): void
$this->analyse([__DIR__ . '/data/bug-11894.php'], []);
}

#[RequiresPhp('>= 8.0.0')]
public function testBug14596(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-14596.php'], [
[
'Named argument cannot be followed by a positional argument.',
12,
],
]);
}

}
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-14596.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Bug14596Methods;

class Foo {
public function bar(int $a, int $b, int $c, string ...$rest): void {}
public static function baz(int $a, int $b, int $c, string ...$rest): void {}
}

function (Foo $obj): void {
$obj->bar(1, 2, 3, d: 'foo', 5);
Foo::baz(1, 2, 3, d: 'foo', 5);
};
Loading