-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Unsound behaviour allowed with return static #8809
Comments
I think the only way to prevent this is to prohibit |
Thanks - FB T87049790 |
On T87049790, @dlreeves wrote:
|
FYI I solved this in Psalm by introducing a Using it forces all child classes to have the exact same template params with the same constraints and requires them to map directly to the parent params. <<__ConsistentConstruct>>
<<__ConsistentGeneric>>
abstract class C1<T> {
final public function __construct(private T $value) {}
public static function from(mixed $value): this {
return new static($value); // would be allowed
}
public function getValue() : T {
return $this->value;
}
}
final class C2 extends C1<string> {} // fail
final class C3<T3, TOther> extends C1<T3> {} // fail
final class C4<T4> extends C1<mixed> {} // fail
final class C5<T5 as object> extends C1<T5> {} // fail
final class C6<T6> extends C1<T6> {} // pass |
Expected behavior
Some sort of typechecker error maybe?
Actual behavior
No error (but running this produces a
TypeError
)Environment
hhvm 4.100
Would be very interested to know how this might be handled. Related issue here: vimeo/psalm#5383
The text was updated successfully, but these errors were encountered: