Skip to content

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

@lexidor

Description

@lexidor

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions