Skip to content

Commit

Permalink
Fix #9824
Browse files Browse the repository at this point in the history
  • Loading branch information
ygottschalk committed May 28, 2023
1 parent d788bcd commit 05e4b86
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Psalm/Internal/PhpVisitor/Reflector/ExpressionResolver.php
Expand Up @@ -305,12 +305,25 @@ public static function getUnresolvedClassConstExpr(
&& $stmt->var->class instanceof PhpParser\Node\Name
&& $stmt->var->name instanceof PhpParser\Node\Identifier
&& $stmt->name instanceof PhpParser\Node\Identifier
&& in_array($stmt->name->name, ['name', 'value', true])
&& in_array($stmt->name->name, ['name', 'value'], true)
&& ($stmt->var->class->parts !== ['self'] || $fq_classlike_name !== null)
&& $stmt->var->class->parts !== ['static']
&& ($stmt->var->class->parts !== ['parent'] || $parent_fq_class_name !== null)
) {
$enum_fq_class_name = ClassLikeAnalyzer::getFQCLNFromNameObject(
$stmt->var->class,
$aliases,
);

if ($stmt->var->class->parts === ['self']) {
$enum_fq_class_name = $fq_classlike_name;
} else {
if ($stmt->var->class->parts === ['parent']) {
assert($parent_fq_class_name !== null);
$enum_fq_class_name = $parent_fq_class_name;
} else {
$enum_fq_class_name = ClassLikeAnalyzer::getFQCLNFromNameObject(
$stmt->var->class,
$aliases,
);
}
}
if ($stmt->name->name === 'value') {
return new EnumValueFetch($enum_fq_class_name, $stmt->var->name->name);

Check failure on line 328 in src/Psalm/Internal/PhpVisitor/Reflector/ExpressionResolver.php

View workflow job for this annotation

GitHub Actions / build

PossiblyNullArgument

src/Psalm/Internal/PhpVisitor/Reflector/ExpressionResolver.php:328:43: PossiblyNullArgument: Argument 1 of Psalm\Internal\Scanner\UnresolvedConstant\EnumValueFetch::__construct cannot be null, possibly null value provided (see https://psalm.dev/078)
} elseif ($stmt->name->name === 'name') {

Check failure on line 329 in src/Psalm/Internal/PhpVisitor/Reflector/ExpressionResolver.php

View workflow job for this annotation

GitHub Actions / build

RedundantConditionGivenDocblockType

src/Psalm/Internal/PhpVisitor/Reflector/ExpressionResolver.php:329:23: RedundantConditionGivenDocblockType: Docblock-defined type 'name' for $stmt->name->name is always =string(name) (see https://psalm.dev/156)
Expand Down
16 changes: 16 additions & 0 deletions tests/ConstantTest.php
Expand Up @@ -1655,6 +1655,22 @@ enum BES: string {
'ignored_issues' => [],
'php_version' => '8.2',
],
'constantEnumSelfReference' => [
'code' => '<?php<?php
enum Bar: string {
case A = "a";
case B = "b";
public const STR = self::A->value . self::B->value;
}
class Foo {
public const CONCAT_STR = "a" . Bar::STR . "e";
}
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.2',
],
'classConstWithParamOut' => [
'code' => '<?php
Expand Down

0 comments on commit 05e4b86

Please sign in to comment.