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
23 changes: 18 additions & 5 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5609,11 +5609,24 @@ private function processAssignVar(
} else {
$varForSetOffsetValue = $var->var;
}
$assignedPropertyExpr = new SetOffsetValueTypeExpr(
$varForSetOffsetValue,
$var->dim,
$assignedPropertyExpr,
);

if (
$var === $originalVar
&& $var->dim !== null
&& $scope->hasExpressionType($var)->yes()
) {
$assignedPropertyExpr = new SetExistingOffsetValueTypeExpr(
$varForSetOffsetValue,
$var->dim,
$assignedPropertyExpr,
);
} else {
$assignedPropertyExpr = new SetOffsetValueTypeExpr(
$varForSetOffsetValue,
$var->dim,
$assignedPropertyExpr,
);
}
Comment on lines +5613 to +5629
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this change, we make sure PropertyAssignNode contains a proper type.
we already had the right type in scope from a previous fix.

$dimFetchStack[] = $var;
$var = $var->var;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,4 +935,11 @@ public function testBug11777(): void
$this->analyse([__DIR__ . '/data/bug-11777.php'], []);
}

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

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

namespace Bug13035;

use function PHPStan\debugScope;
use function PHPStan\Testing\assertType;

class HelloWorld
{
/**
* @var list<int>
*/
public array $list = [];

public function bug(int $offset): void
{
if (isset($this->list[$offset])) {
$this->list[$offset] = 123;
}
}
}
Loading