1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #1664 - allow templated __get params

This commit is contained in:
Brown 2019-05-23 12:59:09 -04:00
parent 758c7e22ff
commit 6ce5fefa4b
2 changed files with 49 additions and 1 deletions

View File

@ -479,7 +479,27 @@ class PropertyFetchAnalyzer
continue;
}
$stmt->inferredType = Type::getMixed();
$fake_method_call = new PhpParser\Node\Expr\MethodCall(
$stmt->var,
new PhpParser\Node\Identifier('__get', $stmt->name->getAttributes()),
[
new PhpParser\Node\Arg(
new PhpParser\Node\Scalar\String_(
$prop_name,
$stmt->name->getAttributes()
)
)
]
);
\Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer::analyze(
$statements_analyzer,
$fake_method_call,
$context
);
$stmt->inferredType = $fake_method_call->inferredType ?? Type::getMixed();
/*
* If we have an explicit list of all allowed magic properties on the class, and we're
* not in that list, fall through

View File

@ -387,6 +387,34 @@ class FileReferenceTest extends TestCase
[],
[]
],
'constantRefs' => [
'<?php
namespace Ns;
abstract class A {
public function foo() : void {}
}
trait T {
public function bar(A $a) : void {
$a->foo();
}
}
class C {
use T;
}',
[
'ns\a::foo' => [
'ns\c::bar' => true,
],
],
[],
[],
[],
[],
[]
],
];
}
}