Skip to content

ImplicitToStringCast not emitted for arrays #5320

@weph

Description

@weph

Given this code:

/**
 * @psalm-param array<array-key, string> $bars
 */
function foo(array $bars): void
{
}

class Bar {
    public function __toString()
    {
        return 'bar';
    }
}

foo([new Bar()]);

I'd expect an ImplicitToStringCast error to be emitted. But it doesn't.
After changing the array to a list, however, the error will be emitted

/**
 * @psalm-param list<string> $bars
 */
function foo(array $bars): void
{
}

class Bar {
    public function __toString()
    {
        return 'bar';
    }
}

foo([new Bar()]);

https://psalm.dev/r/ee207d52b3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions