Rework enable_strict_const_semantics to consider the hierarchy in aggregate
commit87e647e38f1bba1d3cea52836c9bdb443e91da7b
authorVassil Mladenov <vmladenov@fb.com>
Thu, 28 Apr 2022 13:32:04 +0000 (28 06:32 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 28 Apr 2022 13:32:04 +0000 (28 06:32 -0700)
tree94b8f859637d888e340e912217b6c9241a87541a
parent3c0c12f425021a640a739841033a45f4a489c1b4
Rework enable_strict_const_semantics to consider the hierarchy in aggregate

Summary:
Enable_strict_const_semantics is now an int flag instead of a bool, but a bool is still accepted by .hhconfig
  - `1` and `true` are equivalent, and they cause class `B1` defined below to raise an error
  - `2` now raises an error for the definition of `B2`.

Adds an error when there is an inheritance conflict, which was previously missing in the case where the child overrides the constant.

Previously,

```
trait T1 {
  const int X = 4;
}
trait T2 {
  const int X = 5;
}
class A {
  use T1;
}
class B1 /* error here */ extends A {
  use T2;
}
```
```
T1
 \
  A   T2
   \  /
    B1
```
This is an error on B1, but if we  declared X locally, the error would disappear
```
// no errors
class B2 extends A {
  const int X = 6;
  use T2;
}
```
Both cases are fatals under HHVM flag.

Also, this check fires for all kinds of constants (class, type, ctx) because it does not exlude the backing TypeStructure constants, unlike the `check_const` call.

Facebook

~5k errors in www https://www.internalfb.com/intern/everpaste/?color=0&handle=GK10pBDe_jFp6hgQAOEB0BcVaMk6bjEQAAAz

Reviewed By: CatherineGasnier

Differential Revision: D35886138

fbshipit-source-id: 49d2c6dfc38abf08e0a6ba55d1bc27300ab76fd6
32 files changed:
hphp/hack/src/compare_folded_decls_file.ml
hphp/hack/src/errors/typing_error.ml
hphp/hack/src/errors/typing_error.mli
hphp/hack/src/hh_single_decl.ml
hphp/hack/src/hh_single_type_check.ml
hphp/hack/src/options/globalOptions.ml
hphp/hack/src/options/globalOptions.mli
hphp/hack/src/oxidized/gen/global_options.rs
hphp/hack/src/oxidized/manual/global_options_impl.rs
hphp/hack/src/oxidized_by_ref/gen/global_options.rs
hphp/hack/src/oxidized_by_ref/manual/global_options_impl.rs
hphp/hack/src/server/serverConfig.ml
hphp/hack/src/typing/typing_extends.ml
hphp/hack/src/utils/config_file/config_file_common.ml
hphp/hack/src/utils/config_file/config_file_common.mli
hphp/hack/test/typecheck/stricter_consts/HH_FLAGS
hphp/hack/test/typecheck/stricter_consts/class_interface_1.bad.php.exp
hphp/hack/test/typecheck/stricter_consts/class_trait_1.bad.php.exp
hphp/hack/test/typecheck/stricter_consts/conflict_3.bad.php [new file with mode: 0644]
hphp/hack/test/typecheck/stricter_consts/conflict_3.bad.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/stricter_consts/conflict_via.bad.php [new file with mode: 0644]
hphp/hack/test/typecheck/stricter_consts/conflict_via.bad.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/stricter_consts/conflict_with_override.bad.php [new file with mode: 0644]
hphp/hack/test/typecheck/stricter_consts/conflict_with_override.bad.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/stricter_consts/interface_class_interface_1.bad.php.exp
hphp/hack/test/typecheck/stricter_consts/interface_class_interface_class_1.bad.php.exp
hphp/hack/test/typecheck/stricter_consts/interface_interface_1.bad.php.exp
hphp/hack/test/typecheck/stricter_consts/interface_trait_2.bad.php.exp
hphp/hack/test/typecheck/stricter_consts/interface_trait_class_interface_trait_class_1.bad.php.exp
hphp/hack/test/typecheck/stricter_consts/trait_class_trait_class_1.bad.php.exp
hphp/hack/test/typecheck/stricter_consts/trait_trait_1.bad.php.exp
hphp/hack/test/typecheck/stricter_consts/trait_typeconst_1.bad.php.exp