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

Merge pull request #6984 from orklah/enumcase-in-attribute

allow using EnumCase in an Attribute
This commit is contained in:
orklah 2021-11-24 19:52:19 +01:00 committed by GitHub
commit b4d25cbf60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -385,6 +385,10 @@ class StubsGenerator
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');

View File

@ -174,6 +174,31 @@ class EnumTest extends TestCase
[],
'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',
],
];
}