Skip to content

Commit

Permalink
Do not report nonexistent variable passed to by-ref parameter with ch…
Browse files Browse the repository at this point in the history
…eckImplicitMixed
  • Loading branch information
ondrejmirtes committed Nov 12, 2024
1 parent 3447391 commit f158d5b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ public function check(

if (
!$parameter->passedByReference()->createsNewVariable()
|| (!$isBuiltin && $this->checkUnresolvableParameterTypes) // bleeding edge only
|| (
!$isBuiltin
&& $this->checkUnresolvableParameterTypes // bleeding edge only
&& !$argumentValueType instanceof ErrorType
)
) {
$accepts = $this->ruleLevelHelper->acceptsWithReason($parameterType, $argumentValueType, $scope->isDeclareStrictTypes());

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

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

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

namespace Bug12015;

class HelloWorld
{

/**
* @param-out int $ref
*/
public static function passRef(?int &$ref): void
{
$ref = 1;
}
}

function test(): void
{
HelloWorld::passRef($storeHere);
echo $storeHere;
}

0 comments on commit f158d5b

Please sign in to comment.