Generic class parameterizing classname<T> has strange rules
- Dominant language
- C++
- Stars
- 18.7k
- Forks
- 3.1k
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 2
Description
### HHVM Version
```
$ hhvm --version
HipHop VM 3.18.0-dev (rel)
Compiler: heads/master-0-g8d0c746272a20e788028868b30ecfb05b17f7eeb
Repo schema: a667780e3ec127b8d894e6a91cfcfb5980ba13e8
```
Reproduced in HHVM 3.16.0-dev.
### Standalone code, or other way to reproduce the problem
```php
>
class Wrapper<+T> {
public function __construct(private T $v) {}
public function get(): T {
return $this->v;
}
}
class Base {}
class OtherBase {
public function fn(): void {}
}
function violate(classname> $C): void {
$wrapped = (new $C(new Base()));
$wrapped->get()->fn();
}
```
A violation can be caused by a `violate(Wrapper::class)`. The typechecker believes `$wrapped` is `Wrapper` following construction, but crucially doesn't complain about `Base` being passed to the constructor.
### Expected result
```
Invalid argument (Typing[4110])
This is an object of type Base
It is incompatible with an object of type OtherBase
```
### Actual result
```
No errors!
```
Contributor guide
Assessment
This issue has not been assessed yet.