hhvm
hhvm copied to clipboard
[ Typechecker built-in lint ] "Loop variable `_` shadows a local variable" (5568) ignores lambda cow
Describe the bug
hh_client --lint
believes a variable that is declared outside a lambda can be shadowed inside a lambda.
Standalone code, or other way to reproduce the problem
function false_shadow(): void {
$false_shadow = 42;
(vec<int> $things) ==> {
foreach ($things as $false_shadow) {
// do something with $false_shadow
}
};
}
Steps to reproduce the behavior:
- Go to Invoke
hh_client --lint this_file.hack
Expected behavior
The foreach
loop inside the lambda does not write to the outer $false_shadow
. The lambda has a cow scope.
Actual behavior
Lint[5568] Loop variable $false_shadow shadows a local variable defined or last assigned here:
File "path/to/this_file.hack", line 2, characters 5-17: [1]
src/false_shadow.hack:4:29
2 | $false_shadow = 42;
3 | (vec<int> $things) ==> {
[1] 4 | foreach ($things as $false_shadow) {
5 | // do something with $false_shadow
6 | }
Environment
- Operating system
Irrelevant
- Installation method
hhvm/hhvm on dockerhub
- HHVM Version
HipHop VM 4.146.0 (rel) (non-lowptr)
Compiler: 1643142756_285035995
Repo schema: f559125a34cec281a617647f42d18bd793318580
hackc-9ddd1899e3c5cf4954e903514c8f4d89beadd202-4.146.0
Additional context
The same thing also applies to async {}
blocks.
This code is still smelly. The lint error message led me to believe that renaming this variable might change the behavior of the code. The enclosing function in which I encountered this lint error was rather large. It took me a while to realize that they never shadowed each other.
Should be fixed by D39003052.