facebook / facebook/hhvm

Type hole by substitution of generic method type parameter

Abierto
#7,828 2 comentarios 0 reacciones 0 asignados Ver en GitHub
hack
Lenguaje dominante
C++
Estrellas
18.7k
Forks
3.1k
Merge medio
1 h 47 min
PR fusionados (30 d)
2

Descripción

### 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()
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.