Skip to content

Commit

Permalink
Merge pull request #6984 from orklah/enumcase-in-attribute
Browse files Browse the repository at this point in the history
allow using EnumCase in an Attribute
  • Loading branch information
orklah committed Nov 24, 2021
2 parents fdf3a8d + 049285a commit b4d25cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Psalm/Internal/Stubs/Generator/StubsGenerator.php
Expand Up @@ -385,6 +385,10 @@ public static function getExpressionFromType(Type\Union $type) : PhpParser\Node\

return new VirtualArray($new_items);
}

if ($atomic_type instanceof Type\Atomic\TEnumCase) {
return new VirtualClassConstFetch(new VirtualName('\\' . $atomic_type->value), new VirtualIdentifier($atomic_type->case_name));
}
}

return new VirtualString('Psalm could not infer this type');
Expand Down
25 changes: 25 additions & 0 deletions tests/EnumTest.php
Expand Up @@ -174,6 +174,31 @@ public static function foo(self $i) : void {}
[],
'8.1',
],
'EnumCaseInAttribute' => [
'<?php
class CreateController {
#[Param(paramType: ParamType::FLAG)]
public function actionGet(): void {}
}
use Attribute;
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Param {
public function __construct(
public ParamType $paramType = ParamType::PARAM
) {
}
}
enum ParamType {
case FLAG;
case PARAM;
}',
'assertions' => [],
[],
'8.1',
],
];
}

Expand Down

0 comments on commit b4d25cb

Please sign in to comment.