mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Use current context when analyzing attributes (fixes #7710).
This commit is contained in:
parent
ad91df5ee1
commit
04c0db5aff
@ -27,6 +27,7 @@ class AttributeAnalyzer
|
||||
*/
|
||||
public static function analyze(
|
||||
SourceAnalyzer $source,
|
||||
Context $context,
|
||||
AttributeStorage $attribute,
|
||||
AttributeGroup $attribute_group,
|
||||
array $suppressed_issues,
|
||||
@ -111,7 +112,7 @@ class AttributeAnalyzer
|
||||
new NodeDataProvider()
|
||||
);
|
||||
|
||||
$statements_analyzer->analyze(self::attributeGroupToStmts($attribute_group), new Context());
|
||||
$statements_analyzer->analyze(self::attributeGroupToStmts($attribute_group), $context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -400,6 +400,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
|
||||
foreach ($storage->attributes as $i => $attribute) {
|
||||
AttributeAnalyzer::analyze(
|
||||
$this,
|
||||
$class_context,
|
||||
$attribute,
|
||||
$class->attrGroups[$i],
|
||||
$storage->suppressed_issues + $this->getSuppressedIssues(),
|
||||
@ -1526,6 +1527,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
|
||||
foreach ($property_storage->attributes as $i => $attribute) {
|
||||
AttributeAnalyzer::analyze(
|
||||
$source,
|
||||
$context,
|
||||
$attribute,
|
||||
$stmt->attrGroups[$i],
|
||||
$this->source->getSuppressedIssues(),
|
||||
|
@ -822,6 +822,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
||||
foreach ($storage->attributes as $i => $attribute) {
|
||||
AttributeAnalyzer::analyze(
|
||||
$this,
|
||||
$context,
|
||||
$attribute,
|
||||
$this->function->attrGroups[$i],
|
||||
$storage->suppressed_issues + $this->getSuppressedIssues(),
|
||||
@ -1271,6 +1272,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
||||
foreach ($function_param->attributes as $i => $attribute) {
|
||||
AttributeAnalyzer::analyze(
|
||||
$this,
|
||||
$context,
|
||||
$attribute,
|
||||
$param_stmts[$offset]->attrGroups[$i],
|
||||
$storage->suppressed_issues,
|
||||
|
@ -95,10 +95,12 @@ class InterfaceAnalyzer extends ClassLikeAnalyzer
|
||||
}
|
||||
|
||||
$class_storage = $codebase->classlike_storage_provider->get($fq_interface_name);
|
||||
$interface_context = new Context($this->getFQCLN());
|
||||
|
||||
foreach ($class_storage->attributes as $i => $attribute) {
|
||||
AttributeAnalyzer::analyze(
|
||||
$this,
|
||||
$interface_context,
|
||||
$attribute,
|
||||
$this->class->attrGroups[$i],
|
||||
$class_storage->suppressed_issues + $this->getSuppressedIssues(),
|
||||
@ -113,7 +115,7 @@ class InterfaceAnalyzer extends ClassLikeAnalyzer
|
||||
|
||||
$type_provider = new NodeDataProvider();
|
||||
|
||||
$method_analyzer->analyze(new Context($this->getFQCLN()), $type_provider);
|
||||
$method_analyzer->analyze($interface_context, $type_provider);
|
||||
|
||||
$actual_method_id = $method_analyzer->getMethodId();
|
||||
|
||||
|
@ -264,6 +264,25 @@ class AttributeTest extends TestCase
|
||||
class C {}
|
||||
',
|
||||
],
|
||||
'attributeUsesClassContext' => [
|
||||
'<?php
|
||||
#[Attribute]
|
||||
class SomeAttr
|
||||
{
|
||||
/** @param class-string $class */
|
||||
public function __construct(string $class) {}
|
||||
}
|
||||
|
||||
#[SomeAttr(self::class)]
|
||||
class A {}
|
||||
|
||||
#[SomeAttr(parent::class)]
|
||||
class B extends A {}
|
||||
|
||||
#[SomeAttr(self::class)]
|
||||
interface C {}
|
||||
',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -403,6 +422,20 @@ class AttributeTest extends TestCase
|
||||
false,
|
||||
'8.0'
|
||||
],
|
||||
'noParentInAttributeOnClassWithoutParent' => [
|
||||
'<?php
|
||||
#[Attribute]
|
||||
class SomeAttr
|
||||
{
|
||||
/** @param class-string $class */
|
||||
public function __construct(string $class) {}
|
||||
}
|
||||
|
||||
#[SomeAttr(parent::class)]
|
||||
class A {}
|
||||
',
|
||||
'error_message' => 'ParentNotFound',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user