facebook / facebook/hhvm

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

Open
#9,508 4 comments 0 reactions 0 assignees View on GitHub
hack
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

**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.
```HACK
<>
```

The file only contains constants, no errors.
```HACK
<>
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.
```HACK
<>
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 | <>
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 | <>
2 | function f(): void {}

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

bug.hack:1:26
[1] 1 | <>
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.