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

File-level attribute annotations are not typechecked when file declares zero non-const entities #9508

Open
lexidor opened this issue Aug 10, 2024 · 0 comments
Labels

Comments

@lexidor
Copy link
Collaborator

lexidor commented Aug 10, 2024

Describe the bug
When declaring a file attribute, the typechecker should make sure the attribute class exists and that the constructor arguments typecheck. This check is not performed when the file does not declare any entities, or if all the declared entities are top-level constant declarations.

Standalone code, or other way to reproduce the problem

Simple case, no errors.

<<file: ThisDoesNotExist(ThisIsNotBeingChecked::class)>>

The file only contains constants, no errors.

<<file: ThisDoesNotExist(ThisIsNotBeingChecked::class)>>
const int X = 1;
const int Y = 2;
const int Z = X + Y;

The file contains a non-constant, f.e. a function, 3 errors.

<<file: ThisDoesNotExist(ThisIsNotBeingChecked::class)>>
function f(): void {}

Steps to reproduce the behavior:

  1. Typecheck the examples provided above

Expected behavior

All three cases should emit the following three errors.

Naming[2049] Unbound name: ThisDoesNotExist (an object type) [1]

bug.hack:1:9
[1] 1 | <<file: ThisDoesNotExist(ThisIsNotBeingChecked::class)>>
    2 | function f(): void {}

Naming[2049] Unrecognized user attribute: ThisDoesNotExist does not have a class. Please declare a class for the attribute. [1]

bug.hack:1:9
[1] 1 | <<file: ThisDoesNotExist(ThisIsNotBeingChecked::class)>>
    2 | function f(): void {}

Naming[2049] Unbound name: ThisIsNotBeingChecked (an object type) [1]

bug.hack:1:26
[1] 1 | <<file: ThisDoesNotExist(ThisIsNotBeingChecked::class)>>
    2 | function f(): void {}

Actual behavior

Only the third case, emits errors

Environment

  • Operating system

Debian GNU/Linux 12 (bookworm)

  • Installation method

hhvm/hhvm on dockerhub

  • HHVM Version

HipHop VM 4.168.2 (rel) (non-lowptr), hackc-af2b2722e8cac3d0bc5fe213eeb16d7296da458f-4.168.2

Additional context
This is an edge case, reported for completeness sake.

@lexidor lexidor added the hack label Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant