Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-worman committed May 26, 2023
1 parent b99857c commit f279c39
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Expand Up @@ -981,17 +981,23 @@ public static function analyzeAssignmentRef(
$context->references_to_external_scope[$lhs_var_id] = true;
}
if (strpos($rhs_var_id, '->') !== false) {
IssueBuffer::maybeAdd(new UnsupportedPropertyReferenceUsage(
new CodeLocation($statements_analyzer->getSource(), $stmt),
));
IssueBuffer::maybeAdd(
new UnsupportedPropertyReferenceUsage(
new CodeLocation($statements_analyzer->getSource(), $stmt),
),
$statements_analyzer->getSuppressedIssues(),
);
// Reference to object property, we always consider object properties to be an external scope for references
// TODO handle differently so it's detected as unused if the object is unused?
$context->references_to_external_scope[$lhs_var_id] = true;
}
if (strpos($rhs_var_id, '::') !== false) {
IssueBuffer::maybeAdd(new UnsupportedPropertyReferenceUsage(
new CodeLocation($statements_analyzer->getSource(), $stmt),
));
IssueBuffer::maybeAdd(
new UnsupportedPropertyReferenceUsage(
new CodeLocation($statements_analyzer->getSource(), $stmt),
),
$statements_analyzer->getSuppressedIssues(),
);
}

$lhs_location = new CodeLocation($statements_analyzer->getSource(), $stmt->var);
Expand Down
19 changes: 19 additions & 0 deletions tests/UnsupportedPropertyReferenceUsage.php
Expand Up @@ -5,11 +5,30 @@
namespace Psalm\Tests;

use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;

class UnsupportedPropertyReferenceUsage extends TestCase
{
use ValidCodeAnalysisTestTrait;
use InvalidCodeAnalysisTestTrait;

public function providerValidCodeParse(): iterable
{
return [
'can be suppressed' => [
'code' => <<<'PHP'
<?php
class A {
public int $b = 0;
}
$a = new A();
/** @psalm-suppress UnsupportedPropertyReferenceUsage */
$b = &$a->b;
PHP,
],
];
}

public function providerInvalidCodeParse(): iterable
{
return [
Expand Down

0 comments on commit f279c39

Please sign in to comment.