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

When a (typed or not) constant is used on object, the type is lost #10870

Open
spaze opened this issue Mar 30, 2024 · 1 comment
Open

When a (typed or not) constant is used on object, the type is lost #10870

spaze opened this issue Mar 30, 2024 · 1 comment

Comments

@spaze
Copy link

spaze commented Mar 30, 2024

When a (typed or not) constant is used on object ($object::CONST), the type is lost:

class Foo
{
    public const string TYPED = 'string';
    public const NOTYPE = 'string';
}

works, no error:

func(Foo::TYPED);
func(Foo::NOTYPE);

both throw "Argument 1 of func cannot be mixed, expecting string":

func((new Foo)::TYPED);
func((new Foo)::NOTYPE);

https://psalm.dev/r/0a3523524e

May be loosely related to #10700

Copy link

I found these snippets:

https://psalm.dev/r/0a3523524e
<?php
class Foo
{
    public const string TYPED = 'string';
    public const NOTYPE = 'string';
}

function func(string $param): void { echo $param; }

func(Foo::TYPED);
func((new Foo)::TYPED);
func(Foo::NOTYPE);
func((new Foo)::NOTYPE);
Psalm output (using commit ef3b018):

INFO: MixedArgument - 11:6 - Argument 1 of func cannot be mixed, expecting string

INFO: MixedArgument - 13:6 - Argument 1 of func cannot be mixed, expecting string

spaze added a commit to spaze/michalspacek.cz that referenced this issue Mar 30, 2024
See vimeo/psalm#10870

But then all other errors, marked as "other issues" until now, are promoted to real errors so they have to be baselined. This could be reverted once the Psalm error is resolved somehow.
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

No branches or pull requests

1 participant