Bug in use type Bar\{Bar};
abhinav-nav opened this issue · 1 comments
Title: Bug in use type Bar{Bar};
Description:
The line use type Bar\{Bar};
imports the type Bar\Bar
as a named type. However, the type Bar\Bar
is actually an abstract class. When the compiler sees the line const Bar\my_type CONFIG = shape('a' => 'b');
, it expects the type Bar\my_type
to be a concrete type. However, since Bar\Bar
is an abstract class, it cannot be a concrete type. This is why the compiler is throwing an error.
Steps to Reproduce:
- Run the following code:
php
namespace Foo;
use namespace Bar;
use type Bar{Bar};
final class FooBar extends Bar {
const Bar\my_type CONFIG = shape('a' => 'b');
}
namespace Bar;
abstract class Bar {
const my_type CONFIG = shape('a' => 'b');
}
type my_type = shape('a' => string);
2. Run the command `hh_client`.
**Expected Behavior:**
The code should compile without any errors.
**Actual Behavior:**
The code will compile with the following error:
File "/root/foo.hack", line 6, characters 28-30:
Some members in class Foo\FooBar
are incompatible with those declared in type Bar\Bar
(Typing[4348])
File "/root/foo.hack", line 13, characters 9-15:
Expected shape('a' => string)
File "/root/foo.hack", line 7, characters 10-20:
But got Bar\Bar\my_type
Workaround:
The workaround for this bug is to use the line use type Bar\Bar;
instead of use type Bar\{Bar};
. This line imports the abstract class Bar\Bar
as a reference type. This means that the compiler will not try to instantiate the class Bar\Bar
as a concrete type.
Suggested Fix:
The suggested fix for this bug is to change the line use type Bar\{Bar};
to use type Bar\Bar;
. This will import the abstract class Bar\Bar
as a reference type, which will prevent the compiler from throwing an error.
Additional Information:
- The bug was found on Docker nightly.
- The HipHop VM version is 6.33.0-dev (rel) (non-lowptr).
- The compiler version is 1676345911_402707174.
- The repo schema is 960a4d092e2e8175b8f0a3b2caecffb7c980c672.
- The breaking diff is e71e870...21598ba.