Calling a shared protected interface method in an object of another class is allowed by the typechecker, but fatals at runtime.
- Dominant language
- C++
- Stars
- 18.7k
- Forks
- 3.1k
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 2
Description
**Describe the bug**
Given interface `IDoStuff` which declares `protected ->doStuff(): int`, `StuffDoer implements IDoStuff`, and `DoerOfStuff implements IDoStuff`, then `DoerOfStuff` can't call `StuffDoer->doStuff()` at runtime. The typechecker is fine with it though.
**Standalone code, or other way to reproduce the problem**
```HACK
doStuff();
}
}
<<__EntryPoint>>
function main(): void {
$stuff_doer = new StuffDoer();
$doer_of_stuff = new DoerOfStuff();
\var_dump($doer_of_stuff->doOtherStuff($doer_of_stuff));
\var_dump($doer_of_stuff->doOtherStuff($stuff_doer));
}
```
Steps to reproduce the behavior:
1. Run hh_client, `No errors!`
2. Run hhvm, `Fatal error: Call to protected method StuffDoer::doStuff() from context 'DoerOfStuff'`
**Expected behavior**
This should be allowed, since `->doStuff()` is protected from `IDoStuff` down. This means that all implementers of this interface should have access to this method of any other implementer.
**Actual behavior**
```
int(420)
Fatal error: Call to protected method StuffDoer::doStuff() from context 'DoerOfStuff' in doer_of_stuff.php on line 19
```
**Environment**
- Operating system
> Ubuntu 20.04
- Installation method
> apt-get with dl.hhvm.com repository
- HHVM Version
```
HipHop VM 4.100.0 (rel)
Compiler: 1615322845_674785974
Repo schema: d1ae8e21bf3419a65f12a010527485564e719d07
hackc-f55c2cc67914fb44d806dc33d898a1d48b796508-4.100.0
```
**Additional context**
#7358 is another mention of protected interface methods. (PHP doesn't have them, so I can't compare the behavior of PHP to hhvm).
Contributor guide
Research direction
Start by running the standalone doer_of_stuff.php reproducer with hh_client and hhvm, confirming that typechecking succeeds while the cross-implementer call fatals. Trace the protected interface method handling in the typechecker and runtime. Done means the accepted call no longer produces a fatal and the behavior matches the stated expected result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100