Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums cases as attribute params #6982

Closed
Tracked by #6425
weirdan opened this issue Nov 23, 2021 · 5 comments · Fixed by #6984
Closed
Tracked by #6425

Enums cases as attribute params #6982

weirdan opened this issue Nov 23, 2021 · 5 comments · Fixed by #6984

Comments

@weirdan
Copy link
Collaborator

weirdan commented Nov 23, 2021

Enums in attributes are not properly detected for their types https://psalm.dev/r/3615c731dc?php=8.1 (simplified)

Originally posted by @jpresutti in #6425 (comment)

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/3615c731dc
<?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;
}
Psalm output (using commit fdf3a8d):

ERROR: InvalidArgument - 3:24 - Argument 1 of Param::__construct expects ParamType, "Psalm could not infer this type" provided

@weirdan
Copy link
Collaborator Author

weirdan commented Nov 24, 2021

Fixed in #6984

@weirdan weirdan closed this as completed Nov 24, 2021
@jpresutti
Copy link

Thank you for the super quick turnaround on this!

@weirdan
Copy link
Collaborator Author

weirdan commented Nov 24, 2021

I think I've seen @muglug fixing some issues within 15 minutes of them being reported, so we still have some room for improvement 😆

@jpresutti
Copy link

I think I've seen @muglug fixing some issues within 15 minutes of them being reported, so we still have some room for improvement 😆

Either way, @weirdan this was gonna potentially block me from releasing the next version of my framework tomorrow, due to my strict Psalm rule for errorLevel 1 clean with 100% type inference (except in VERY limited cases for psalm-suppress) so this makes me happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants