I have defined an interface with the return type static. Afterwards I implemented a generic class that uses the interface. When I call the interface method the type is not correctly resolved. See the example:
I fix the error by added a doc comment in the class implementation:
class Collection implements CopyInterface {
/** @return static */ # <--- This line solves the problem
public function copy(): static {
// No real implementation
return $this;
}
}
https://psalm.dev/r/b59404794e
```php
x = $x;
}
public function copy(): static {
// No real implementation
return $this;
}
}
/** @var Collection $intCollection */
$intCollection = new Collection([1]);
// The following function is only to check the inferred types
/** @param Collection $x */
function checkCollection($x): string {
return get_class($x);
}
checkCollection($intCollection);
checkCollection($intCollection->copy());
```
```
Psalm output (using commit f2db139):
INFO: MixedArgumentTypeCoercion - 36:17 - Argument 1 of checkCollection expects Collection, parent type Collection&Collection provided
```
Hi,
I have defined an interface with the return type
static
. Afterwards I implemented a generic class that uses the interface. When I call the interface method the type is not correctly resolved. See the example:https://psalm.dev/r/b59404794e
I fix the error by added a doc comment in the class implementation:
Is this an intended behavior?