Skip to content

Commit 58d208a

Browse files
Francesco Zappa Nardellimeta-codesync[bot]
authored andcommitted
make redundant sealed annotation a warning instead of a lint error
Summary: We used to raise a lint if a classish was sealed against another classish that was not a subtype. The `tco_enforce_sealed_subclasses` option from GlobalOptions turned the lint into a strict error but defaulted to false. This diff removes the global option and the strict error, and turns the lint into a warning. Additionally, fixes the incorrect wording used in a few cases (eg a class does not _extend_ an interface, it _ implements_ it). Reviewed By: mheiber Differential Revision: D89376668 fbshipit-source-id: 548553fae16a50b4c741111d9b029069f6c036b2
1 parent 8aeb303 commit 58d208a

40 files changed

Lines changed: 116 additions & 126 deletions

hphp/hack/src/client_and_server/serverConfig.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,6 @@ let load_config (config : Config_file_common.t) (options : GlobalOptions.t) :
484484
(bool_opt Config_keys.require_extends_implements_ancestors config)
485485
?tco_strict_value_equality:
486486
(bool_opt Config_keys.strict_value_equality config)
487-
?tco_enforce_sealed_subclasses:
488-
(bool_opt Config_keys.enforce_sealed_subclasses config)
489487
?tco_implicit_inherit_sdt:(bool_opt Config_keys.implicit_inherit_sdt config)
490488
?tco_repo_stdlib_path:(string_opt Config_keys.repo_stdlib_path config)
491489
?tco_explicit_consistent_constructors:

hphp/hack/src/diagnostics/error_codes.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ module Typing = struct
737737
| RigidTVarEscape [@value 4442]
738738
| StrictEqValueIncompatibleTypes [@value 4443]
739739
| ModuleError [@value 4444]
740-
| SealedNotSubtype [@value 4445]
740+
(* | SealedNotSubtypeDEPRECATED [@value 4445] *)
741741
| ModuleHintError [@value 4446]
742742
| MemoizeObjectWithoutGlobals [@value 4447]
743743
| ExpressionTreeNonPublicProperty [@value 4448]
@@ -833,6 +833,7 @@ module Warning = struct
833833
| NullsafePipeOnNull [@value 12032]
834834
| UnboundNameWarning [@value 12033]
835835
| SetOrKeysetArrayGet [@value 12034]
836+
| SealedNotSubtype [@value 12035]
836837
(* Add new Warning codes here! Comment out when deprecating. *)
837838
[@@deriving enum, ord, show { with_path = false }]
838839
end

hphp/hack/src/options/globalOptions.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ type t = {
152152
tco_meth_caller_only_public_visibility: bool;
153153
tco_require_extends_implements_ancestors: bool;
154154
tco_strict_value_equality: bool;
155-
tco_enforce_sealed_subclasses: bool;
156155
tco_implicit_inherit_sdt: bool;
157156
tco_repo_stdlib_path: string option;
158157
tco_explicit_consistent_constructors: int;
@@ -277,7 +276,6 @@ let default =
277276
tco_meth_caller_only_public_visibility = true;
278277
tco_require_extends_implements_ancestors = false;
279278
tco_strict_value_equality = false;
280-
tco_enforce_sealed_subclasses = false;
281279
tco_implicit_inherit_sdt = false;
282280
tco_repo_stdlib_path = None;
283281
tco_explicit_consistent_constructors = 0;
@@ -401,7 +399,6 @@ let set
401399
?tco_meth_caller_only_public_visibility
402400
?tco_require_extends_implements_ancestors
403401
?tco_strict_value_equality
404-
?tco_enforce_sealed_subclasses
405402
?tco_implicit_inherit_sdt
406403
?tco_repo_stdlib_path
407404
?tco_explicit_consistent_constructors
@@ -630,10 +627,6 @@ let set
630627
options.tco_require_extends_implements_ancestors;
631628
tco_strict_value_equality =
632629
setting tco_strict_value_equality options.tco_strict_value_equality;
633-
tco_enforce_sealed_subclasses =
634-
setting
635-
tco_enforce_sealed_subclasses
636-
options.tco_enforce_sealed_subclasses;
637630
tco_implicit_inherit_sdt =
638631
setting tco_implicit_inherit_sdt options.tco_implicit_inherit_sdt;
639632
tco_repo_stdlib_path =

hphp/hack/src/options/globalOptions.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ type t = {
193193
(** Consider `require extends` and `require implements` as ancestors when checking a class *)
194194
tco_strict_value_equality: bool;
195195
(** Emit an error when "==" or "!=" is used to compare values that are incompatible types *)
196-
tco_enforce_sealed_subclasses: bool;
197-
(** All member of the __Sealed whitelist should be subclasses*)
198196
tco_implicit_inherit_sdt: bool;
199197
(** Inherit SDT from parents, without writing <<__SupportDynamicType>> *)
200198
tco_repo_stdlib_path: string option;
@@ -383,7 +381,6 @@ val set :
383381
?tco_meth_caller_only_public_visibility:bool ->
384382
?tco_require_extends_implements_ancestors:bool ->
385383
?tco_strict_value_equality:bool ->
386-
?tco_enforce_sealed_subclasses:bool ->
387384
?tco_implicit_inherit_sdt:bool ->
388385
?tco_repo_stdlib_path:string ->
389386
?tco_explicit_consistent_constructors:int ->

hphp/hack/src/options/typecheckerOptions.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ let require_extends_implements_ancestors t =
198198

199199
let strict_value_equality t = t.GlobalOptions.tco_strict_value_equality
200200

201-
let enforce_sealed_subclasses t = t.GlobalOptions.tco_enforce_sealed_subclasses
202-
203201
let repo_stdlib_path t = t.GlobalOptions.tco_repo_stdlib_path
204202

205203
let everything_sdt t = t.GlobalOptions.po.ParserOptions.everything_sdt

hphp/hack/src/oxidized/gen/error_codes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This source code is licensed under the MIT license found in the
44
// LICENSE file in the "hack" directory of this source tree.
55
//
6-
// @generated SignedSource<<0cc28ae99bc1061db33ccad8126c8ba3>>
6+
// @generated SignedSource<<1979bd32cde8ff3069353e3a5093c26e>>
77
//
88
// To regenerate this file, run:
99
// buck run @fbcode//mode/dev-nosan-lg fbcode//hphp/hack/src:oxidized_regen
@@ -519,7 +519,6 @@ pub enum Typing {
519519
RigidTVarEscape = 4442,
520520
StrictEqValueIncompatibleTypes = 4443,
521521
ModuleError = 4444,
522-
SealedNotSubtype = 4445,
523522
ModuleHintError = 4446,
524523
MemoizeObjectWithoutGlobals = 4447,
525524
ExpressionTreeNonPublicProperty = 4448,
@@ -625,6 +624,7 @@ pub enum Warning {
625624
NullsafePipeOnNull = 12032,
626625
UnboundNameWarning = 12033,
627626
SetOrKeysetArrayGet = 12034,
627+
SealedNotSubtype = 12035,
628628
}
629629
impl TrivialDrop for Warning {}
630630
arena_deserializer::impl_deserialize_in_arena!(Warning);

hphp/hack/src/oxidized/gen/global_options.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This source code is licensed under the MIT license found in the
44
// LICENSE file in the "hack" directory of this source tree.
55
//
6-
// @generated SignedSource<<1a93b3740f1d35ca3922e713522f453e>>
6+
// @generated SignedSource<<dca96768b0528150f35179020488742c>>
77
//
88
// To regenerate this file, run:
99
// buck run @fbcode//mode/dev-nosan-lg fbcode//hphp/hack/src:oxidized_regen
@@ -295,8 +295,6 @@ pub struct GlobalOptions {
295295
pub tco_require_extends_implements_ancestors: bool,
296296
/// Emit an error when "==" or "!=" is used to compare values that are incompatible types
297297
pub tco_strict_value_equality: bool,
298-
/// All member of the __Sealed whitelist should be subclasses
299-
pub tco_enforce_sealed_subclasses: bool,
300298
/// Inherit SDT from parents, without writing <<__SupportDynamicType>>
301299
pub tco_implicit_inherit_sdt: bool,
302300
/// Directory of HSL wrappers defined in the repo, warns on unbound name.

hphp/hack/src/oxidized/manual/global_options_impl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ impl Default for GlobalOptions {
103103
tco_meth_caller_only_public_visibility: true,
104104
tco_require_extends_implements_ancestors: false,
105105
tco_strict_value_equality: false,
106-
tco_enforce_sealed_subclasses: false,
107106
tco_implicit_inherit_sdt: false,
108107
tco_explicit_consistent_constructors: 0,
109108
tco_require_types_class_consts: 0,

hphp/hack/src/typing/typing_class.ml

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,10 @@ let check_parent env class_def class_type =
445445
()
446446

447447
(** If the class is sealed, check that the elements of the whitelist
448-
are descendants of the class. Error or lint depending on option
449-
enforce_sealed_subclasses. *)
450-
let sealed_subtype (c : Nast.class_) ~is_enum ~hard_error ~env =
448+
are descendants of the class and emit a warning if not. *)
449+
let sealed_subtype (c : Nast.class_) ~is_enum ~env =
451450
let parent_name = snd c.c_name in
451+
let parent_kind = c.c_kind in
452452
let is_sealed (attr : Nast.user_attribute) =
453453
String.equal (snd attr.ua_name) SN.UserAttributes.uaSealed
454454
in
@@ -481,37 +481,30 @@ let sealed_subtype (c : Nast.class_) ~is_enum ~hard_error ~env =
481481
in
482482
if not includes_ancestor then
483483
let parent_pos = pos in
484-
let child_pos = Cls.pos decl in
485484
let child_name = Cls.name decl in
486485
let class_kind = Cls.kind decl in
487486
let (child_kind, verb) =
488-
match class_kind with
489-
| Ast_defs.Cclass _ -> ("Class", "extend")
490-
| Ast_defs.Cinterface -> ("Interface", "implement")
491-
| Ast_defs.Ctrait -> ("Trait", "use")
492-
| Ast_defs.Cenum -> ("Enum", "use")
493-
| Ast_defs.Cenum_class _ -> ("Enum Class", "extend")
487+
Ast_defs.(
488+
match (parent_kind, class_kind) with
489+
| (Cinterface, Cclass _) -> ("Class", "implement")
490+
| (_, Cclass _) -> ("Class", "extend")
491+
| (Cinterface, Cinterface) -> ("Interface", "extend")
492+
| (_, Cinterface) -> ("Interface", "implement")
493+
| (Cinterface, Ctrait) -> ("Trait", "implement")
494+
| (_, Ctrait) -> ("Trait", "use")
495+
| (_, Cenum) -> ("Enum", "use")
496+
| (_, Cenum_class _) -> ("Enum Class", "extend"))
494497
in
495-
if hard_error then
496-
Typing_error_utils.add_typing_error
497-
~env
498-
Typing_error.(
499-
primary
500-
@@ Primary.Sealed_not_subtype
501-
{
502-
pos = parent_pos;
503-
child_pos;
504-
name = parent_name;
505-
child_name;
506-
child_kind = class_kind;
507-
})
508-
else
509-
Lint.sealed_not_subtype
510-
verb
511-
parent_pos
512-
parent_name
513-
child_name
514-
child_kind)
498+
Typing_warning_utils.add
499+
env
500+
( parent_pos,
501+
Typing_warning.Sealed_not_subtype,
502+
{
503+
Typing_warning.Sealed_not_subtype.verb;
504+
parent_name;
505+
child_name;
506+
child_kind;
507+
} ))
515508
(* unit below is fine because error cases are handled as Parsing[1002] *)
516509
| _ -> ()
517510
in
@@ -1644,12 +1637,11 @@ let check_override_keyword env c tc =
16441637
check_used_methods_with_override env c tc
16451638

16461639
(** If the class is sealed, check that the elements of the whitelist
1647-
are descendants of the class. Error or lint depending on option
1648-
enforce_sealed_subclasses. *)
1640+
are descendants of the class and emit a warning if not.
1641+
*)
16491642
let check_sealed env c =
1650-
let hard_error = TCO.enforce_sealed_subclasses (Env.get_tcopt env) in
16511643
let is_enum = is_enum_or_enum_class c.c_kind in
1652-
sealed_subtype c ~is_enum ~hard_error ~env
1644+
sealed_subtype c ~is_enum ~env
16531645

16541646
let check_class_require_non_strict_constraints env c tc =
16551647
let req_non_strict_constraints =

hphp/hack/src/typing/typing_error.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,13 +1189,6 @@ module Primary = struct
11891189
parent_kind: [ `intf | `trait | `class_ | `enum | `enum_class ];
11901190
verb: [ `extend | `implement | `use ];
11911191
}
1192-
| Sealed_not_subtype of {
1193-
pos: Pos.t;
1194-
name: string;
1195-
child_kind: Ast_defs.classish_kind;
1196-
child_pos: Pos_or_decl.t;
1197-
child_name: string;
1198-
}
11991192
| Trait_prop_const_class of {
12001193
pos: Pos.t;
12011194
name: string;

0 commit comments

Comments
 (0)