hhvm
hhvm copied to clipboard
Allow whitelisting unrecognized __Foo attributes with user_attributes= in .hhconfig
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
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])
@elgenie what do you think? This could be useful for forwards-compatibility.
Chatted. Side-effect: whitelisting anything requires whitelisting /everything/. Possibly add a separate whitelist just for unknown builtins that doesn't introduce that
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".
My code sample is invalid Hack. Double underscores are reserved for hhvm internals. The class declaration class __Foo {}
is disallowed in documentation-only.