facebook / hhvm

A virtual machine for executing programs written in Hack.
https://hhvm.com
Other
18.06k stars 2.99k forks source link

Using nameof syntax leads to parse errors #9447

Open varungandhi-src opened 4 weeks ago

varungandhi-src commented 4 weeks ago

Describe the bug

The code examples on the nameof page lead to parse errors.

Standalone code, or other way to reproduce the problem

class B {}
class C extends B {}
trait T {
    require extends B;
    public static function f(): void {
        var_dump(nameof T); // "T"
        var_dump(nameof self); // "D" (user of trait)
        var_dump(nameof parent); // "C" (parent of trait user, not B)
        var_dump(nameof static); // "E", receiver for ::f() in main
    }
}
class D extends C { use T; }
class E extends D {}

<<__EntryPoint>>
function main(): void {
  E::f();
}

Steps to reproduce the behavior:

  1. Copy-paste the above code in tmp.hack and run hhvm tmp.hack. I tested with the Docker container

Expected behavior

Code should run (or at least parse) properly.

Actual behavior

Fatal error: Encountered unexpected token `T`. in /home/tmp.hack on line 6

Environment

HipHop VM 4.172.0 (rel) (non-lowptr)
Compiler: 1667340154_989010953
Repo schema: 63eaf8b56fb7edbc7a8ca9e32786eb0c1f8f508c

Additional context

We're trying to add support for Hack syntax highlighting in Sourcegraph here: https://github.com/sourcegraph/sourcegraph/pull/62770 and were going through the official docs for code examples.

lexidor commented 3 weeks ago

The version of hhvm you are using is not the latest version. nameof is very new. Your version of hhvm does not support this syntax.