psalm icon indicating copy to clipboard operation
psalm copied to clipboard

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

Open spaze opened this issue 10 months ago • 1 comments

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

spaze avatar Mar 30 '24 03:03 spaze

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

psalm-github-bot[bot] avatar Mar 30 '24 03:03 psalm-github-bot[bot]