facebook / facebook/hhvm

Unexpected fatal error at runtime, with no corresponding typechecker error, when constructing a class that extends an abstract class using a generic payload `payload_t`.

Open
#8,763 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

**Describe the bug**
Unexpected fatal error at runtime, with no corresponding typechecker error, when constructing a class that extends an abstract class using a generic payload `payload_t`.

**Standalone code, or other way to reproduce the problem**
```
type payload_t = shape('type' => string, ...);
abstract class Event {
abstract const type TPayload as payload_t;
protected this::TPayload $payload;
}
type example_payload_t = shape(
'type' => string,
'test' => string,
);
final class TestEvent extends Event {
const type TPayload = example_payload_t;
public function __construct(
protected example_payload_t $payload,
) {}
}
<<__EntryPoint>>
function main(): void {
$event = new TestEvent(shape(
'type' => 'example',
'test' => 'example',
));
}
```

Steps to repro the error message:
`hhvm -d hhvm.check_prop_type_hints=3 test.hack`

**Expected behavior**

We were able to solve the problem with this fix:
```
public function __construct(
protected this::TPayload $payload,
) {}
```

This was a scary error to receive, since no type checker error happens, but we get a fatal error at runtime for no discernible reason. We aren't sure if this should be **caught as a typechecker error, or if this is an issue with the runtime**.

**Actual behavior**

```
Fatal error: Uncaught Error: Type-hint of 'TestEvent::payload' must be (as in class Event), not example_payload_t in /Users/ssandler/Documents/dev/webapp/test.hack:27
Stack trace:
#0 (): main()
#1 {main}
```

**Environment**
- Operating system
**MacOS Catalina**
- Installation method
**homebrew**
- HHVM Version
```
hhvm --version
HipHop VM 4.80.0 (rel)
Compiler: 1603142563_N
Repo schema: 09d2af8dd22201dd8d48e5dcfcaed281ff9422c7
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.