Skip to content

Commit

Permalink
[flow][tuples] Add option for gating inexact tuple types syntax
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal]

The boilerplate of adding an option to gate the future implementation of inexact tuple types.

Reviewed By: SamChou19815

Differential Revision: D56713880

fbshipit-source-id: d73f3eb47751e55bdabaeeee32574cf3e899592e
  • Loading branch information
gkz authored and facebook-github-bot committed May 2, 2024
1 parent c2f5ca9 commit 7df19bf
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/commands/commandUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,7 @@ let make_options
options_flags.include_warnings
|| options_flags.max_warnings <> None
|| FlowConfig.include_warnings flowconfig;
opt_inexact_tuple_types_syntax = FlowConfig.inexact_tuple_types_syntax flowconfig;
opt_max_header_tokens = FlowConfig.max_header_tokens flowconfig;
opt_haste_module_ref_prefix = FlowConfig.haste_module_ref_prefix flowconfig;
opt_haste_module_ref_prefix_LEGACY_INTEROP =
Expand Down
7 changes: 7 additions & 0 deletions src/commands/config/flowConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ module Opts = struct
haste_paths_includes: string list;
ignore_non_literal_requires: bool;
include_warnings: bool;
inexact_tuple_types_syntax: bool;
lazy_mode: lazy_mode option;
log_saving: Options.log_saving SMap.t;
long_lived_workers: bool;
Expand Down Expand Up @@ -221,6 +222,7 @@ module Opts = struct
haste_paths_includes = ["<PROJECT_ROOT>/.*"];
ignore_non_literal_requires = false;
include_warnings = false;
inexact_tuple_types_syntax = false;
lazy_mode = None;
log_saving = SMap.empty;
long_lived_workers = false;
Expand Down Expand Up @@ -957,6 +959,9 @@ module Opts = struct
("gc.worker.space_overhead", gc_worker_space_overhead_parser);
("gc.worker.window_size", gc_worker_window_size_parser);
("include_warnings", boolean (fun opts v -> Ok { opts with include_warnings = v }));
( "inexact_tuple_types_syntax",
boolean (fun opts v -> Ok { opts with inexact_tuple_types_syntax = v })
);
("lazy_mode", lazy_mode_parser);
("log_saving", log_saving_parser);
("max_header_tokens", uint (fun opts v -> Ok { opts with max_header_tokens = v }));
Expand Down Expand Up @@ -1636,6 +1641,8 @@ let ignore_non_literal_requires c = c.options.Opts.ignore_non_literal_requires

let include_warnings c = c.options.Opts.include_warnings

let inexact_tuple_types_syntax c = c.options.Opts.inexact_tuple_types_syntax

let lazy_mode c = c.options.Opts.lazy_mode

(* global defaults for lint severities and strict mode *)
Expand Down
2 changes: 2 additions & 0 deletions src/commands/config/flowConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ val ignore_non_literal_requires : config -> bool

val include_warnings : config -> bool

val inexact_tuple_types_syntax : config -> bool

val lazy_mode : config -> lazy_mode option

(* global defaults for lint suppressions and strict mode *)
Expand Down
3 changes: 3 additions & 0 deletions src/common/options.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ type t = {
opt_ignore_non_literal_requires: bool;
opt_include_suppressions: bool;
opt_include_warnings: bool;
opt_inexact_tuple_types_syntax: bool;
opt_lazy_mode: bool;
opt_lint_severities: Severity.severity LintSettings.t;
opt_log_file: File_path.t;
Expand Down Expand Up @@ -265,6 +266,8 @@ let haste_paths_includes opts = opts.opt_haste_paths_includes

let include_suppressions opts = opts.opt_include_suppressions

let inexact_tuple_types_syntax opts = opts.opt_inexact_tuple_types_syntax

let is_debug_mode opts = opts.opt_debug

let is_quiet opts = opts.opt_quiet
Expand Down
1 change: 1 addition & 0 deletions src/flow_dot_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ let stub_metadata ~root ~checked =
enable_as_const = false;
enable_const_params = false;
enable_enums = true;
enable_inexact_tuple_types_syntax = true;
enable_relay_integration = false;
exact_by_default = true;
facebook_fbs = None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ let stub_metadata ~root ~checked =
enable_as_const = false;
enable_const_params = false;
enable_enums = true;
enable_inexact_tuple_types_syntax = false;
enable_relay_integration = false;
exact_by_default = false;
facebook_fbs = None;
Expand Down
1 change: 1 addition & 0 deletions src/typing/__tests__/type_hint_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ let metadata =
enable_as_const = false;
enable_const_params = false;
enable_enums = true;
enable_inexact_tuple_types_syntax = false;
enable_relay_integration = false;
exact_by_default = true;
facebook_fbs = None;
Expand Down
1 change: 1 addition & 0 deletions src/typing/__tests__/typed_ast_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let metadata =
enable_as_const = false;
enable_const_params = false;
enable_enums = true;
enable_inexact_tuple_types_syntax = false;
enable_relay_integration = false;
exact_by_default = false;
facebook_fbs = None;
Expand Down
4 changes: 4 additions & 0 deletions src/typing/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type metadata = {
enable_as_const: bool;
enable_const_params: bool;
enable_enums: bool;
enable_inexact_tuple_types_syntax: bool;
enable_relay_integration: bool;
exact_by_default: bool;
facebook_fbs: string option;
Expand Down Expand Up @@ -264,6 +265,7 @@ let metadata_of_options options =
enable_as_const = Options.as_const options;
enable_const_params = Options.enable_const_params options;
enable_enums = Options.enums options;
enable_inexact_tuple_types_syntax = Options.inexact_tuple_types_syntax options;
enable_relay_integration = Options.enable_relay_integration options;
exact_by_default = Options.exact_by_default options;
facebook_fbs = Options.facebook_fbs options;
Expand Down Expand Up @@ -474,6 +476,8 @@ let enable_const_params cx =

let enable_enums cx = cx.metadata.enable_enums

let enable_inexact_tuple_types_syntax cx = cx.metadata.enable_inexact_tuple_types_syntax

let enable_relay_integration cx =
cx.metadata.enable_relay_integration
&& Relay_options.enabled_for_file cx.metadata.relay_integration_excludes (file cx)
Expand Down
3 changes: 3 additions & 0 deletions src/typing/context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type metadata = {
enable_as_const: bool;
enable_const_params: bool;
enable_enums: bool;
enable_inexact_tuple_types_syntax: bool;
enable_relay_integration: bool;
exact_by_default: bool;
facebook_fbs: string option;
Expand Down Expand Up @@ -173,6 +174,8 @@ val enable_const_params : t -> bool

val enable_enums : t -> bool

val enable_inexact_tuple_types_syntax : t -> bool

val enable_relay_integration : t -> bool

val relay_integration_esmodules : t -> bool
Expand Down
2 changes: 1 addition & 1 deletion src/typing/type_annotation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ module Make (ConsGen : Type_annotation_sig.ConsGen) (Statement : Statement_sig.S
in
let (unresolved, els_asts) = (List.rev unresolved_rev, List.rev els_asts_rev) in
let t =
if inexact then (
if inexact && not (Context.enable_inexact_tuple_types_syntax env.cx) then (
Flow_js_utils.add_output
env.cx
(Error_message.EUnsupportedSyntax (loc, Flow_intermediate_error_types.InexactTupleType));
Expand Down
2 changes: 1 addition & 1 deletion src/typing/type_sig_merge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ and merge_annot env file = function
let ts = Base.List.map ~f:(merge env file) ts in
Type.(IntersectionT (reason, InterRep.make t0 t1 ts))
| Tuple { loc; elems_rev; inexact } ->
if inexact then
if inexact && not (Context.enable_inexact_tuple_types_syntax file.cx) then
Type.AnyT.at Type.AnnotatedAny loc
else
let reason = Reason.(mk_annot_reason RTupleType loc) in
Expand Down
1 change: 1 addition & 0 deletions tests/inexact_tuples_unsupported/.flowconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[options]
all=true
casting_syntax=as
inexact_tuple_types_syntax=false
1 change: 1 addition & 0 deletions tests/tuples/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
no_flowlib=false
lazy_mode=fs
all=true
inexact_tuple_types_syntax=true
1 change: 1 addition & 0 deletions tests/tuples/inexact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type EmptyInexact = [...]; // OK

0 comments on commit 7df19bf

Please sign in to comment.