Skip to content

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

Open

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.

Activity

  1. payal76027-svg commented on Aug 27, 2025

    @payal76027-svg

    <<file: ThisDoesNotExist(ThisIsNotBeingChecked::class)>><<file: ThisDoesNotExist(ThisIsNotBeingChecked::class)>>
    function f(): void {}<<file: ThisDoesNotExist(ThisIsNotBeingChecked::class)>>
    const int X = 1;
    const int Y = 2;
    const int Z = X + Y;

  2. haowanaa commented on Aug 27, 2025

    @haowanaa
  3. ktmb9494-oss commented on Nov 20, 2025

    @ktmb9494-oss

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

  4. ktmb9494-oss commented on Nov 20, 2025

    @ktmb9494-oss

  5. changed the title [-]File-level attribute annotations are not typechecked when file declares zero non-const entities[/-] [+][ Typechecker ] File-level attribute annotations are not typechecked when file declares zero non-const entities[/+] on Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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