Skip to content

Commit

Permalink
Remove deprecated $call property syntax
Browse files Browse the repository at this point in the history
Summary:
This feature was deprecated in D8042447 (Flow v0.75.0), which seems like a more
than reasonable deprecation period. It should be easy to change any uses of this
to use callable property syntax or the [[call]] internal slot property syntax.

Removing this feature makes it possible to clean up a lot of crufty code with
weird corner cases.

Reviewed By: panagosg7

Differential Revision: D14648545

fbshipit-source-id: 48d6aefda5e0952ae6611e7e49f451eef61e89a5
  • Loading branch information
samwgoldman authored and facebook-github-bot committed Apr 22, 2019
1 parent 00b705b commit cbd6438
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 186 deletions.
1 change: 0 additions & 1 deletion src/common/lints/lintSettings.ml
Expand Up @@ -21,7 +21,6 @@ type 'a t = {
}

let default_lint_severities = [
Lints.DeprecatedCallSyntax, (Severity.Err, None);
Lints.DeprecatedUtility, (Severity.Err, None);
]

Expand Down
3 changes: 0 additions & 3 deletions src/common/lints/lints.ml
Expand Up @@ -28,7 +28,6 @@ type lint_kind =
| InexactSpread
| UnnecessaryOptionalChain
| UnnecessaryInvariant
| DeprecatedCallSyntax
| SignatureVerificationFailure

let string_of_sketchy_null_kind = function
Expand All @@ -54,7 +53,6 @@ let string_of_kind = function
| InexactSpread -> "inexact-spread"
| UnnecessaryOptionalChain -> "unnecessary-optional-chain"
| UnnecessaryInvariant -> "unnecessary-invariant"
| DeprecatedCallSyntax -> "deprecated-call-syntax"
| SignatureVerificationFailure -> "signature-verification-failure"

let kinds_of_string = function
Expand Down Expand Up @@ -83,7 +81,6 @@ let kinds_of_string = function
| "inexact-spread" -> Some [InexactSpread]
| "unnecessary-optional-chain" -> Some [UnnecessaryOptionalChain]
| "unnecessary-invariant" -> Some [UnnecessaryInvariant]
| "deprecated-call-syntax" -> Some [DeprecatedCallSyntax]
| "signature-verification-failure" -> Some [SignatureVerificationFailure]
| _ -> None

Expand Down
1 change: 0 additions & 1 deletion src/common/lints/lints.mli
Expand Up @@ -28,7 +28,6 @@ type lint_kind =
| InexactSpread
| UnnecessaryOptionalChain
| UnnecessaryInvariant
| DeprecatedCallSyntax
| SignatureVerificationFailure

val string_of_kind: lint_kind -> string
Expand Down
28 changes: 2 additions & 26 deletions src/typing/class_sig.ml
Expand Up @@ -37,7 +37,6 @@ type signature = {
getters: func_info SMap.t;
setters: func_info SMap.t;
calls: Type.t list;
call_deprecated: Type.t option;
}

type t = {
Expand Down Expand Up @@ -79,7 +78,6 @@ let empty id reason tparams tparams_map super =
getters = SMap.empty;
setters = SMap.empty;
calls = [];
call_deprecated = None;
} in
let constructor = [] in
let static =
Expand Down Expand Up @@ -183,19 +181,7 @@ let append_method ~static name loc fsig ?(set_asts=ignore) ?(set_type=ignore) x
}) x

let append_call ~static t = map_sig ~static (fun s ->
(* Note that $call properties always override the call property syntax.
As before, if both are present, the $call property is used and the call
property is ignored. *)
match s.call_deprecated with
| None -> { s with calls = t :: s.calls }
| Some _ -> s
)

let add_call_deprecated ~static t = map_sig ~static (fun s ->
(* Note that $call properties always override the call property syntax.
As before, if both are present, the $call property is used and the call
property is ignored. *)
{ s with call_deprecated = Some t; calls = [] }
{s with calls = t :: s.calls}
)

let add_getter ~static name loc fsig ?(set_asts=ignore) ?(set_type=ignore) x =
Expand Down Expand Up @@ -246,7 +232,6 @@ let subst_sig cx map s =
getters = SMap.map (subst_func_sig) s.getters;
setters = SMap.map (subst_func_sig) s.setters;
calls = Core_list.map ~f:(Flow.subst cx map) s.calls;
call_deprecated = Option.map ~f:(Flow.subst cx map) s.call_deprecated;
}

let subst_typeapp cx map (loc, c, targs) =
Expand Down Expand Up @@ -378,16 +363,7 @@ let elements cx ?constructor s =
(* Treat getters and setters as methods *)
let methods = SMap.union getters_and_setters methods in

(* Previously, call properties were stored in the props map under the key
$call. Unfortunately, this made it possible to specify call properties
using this syntax in interfaces, declared classes, and even normal classes.
Note that $call properties always override the call property syntax
As before, if both are present, the $call property is used and the call
property is ignored. *)
let call = match s.call_deprecated with
| Some t -> Some t
| None ->
let call =
match List.rev s.calls with
| [] -> None
| [t] -> Some t
Expand Down
2 changes: 0 additions & 2 deletions src/typing/class_sig.mli
Expand Up @@ -124,8 +124,6 @@ val append_method:

val append_call: static:bool -> Type.t -> t -> t

val add_call_deprecated: static:bool -> Type.t -> t -> t

(** Add getter to signature. *)
val add_getter:
static:bool ->
Expand Down
2 changes: 0 additions & 2 deletions src/typing/debug_js.ml
Expand Up @@ -2826,8 +2826,6 @@ let dump_error_message =
spf "EDeprecatedType (%s)" (string_of_aloc loc)
| EUnsafeGettersSetters loc ->
spf "EUnclearGettersSetters (%s)" (string_of_aloc loc)
| EDeprecatedCallSyntax loc ->
spf "EDeprecatedCallSyntax (%s)" (string_of_aloc loc)
| EUnusedSuppression loc ->
spf "EUnusedSuppression (%s)" (string_of_aloc loc)
| ELintSetting (loc, kind) ->
Expand Down
9 changes: 0 additions & 9 deletions src/typing/errors/error_message.ml
Expand Up @@ -177,7 +177,6 @@ and 'loc t' =
| EUnnecessaryOptionalChain of 'loc * 'loc virtual_reason
| EUnnecessaryInvariant of 'loc * 'loc virtual_reason
| EInexactSpread of 'loc virtual_reason * 'loc virtual_reason
| EDeprecatedCallSyntax of 'loc
| EUnexpectedTemporaryBaseType of 'loc
| EBigIntNotYetSupported of 'loc virtual_reason
(* These are unused when calculating locations so we can leave this as Aloc *)
Expand Down Expand Up @@ -480,7 +479,6 @@ let map_loc_of_error_message (f : 'a -> 'b) : 'a t' -> 'b t' =
| EUnnecessaryOptionalChain (loc, r) -> EUnnecessaryOptionalChain (f loc, map_reason r)
| EUnnecessaryInvariant (loc, r) -> EUnnecessaryInvariant (f loc, map_reason r)
| EInexactSpread (r1, r2) -> EInexactSpread (map_reason r1, map_reason r2)
| EDeprecatedCallSyntax loc -> EDeprecatedCallSyntax (f loc)
| EUnexpectedTemporaryBaseType loc -> EUnexpectedTemporaryBaseType (f loc)
| EBigIntNotYetSupported r -> EBigIntNotYetSupported (map_reason r)
| ESignatureVerification _ as e -> e
Expand Down Expand Up @@ -612,7 +610,6 @@ let util_use_op_of_msg nope util = function
| EUnnecessaryOptionalChain _
| EUnnecessaryInvariant _
| EInexactSpread _
| EDeprecatedCallSyntax _
| EUnexpectedTemporaryBaseType _
| EBigIntNotYetSupported _
| ESignatureVerification _
Expand Down Expand Up @@ -666,7 +663,6 @@ let aloc_of_msg : t -> ALoc.t option = function
| EDeprecatedType loc
| EDeprecatedUtility (loc, _)
| EUnsafeGettersSetters loc
| EDeprecatedCallSyntax loc
| EUnnecessaryOptionalChain (loc, _)
| EUnnecessaryInvariant (loc, _)
| EOptionalChainingMethods loc
Expand Down Expand Up @@ -771,7 +767,6 @@ let kind_of_msg = Errors.(function
| EDeprecatedUtility _ -> LintError Lints.DeprecatedUtility
| EDynamicExport _ -> LintError Lints.DynamicExport
| EUnsafeGettersSetters _ -> LintError Lints.UnsafeGettersSetters
| EDeprecatedCallSyntax _ -> LintError Lints.DeprecatedCallSyntax
| ESketchyNullLint { kind; _ } -> LintError (Lints.SketchyNull kind)
| ESketchyNumberLint (kind, _) -> LintError (Lints.SketchyNumber kind)
| EUnnecessaryOptionalChain _ -> LintError Lints.UnnecessaryOptionalChain
Expand Down Expand Up @@ -1746,10 +1741,6 @@ let friendly_message_of_msg : Loc.t t' -> Loc.t friendly_message_recipe =
Normal
[text "Getters and setters can have side effects and are unsafe."]

| EDeprecatedCallSyntax _ ->
Normal
[text "Deprecated $call syntax. Use callable property syntax instead."]

| EUnusedSuppression _ ->
Normal
[text "Unused suppression comment."]
Expand Down
18 changes: 2 additions & 16 deletions src/typing/ty_normalizer.ml
Expand Up @@ -861,11 +861,6 @@ end = struct
mapM (method_ty ~env) ts >>| fun ts ->
Core_list.map ~f:(fun t -> Ty.CallProp t) ts

and call_prop ~env = function
| _, T.Method (_, t)
| _, T.Field (_, t, _) -> call_prop_from_t ~env t
| _ -> terr ~kind:BadCallProp None

and obj_props =
(* call property *)
let do_calls ~env = function
Expand All @@ -876,10 +871,6 @@ end = struct
| None ->
return []
in
(* `$call` property *)
let do_calls_legacy ~env call_props =
concat_fold_m (call_prop ~env) call_props
in
let do_props ~env props =
concat_fold_m (obj_prop ~env) props
in
Expand All @@ -894,16 +885,11 @@ end = struct
in
fun ~env props_id call_id_opt dict ->
let cx = Env.get_cx env in
let call_props, props =
Context.find_props cx props_id
|> SMap.bindings
|> Core_list.partition_tf ~f:(fun (x, _) -> x = "$call")
in
do_calls_legacy ~env call_props >>= fun call_props_legacy ->
let props = SMap.bindings (Context.find_props cx props_id) in
do_calls ~env call_id_opt >>= fun call_props ->
do_props ~env props >>= fun props ->
do_dict ~env dict >>| fun dict ->
call_props_legacy @ call_props @ props @ dict
call_props @ props @ dict

and arr_ty ~env reason elt_t =
let arr_literal = match Reason.desc_of_reason reason with
Expand Down

0 comments on commit cbd6438

Please sign in to comment.