facebook / facebook/hhvm

Type hole by substitution of generic method type parameter

オープン
#7,828 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
hack
主要言語
C++
スター
18.7k
フォーク
3.1k
平均マージ
1時間 47分
マージ済み PR(30日)
2

説明

### HHVM Version

```
$ hhvm --version
HipHop VM 3.19.1 (rel)
Compiler: tags/HHVM-3.19.1-0-g6129094b1b61e1ae32245a583db0283e645384c1
Repo schema: 062f6c54b49727e83a10a43cdbb861741076e51d
```

### Standalone code, or other way to reproduce the problem

Generic methods can be implemented/overridden by replacing the function's generic parameter with a class-wide one, like so:

```hack
(T $v): void;
}
class C implements I {
public function foo(T $v): void {
$v::some_method();
}
}
```

The implementation vs. the interface contract shouldn't be compatible, but the typechecker doesn't complain. Then, it's pretty easy to break:

```hack
function cast(C $v): void {
violate($v);
}
function violate(I $v): void {
$v->foo(new \stdClass());
}
```

### Expected result

```
(Typing[4120])
Member foo has the wrong type
This is an object of type Base
It is incompatible with a value of generic type T
```

Such is the error if it's `C`'s `foo` instead that redeclares the type `as Base`, e.g.:

```
class C implements I { public function foo(T $v): void // ...
```

### Actual result

```
No errors!
```

But calling `cast(new C());` results in:

```
Fatal error: Call to undefined method stdClass::some_method()
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。