Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 10 additions & 7 deletions src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public function check(
$functionParametersMaxCount = -1;
}

if (!$scope instanceof MutatingScope) {
throw new ShouldNotHappenException();
}

/** @var array<int, array{Expr, Type|null, bool, string|null, int}> $arguments */
$arguments = [];
/** @var array<int, Node\Arg> $args */
Expand All @@ -114,6 +118,10 @@ public function check(
$argumentName = $arg->name->toString();
}

if ($arg->value instanceof Expr\Assign) {
$scope = $scope->assignExpression($arg->value->var, $scope->getType($arg->value->expr), $scope->getNativeType($arg->value->expr));
}

if ($hasNamedArguments && $arg->unpack) {
$errors[] = RuleErrorBuilder::message('Named argument cannot be followed by an unpacked (...) argument.')
->identifier('argument.unpackAfterNamed')
Expand Down Expand Up @@ -318,14 +326,9 @@ public function check(
}

if ($argumentValueType === null) {
if ($scope instanceof MutatingScope) {
$scope = $scope->pushInFunctionCall(null, $parameter);
}
$scope = $scope->pushInFunctionCall(null, $parameter);
$argumentValueType = $scope->getType($argumentValue);

if ($scope instanceof MutatingScope) {
$scope = $scope->popInFunctionCall();
}
$scope = $scope->popInFunctionCall();
}

if (!$acceptsNamedArguments->yes()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2317,4 +2317,11 @@ public function testBug12317(): void
]);
}

public function testBug12234(): void
{
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-12234.php'], []);
}

}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-12234.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Bug12234;

class Foo {
public function getSize(): int {
return 0;
}
}

function bar(Foo $foo, int $b): true {
return true;
}

$test = bar(
$foo = new Foo(),
$foo->getSize(),
);
Loading