hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

Allow whitelisting unrecognized __Foo attributes with user_attributes= in .hhconfig

Open fredemmott opened this issue 9 years ago • 5 comments

Revert of https://github.com/facebook/hhvm/commit/ec1031e25c189a12e0e89eb151c796da0b8fcdb2 ?

Potentially more useful for third-party code than FB - eg:

  • vendor/foo/ uses a new user attribute from 3.7 which doesn't have runtime effects
  • however, the main project keeps supporting (and being developed on) older versions

Otherwise, this is potentially an artificial restriction for library compatibility/feature adoption.

Some future attributes may have runtime effects, but leaving that to the user seems reasonable.

cc @elgenie

fredemmott avatar Mar 02 '15 18:03 fredemmott

Example:

[fredemmott@devbig076 ~/hhtest] cat test.php
<?hh

<<__Bogus>>
function foo() {
}

<<Bogus>>
function bar() {
}
[fredemmott@devbig076 ~/hhtest] cat .hhconfig
assume_php=false
user_attributes=__Bogus,Bogus
[fredemmott@devbig076 ~/hhtest] myhh_client
/home/fredemmott/hhtest/test.php:3:3,9: Unrecognized user attribute: __Bogus starts with __ but is not a standard attribute (Naming[2049])

fredemmott avatar Mar 02 '15 18:03 fredemmott

@elgenie what do you think? This could be useful for forwards-compatibility.

jwatzman avatar Mar 03 '15 05:03 jwatzman

Chatted. Side-effect: whitelisting anything requires whitelisting /everything/. Possibly add a separate whitelist just for unknown builtins that doesn't introduce that

fredemmott avatar Mar 07 '15 02:03 fredemmott

The modern equivalent of this would be the following, however this produces a typeerror.

class __Foo implements \HH\FunctionAttribute {}

<<__Foo()>>
function foo(): void {}
Naming[2049] Unrecognized user attribute: __Foo starts with __ but is not a standard attribute
   --> file.hack
  9 | <<__Foo()>>
    |   ^^^^^

1 error found.

The typechecker error message here is a bit misleading "Unrecognized user attribute".

lexidor avatar May 20 '20 20:05 lexidor

My code sample is invalid Hack. Double underscores are reserved for hhvm internals. The class declaration class __Foo {} is disallowed in documentation-only.

lexidor avatar Oct 04 '23 23:10 lexidor