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

Cannot call method on ternary with common parent class #10552

Closed
bwoebi opened this issue Jan 14, 2024 · 1 comment
Closed

Cannot call method on ternary with common parent class #10552

bwoebi opened this issue Jan 14, 2024 · 1 comment

Comments

@bwoebi
Copy link

bwoebi commented Jan 14, 2024

Having a conditional type like (IsClient is true ? Child1 : Child2) and calling a method on it will fail with InvalidMethodCall, though all methods on the intersection Child1&Child2 should be trivially callable.

https://psalm.dev/r/1629e589b7

Copy link

I found these snippets:

https://psalm.dev/r/1629e589b7
<?php

class Old {
    public function x(): void {}
}
class Child1 extends Old {}
class Child2 extends Old {}

/**
 * @template IsClient of bool
 */
class A {
    /**
     * @psalm-param (IsClient is true ? Child1 : Child2) $var
     */
    public function test(Old $var): void {
        $var->x();
    }
}
Psalm output (using commit a75d26a):

ERROR: InvalidMethodCall - 17:15 - Cannot call method on (IsClient is true ? Child1 : Child2) variable $var

@danog danog closed this as completed in f7edaa6 Jan 18, 2024
danog added a commit that referenced this issue Jan 18, 2024
danog added a commit that referenced this issue Jan 19, 2024
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