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

First type in an intersection type, used as a type parameter for a class-string, in a union of class-strings, gets dropped from the union. #10799

Closed
rzvc opened this issue Mar 9, 2024 · 2 comments · Fixed by #10800
Labels
bug intersections Issues related to intersection types

Comments

@rzvc
Copy link

rzvc commented Mar 9, 2024

Sorry for the title. It's slightly incorrect, but didn't want to make it longer. The code below exemplifies the issue quite well:
https://psalm.dev/r/69a0df463f

Copy link

I found these snippets:

https://psalm.dev/r/69a0df463f
<?php

interface IFoo
{
}

interface IBar
{
}

class Foo implements IFoo
{
}

class Bar implements IBar
{
}

class FooBar implements IFoo, IBar
{
}

/**
* @param class-string<IFoo>|class-string<IBar>|class-string<IFoo & IBar> $class
*/
function test1($class) : void
{
    echo $class;
}

test1(Foo::class);
test1(Bar::class);
test1(FooBar::class);


/**
* @param class-string<IFoo>|class-string<IBar>|class-string<IBar & IFoo> $class
*/
function test2($class) : void
{
    echo $class;
}

test2(Foo::class);
test2(Bar::class);
test2(FooBar::class);
Psalm output (using commit 3600d51):

ERROR: InvalidArgument - 31:7 - Argument 1 of test1 expects class-string<IBar>|class-string<IFoo&IBar>, but Foo::class provided

ERROR: InvalidArgument - 45:7 - Argument 1 of test2 expects class-string<IBar&IFoo>|class-string<IFoo>, but Bar::class provided

@weirdan
Copy link
Collaborator

weirdan commented Mar 9, 2024

The linked PR changes the interpretation of class-string<IBar>|class-string<IFoo>|class-string<IBar & IFoo> to class-string<IBar>|class-string<IFoo> (regardless of the order of the intersection).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug intersections Issues related to intersection types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants