You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
input:24: PhanUndeclaredMethod Call to undeclared method \Foo::b (Did you mean expr->a())
(Phan 5.4.1)
It seems to me that, if newBar()'s type is Foo&Woop, and Foo::a returns static, then newBar()->a()'s type should also be Foo&Woop – however, it is apparently Foo.
(The same thing happens when the method is documented with @return static, or @return $this, instead of the static PHP type.)
I've tested the same example using Psalm and PHPStan, and they both accept this code:
static
return type loses information about intersection types.Example: https://phan.github.io/demo/?code=%3C%3Fphp%0A%0Aclass+Foo+{%0A%09function+a()%3A+static+{%0A%09%09return+%24this%3B%0A%09}%0A}%0A%0Ainterface+Woop+{%0A%09function+b()%3A+static%3B%0A}%0A%0Aclass+Bar+extends+Foo+implements+Woop+{%0A%09function+b()%3A+static+{%0A%09%09return+%24this%3B%0A%09}%0A}%0A%0Afunction+newBar()%3A+Foo%26Woop+{%0A%09return+new+Bar%3B%0A}%0A%0A(new+Bar)->a()->b()%3B%0AnewBar()->a()->b()%3B%0A
Outputs:
(Phan 5.4.1)
It seems to me that, if
newBar()
's type isFoo&Woop
, andFoo::a
returnsstatic
, thennewBar()->a()
's type should also beFoo&Woop
– however, it is apparentlyFoo
.(The same thing happens when the method is documented with
@return static
, or@return $this
, instead of thestatic
PHP type.)I've tested the same example using Psalm and PHPStan, and they both accept this code:
The text was updated successfully, but these errors were encountered: