mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #6922 from weirdan/cases-references
This commit is contained in:
commit
608e8d11fa
@ -1627,35 +1627,36 @@ class ClassLikes
|
||||
|
||||
$storage = $this->classlike_storage_provider->get($class_name);
|
||||
|
||||
if (!isset($storage->constants[$constant_name])) {
|
||||
return null;
|
||||
if (isset($storage->constants[$constant_name])) {
|
||||
$constant_storage = $storage->constants[$constant_name];
|
||||
|
||||
if ($visibility === ReflectionProperty::IS_PUBLIC
|
||||
&& $constant_storage->visibility !== ClassLikeAnalyzer::VISIBILITY_PUBLIC
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($visibility === ReflectionProperty::IS_PROTECTED
|
||||
&& $constant_storage->visibility !== ClassLikeAnalyzer::VISIBILITY_PUBLIC
|
||||
&& $constant_storage->visibility !== ClassLikeAnalyzer::VISIBILITY_PROTECTED
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($constant_storage->unresolved_node) {
|
||||
$constant_storage->type = new Type\Union([ConstantTypeResolver::resolve(
|
||||
$this,
|
||||
$constant_storage->unresolved_node,
|
||||
$statements_analyzer,
|
||||
$visited_constant_ids
|
||||
)]);
|
||||
}
|
||||
|
||||
return $constant_storage->type;
|
||||
} elseif (isset($storage->enum_cases[$constant_name])) {
|
||||
return new Type\Union([new Type\Atomic\TEnumCase($storage->name, $constant_name)]);
|
||||
}
|
||||
|
||||
$constant_storage = $storage->constants[$constant_name];
|
||||
|
||||
if ($visibility === ReflectionProperty::IS_PUBLIC
|
||||
&& $constant_storage->visibility !== ClassLikeAnalyzer::VISIBILITY_PUBLIC
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($visibility === ReflectionProperty::IS_PROTECTED
|
||||
&& $constant_storage->visibility !== ClassLikeAnalyzer::VISIBILITY_PUBLIC
|
||||
&& $constant_storage->visibility !== ClassLikeAnalyzer::VISIBILITY_PROTECTED
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($constant_storage->unresolved_node) {
|
||||
$constant_storage->type = new Type\Union([ConstantTypeResolver::resolve(
|
||||
$this,
|
||||
$constant_storage->unresolved_node,
|
||||
$statements_analyzer,
|
||||
$visited_constant_ids
|
||||
)]);
|
||||
}
|
||||
|
||||
return $constant_storage->type;
|
||||
return null;
|
||||
}
|
||||
|
||||
private function checkMethodReferences(ClassLikeStorage $classlike_storage, Methods $methods): void
|
||||
|
@ -7,7 +7,7 @@ class ConstantTest extends TestCase
|
||||
use Traits\ValidCodeAnalysisTestTrait;
|
||||
|
||||
/**
|
||||
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
|
||||
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[], php_version?: string}>
|
||||
*/
|
||||
public function providerValidCodeParse(): iterable
|
||||
{
|
||||
@ -1180,6 +1180,22 @@ class ConstantTest extends TestCase
|
||||
|
||||
}',
|
||||
],
|
||||
'classConstantReferencingEnumCase' => [
|
||||
'<?php
|
||||
enum E {
|
||||
case Z;
|
||||
}
|
||||
class C {
|
||||
public const CC = E::Z;
|
||||
}
|
||||
$c = C::CC;
|
||||
',
|
||||
'assertions' => [
|
||||
'$c===' => 'enum(E::Z)'
|
||||
],
|
||||
[],
|
||||
'8.1'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -154,6 +154,26 @@ class EnumTest extends TestCase
|
||||
[],
|
||||
'8.1'
|
||||
],
|
||||
'SKIPPED-wildcardEnum' => [
|
||||
'<?php
|
||||
enum A {
|
||||
case C_1;
|
||||
case C_2;
|
||||
case C_3;
|
||||
|
||||
/**
|
||||
* @param self::C_* $i
|
||||
*/
|
||||
public static function foo(self $i) : void {}
|
||||
}
|
||||
|
||||
A::foo(A::C_1);
|
||||
A::foo(A::C_2);
|
||||
A::foo(A::C_3);',
|
||||
'assertions' => [],
|
||||
[],
|
||||
'8.1',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ use const PHP_VERSION;
|
||||
trait ValidCodeAnalysisTestTrait
|
||||
{
|
||||
/**
|
||||
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
|
||||
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[],php_version?:string}>
|
||||
*/
|
||||
abstract public function providerValidCodeParse(): iterable;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user