Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in use type Bar\{Bar}; #9386

Closed
abhinav-nav opened this issue Aug 5, 2023 · 1 comment
Closed

Bug in use type Bar\{Bar}; #9386

abhinav-nav opened this issue Aug 5, 2023 · 1 comment

Comments

@abhinav-nav
Copy link

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:

  1. 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.
@lexidor
Copy link
Collaborator

lexidor commented Aug 24, 2023

#9335

@lexidor lexidor closed this as not planned Won't fix, can't repro, duplicate, stale Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants