Raise error when a trait is <<__ConsistentConstruct>> but does not declare an explici... nightly-2021.11.10
commit090b485b50c23f26b03b067438277bf1cf492279
authorVassil Mladenov <vmladenov@fb.com>
Wed, 10 Nov 2021 00:52:53 +0000 (9 16:52 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 10 Nov 2021 00:54:19 +0000 (9 16:54 -0800)
treeb880bf6a2500168c8209c01a9144f73002ee1e90
parent30d2bd1eb464b0efdd202a49cc69c01ae2bfd98b
Raise error when a trait is <<__ConsistentConstruct>> but does not declare an explicit constructor

Summary:
Trait method copy-paste behavior breaks down with ConsistentConstruct, where unlike classes, traits to not generate a pure default constructor. This leads to a bug where a trait method can call `new static()` and assume the constructor is pure when it is really impure in the class that uses the trait.

This diff adds a flag to raise an error when a trait is <<__ConsistentConstruct>> without an explicit constructor. If the trait does have a constructor, then it's okay because the class that uses the trait will be forced to be consistent.

For the sake of completeness, I've added an option to raise this error on *all* classish declarations that do not explicitly declare a constructor, as the consistency is really more of a property of the constructor than of the classish.

Reviewed By: jamesjwu

Differential Revision: D32151766

fbshipit-source-id: 74fc75b64316286b66678707dccb471564546b90
21 files changed:
hphp/hack/src/errors/error_codes.ml
hphp/hack/src/errors/errors.ml
hphp/hack/src/errors/errors.mli
hphp/hack/src/hh_single_decl.ml
hphp/hack/src/hh_single_type_check.ml
hphp/hack/src/naming/naming.ml
hphp/hack/src/options/globalOptions.ml
hphp/hack/src/options/globalOptions.mli
hphp/hack/src/options/typecheckerOptions.ml
hphp/hack/src/oxidized/gen/error_codes.rs
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/test/typecheck/construct/explicit_consistent_construct/HH_FLAGS [new file with mode: 0644]
hphp/hack/test/typecheck/construct/explicit_consistent_construct/all/HH_FLAGS [new file with mode: 0644]
hphp/hack/test/typecheck/construct/explicit_consistent_construct/all/all.php [new file with mode: 0644]
hphp/hack/test/typecheck/construct/explicit_consistent_construct/all/all.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/construct/explicit_consistent_construct/trait.php [new file with mode: 0644]
hphp/hack/test/typecheck/construct/explicit_consistent_construct/trait.php.exp [new file with mode: 0644]