[ Typechecker ] Invoking a static method on a classname of an interface is allowed, but a reified T of an interface is not
- Dominant language
- C++
- Stars
- 18.7k
- Forks
- 3.1k
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 2
Description
**Describe the bug**
Invoking a static method on a classname of an interface is allowed, but a reified T of an interface is not.
**Standalone code, or other way to reproduce the problem**
```HACK
interface IFace {
public static function doIt(): void;
public static function returnIt(): int;
}
final class MyClass implements IFace {
public static function doIt(): void {
echo "I am doing the 'it'\n";
}
public static function returnIt(): int {
return 42;
}
}
function do_the_it_with_this_class(classname $iface): void {
$iface::doIt();
}
function return_it_with_the_class(classname $iface): void {
$iface::returnIt();
}
function return_it_with_reified_generics(): void {
// This is a typechecker error, which is correct, but very limiting.
// Typing[4073] Cannot call IFace::returnIt(); it is abstract
T::returnIt();
}
```
Steps to reproduce the behavior:
1. Run the typechecker
**Expected behavior**
With the current semantics of interfaces in Hack, both `$iface::returnIt()` and `T::returnIt()` may invoke an abstract (interface) method. This is not sound and an error should be raised for both.
**Actual behavior**
Currently, `T::returnIt()` is an error, but `$iface::returnIt()` is not.
```
Typing[4073] Cannot call IFace::returnIt(); it is abstract
--> src/file.hack
35 | public static function returnIt(): int;
| ^^^^^^^^ Declaration is here
58 | T::returnIt();
|
```
**Feature request**
Moved to issue #8713
Copy-paste output, or add a screenshot to illustrate what actually happens. Copy-pasted text output (e.g. from `hhvm` or `hh_client`) is preferred to screenshots.
```
Typing[4073] Cannot call IFace::returnIt(); it is abstract
--> src/file.hack
35 | public static function returnIt(): int;
| ^^^^^^^^ Declaration is here
58 | T::returnIt();
| ^^^^^^^^
1 error found.
```
**Environment**
- Operating system: Ubuntu 20.04
- Installation method: apt-get dl.hhvm.com
- HHVM Version: 4.56
```
HipHop VM 4.56.0 (rel)
Compiler: 1588614387_226336535
Repo schema: d1ae8e21bf3419a65f12a010527485564e719d07
hackc-0b10dd000fc9b454637d8dffc67fb542d231572c-4.56.0
```
Contributor guide
Assessment
This issue has not been assessed yet.