Skip to content

Commit 1c50add

Browse files
cknittclaude
andauthored
Fix issues from differential semantic drift analysis (#8768) (#8770)
* Complete values of modules included with await Fixes #8758. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Remove helpers left unused by the deriving removals Fixes #8760. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Print bigint constants in the outcome printer with Bigint_utils Fixes #8763. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Replace Clflags.error_size with a constant No option sets it, so the limit <= 0 branch was unreachable. Fixes #8764. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Update comments after the dict and JSX representation changes rewatch rebuilds when bsc changes, so .cmj files are never read by another compiler. Fixes #8767. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Check for the supported Node.js version 22 in rescript/cli/bins Fixes #8761. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Type-check cli/common with npm run typecheck Fixes #8766. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Document why platform packages still export their binary paths rescript-vscode imports bin.js directly and reads binPaths. Closes #8762. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Share the watcher's exit after the lock file is removed Fixes #8765. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Recover from missing values in dict patterns like in record patterns dict{"a": } => ... skipped past => instead of producing a pattern hole. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Complete typed values inside dict literals and dict patterns dict is abstract since #8752, so entries followed a record-field path that found no type. Fixes #8759. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Add CHANGELOG entries for #8770 Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b497cb6 commit 1c50add

46 files changed

Lines changed: 1740 additions & 763 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
#### :bug: Bug fix
2626

27+
- Fix editor completion of values from modules included with `include await M`. https://github.com/rescript-lang/rescript/pull/8770
28+
- Fix editor completion inside dict literals and dict patterns, which suggested untyped values. https://github.com/rescript-lang/rescript/pull/8770
29+
- Report the required Node.js version 22 when the platform package can't be found. https://github.com/rescript-lang/rescript/pull/8770
2730
- Fix JSX preserve mode emitting JSX that means something other than the compiled call, and keep more elements as JSX. https://github.com/rescript-lang/rescript/pull/8754
2831
- Fix exhaustiveness and unused-case checks for dict patterns that match the same key in several cases, print their counter-examples as dict patterns, and reject a key matched twice in one pattern. https://github.com/rescript-lang/rescript/pull/8751
2932
- Emit `"__proto__"` keys in object literals as computed keys, so they create a property instead of setting the prototype. https://github.com/rescript-lang/rescript/pull/8747

‎analysis/reanalyze/src/side_effects.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let rec expr_no_side_effects (expr : Typedtree.expression) =
6060
entries
6161
|> List.for_all (function
6262
| Typedtree.Tdict_entry (_, e) -> e |> expr_no_side_effects
63-
(* Object.assign reads the spread dicts *)
63+
(* Spreading a dict reads its properties *)
6464
| Tdict_spread _ -> false)
6565
| Texp_ifthenelse (e1, e2, eo) ->
6666
e1 |> expr_no_side_effects && e2 |> expr_no_side_effects

‎analysis/src/completion_back_end.ml‎

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,12 +983,36 @@ and get_completions_for_context_path ~state ~debug ~full ~opens ~raw_opens ~pos
983983
Completion.create "array" ~env
984984
~kind:(Completion.Value (Ctype.newconstr Predef.path_array []));
985985
]
986-
| CPDict ->
987-
if Debug.verbose () then print_endline "[ctx_path]--> CPDict";
986+
| CPDict None ->
987+
if Debug.verbose () then print_endline "[ctx_path]--> CPDict (no payload)";
988988
[
989989
Completion.create "dict" ~env
990990
~kind:(Completion.Value (Ctype.newconstr Predef.path_dict []));
991991
]
992+
| CPDict (Some cp) -> (
993+
if Debug.verbose () then print_endline "[ctx_path]--> CPDict (with payload)";
994+
match mode with
995+
| Regular -> (
996+
match
997+
cp
998+
|> get_completions_for_context_path ~state ~debug ~full ~opens
999+
~raw_opens ~pos ~env ~exact:true ~scope
1000+
|> completions_get_completion_type ~full ~state
1001+
with
1002+
| None -> []
1003+
| Some (typ, env) ->
1004+
[
1005+
Completion.create "dummy" ~env
1006+
~kind:
1007+
(Completion.ExtractedType (Tdict (env, ExtractedType typ), `Type));
1008+
])
1009+
| Pipe ->
1010+
(* Pipe completion with dict just needs to know that it's a dict, not
1011+
what inner type it has. *)
1012+
[
1013+
Completion.create "dummy" ~env
1014+
~kind:(Completion.Value (Ctype.newconstr Predef.path_dict []));
1015+
])
9921016
| CPArray (Some cp) -> (
9931017
if Debug.verbose () then
9941018
print_endline "[ctx_path]--> CPArray (with payload)";
@@ -1937,6 +1961,24 @@ let rec complete_typed_value ?(type_arg_context : type_arg_context option)
19371961
~env;
19381962
]
19391963
else []
1964+
| Tdict (env, typ) as extracted_type ->
1965+
if Debug.verbose () then print_endline "[complete_typed_value]--> Tdict";
1966+
if prefix = "" then
1967+
[
1968+
create "dict{}" ~includes_snippets:true ~insert_text:"dict{$0}"
1969+
~sort_text:"A"
1970+
~kind:
1971+
(match typ with
1972+
| ExtractedType _ ->
1973+
ExtractedType
1974+
( extracted_type,
1975+
match mode with
1976+
| Pattern _ -> `Type
1977+
| Expression -> `Value )
1978+
| TypeExpr typ -> Value (Ctype.newconstr Predef.path_dict [typ]))
1979+
~env;
1980+
]
1981+
else []
19401982
| Tstring env ->
19411983
if Debug.verbose () then print_endline "[complete_typed_value]--> Tstring";
19421984
if prefix = "" then

‎analysis/src/completion_expressions.ml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@ let rec traverse_expr (exp : Parsetree.expression) ~expr_path ~pos
4747
`[None, <com>, None]`) *)
4848
Some ("", next_expr_path)
4949
| _ -> None)
50+
| Pexp_dict entries -> (
51+
(* Complete inside the value of the entry with the cursor, or for the type
52+
of the values at an expression hole, e.g. `dict{"a": <com>}` *)
53+
let next_expr_path =
54+
[Completable.NDictValue {optional = false}] @ expr_path
55+
in
56+
let values =
57+
entries
58+
|> List.filter_map (function
59+
| Parsetree.Pdict_entry (_, value) -> Some value
60+
| Pdict_spread _ -> None)
61+
in
62+
match
63+
values
64+
|> List.find_opt (fun value ->
65+
value.Parsetree.pexp_loc
66+
|> Cursor_position.classify_loc ~pos
67+
= HasCursor)
68+
with
69+
| Some value ->
70+
value
71+
|> traverse_expr ~expr_path:next_expr_path
72+
~first_char_before_cursor_no_white ~pos
73+
| None when List.exists is_expr_hole values ->
74+
some_if_has_cursor ("", next_expr_path)
75+
| None -> None)
5076
| Pexp_tuple tuple_items when loc_has_cursor exp.pexp_loc ->
5177
tuple_items
5278
|> traverse_expr_tuple_items ~first_char_before_cursor_no_white ~pos

‎analysis/src/completion_front_end.ml‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ let rec expr_to_context_path_inner ~(in_jsx_context : bool)
231231
(match exprs with
232232
| [] -> None
233233
| exp :: _ -> expr_to_context_path ~in_jsx_context exp))
234-
| Pexp_dict _ -> Some CPDict
234+
| Pexp_dict _ -> Some (CPDict None)
235235
| Pexp_ident {txt = Lident "->"} -> None
236236
| Pexp_ident {txt; loc} ->
237237
Some
@@ -511,11 +511,10 @@ let completion_with_parser1 ~debug ~offset ~pos_cursor ~kind_file
511511
:: pattern_path)
512512
?context_path)
513513
| Ppat_dict entries ->
514-
Ext_list.iter entries (fun {pdp_key; pdp_pattern} ->
514+
Ext_list.iter entries (fun {pdp_pattern; pdp_optional} ->
515515
scope_pattern
516516
~pattern_path:
517-
(Completable.NFollowRecordField {field_name = pdp_key.txt}
518-
:: pattern_path)
517+
(Completable.NDictValue {optional = pdp_optional} :: pattern_path)
519518
?context_path pdp_pattern)
520519
| Ppat_record (fields, _, rest) -> (
521520
Ext_list.iter fields (fun {lid = fname; x = p} ->
@@ -752,13 +751,23 @@ let completion_with_parser1 ~debug ~offset ~pos_cursor ~kind_file
752751
mbs |> List.iter scope_module_binding;
753752
mbs |> List.iter (fun b -> iterator.module_binding iterator b);
754753
processed := true
755-
| Pstr_include {pincl_mod = {pmod_desc = med}} -> (
756-
match med with
757-
| Pmod_ident {txt = lid; loc}
758-
| Pmod_apply ({pmod_desc = Pmod_ident {txt = lid; loc}}, _) ->
754+
| Pstr_include {pincl_mod} -> (
755+
(* [include await M] and [include (await F)(X)] include [M] and [F] *)
756+
let without_awaits m = snd (Ast_await.remove_awaits false m) in
757+
let included_path =
758+
match (without_awaits pincl_mod).pmod_desc with
759+
| Pmod_ident lid -> Some lid
760+
| Pmod_apply (functor_, _) -> (
761+
match (without_awaits functor_).pmod_desc with
762+
| Pmod_ident lid -> Some lid
763+
| _ -> None)
764+
| _ -> None
765+
in
766+
match included_path with
767+
| Some {txt = lid; loc} ->
759768
let module_name = Longident.flatten lid |> String.concat "." in
760769
scope := !scope |> Scope.add_include ~name:module_name ~loc
761-
| _ -> ())
770+
| None -> ())
762771
| _ -> ());
763772
if not !processed then
764773
Ast_iterator.default_iterator.structure_item iterator item

‎analysis/src/completion_patterns.ml‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,26 @@ and traverse_pattern (pat : Parsetree.pattern) ~pattern_path ~loc_has_cursor
115115
("", [Completable.NRecordBody {seen_fields = []}] @ pattern_path)
116116
"Ppat_record(empty)")
117117
| Ppat_dict entries -> (
118-
(* Complete inside the pattern of the entry with the cursor, as for a
119-
record field *)
118+
(* Complete inside the pattern of the entry with the cursor *)
120119
let entry_with_cursor =
121-
entries
122-
|> List.find_opt (fun {Parsetree.pdp_pattern} ->
123-
pdp_pattern.ppat_loc
124-
|> Cursor_position.classify_loc ~pos:pos_before_cursor
125-
= HasCursor
126-
|| is_pattern_hole pdp_pattern)
120+
match
121+
entries
122+
|> List.find_opt (fun {Parsetree.pdp_pattern} ->
123+
pdp_pattern.ppat_loc
124+
|> Cursor_position.classify_loc ~pos:pos_before_cursor
125+
= HasCursor)
126+
with
127+
| Some entry -> Some entry
128+
| None ->
129+
entries
130+
|> List.find_opt (fun {Parsetree.pdp_pattern} ->
131+
is_pattern_hole pdp_pattern)
127132
in
128133
match entry_with_cursor with
129134
| None -> None
130-
| Some {pdp_key; pdp_pattern} -> (
135+
| Some {pdp_pattern; pdp_optional} -> (
131136
let pattern_path =
132-
[Completable.NFollowRecordField {field_name = pdp_key.txt}]
133-
@ pattern_path
137+
[Completable.NDictValue {optional = pdp_optional}] @ pattern_path
134138
in
135139
match pdp_pattern.ppat_desc with
136140
| Ppat_extension ({txt = "rescript.patternhole"}, _) ->

‎analysis/src/shared_types.ml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ and completion_type =
374374
}
375375
| Tbool of Query_env.t
376376
| Tarray of Query_env.t * inner_type
377+
| Tdict of Query_env.t * inner_type
377378
| Tstring of Query_env.t
378379
| TtypeT of {env: Query_env.t; path: Path.t}
379380
| Tvariant of {
@@ -616,6 +617,8 @@ module Completable = struct
616617
source_arity: int;
617618
}
618619
| NArray
620+
| NDictValue of {optional: bool}
621+
(** The pattern or expression of a dict entry, [?P] if [optional] *)
619622

620623
let nested_path_to_string p =
621624
match p with
@@ -629,11 +632,12 @@ module Completable = struct
629632
"polyvariantPayload::" ^ constructor_name ^ "($" ^ string_of_int item_num
630633
^ ")"
631634
| NArray -> "array"
635+
| NDictValue {optional} -> if optional then "dictValue(?)" else "dictValue"
632636

633637
type context_path =
634638
| CPString
635639
| CPArray of context_path option
636-
| CPDict
640+
| CPDict of context_path option
637641
| CPInt
638642
| CPFloat
639643
| CPBool
@@ -735,7 +739,8 @@ module Completable = struct
735739
| CPArray (Some ctx_path) ->
736740
"array<" ^ context_path_to_string ctx_path ^ ">"
737741
| CPArray None -> "array"
738-
| CPDict -> "dict"
742+
| CPDict (Some ctx_path) -> "dict<" ^ context_path_to_string ctx_path ^ ">"
743+
| CPDict None -> "dict"
739744
| CPId {path; completion_context} ->
740745
completion_context_to_string completion_context ^ list path
741746
| CPField {context_path = cp; field_name = s} ->

‎analysis/src/type_utils.ml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ let rec extracted_type_to_string ?(name_only = false) ?(inner = false) =
103103
"array<" ^ Shared.type_to_string inner_typ ^ ">"
104104
| Tarray (_, ExtractedType inner_typ) ->
105105
"array<" ^ extracted_type_to_string ~inner:true inner_typ ^ ">"
106+
| Tdict (_, TypeExpr inner_typ) ->
107+
"dict<" ^ Shared.type_to_string inner_typ ^ ">"
108+
| Tdict (_, ExtractedType inner_typ) ->
109+
"dict<" ^ extracted_type_to_string ~inner:true inner_typ ^ ">"
106110
| Toption (_, TypeExpr inner_typ) ->
107111
"option<" ^ Shared.type_to_string inner_typ ^ ">"
108112
| Tresult {ok_type; error_type} ->
@@ -388,6 +392,8 @@ let rec extract_type ?(print_opening_debug = true)
388392
Some (Tpromise (env, payload_type_expr), type_arg_context)
389393
| Tconstr (Path.Pident {name = "array"}, [payload_type_expr], _) ->
390394
Some (Tarray (env, TypeExpr payload_type_expr), type_arg_context)
395+
| Tconstr (Path.Pident {name = "dict"}, [payload_type_expr], _) ->
396+
Some (Tdict (env, TypeExpr payload_type_expr), type_arg_context)
391397
| Tconstr (Path.Pident {name = "result"}, [ok_type; error_type], _) ->
392398
Some (Tresult {env; ok_type; error_type}, type_arg_context)
393399
| Tconstr (Path.Pident {name = "bool"}, [], _) ->
@@ -827,6 +833,17 @@ let rec resolve_nested ?type_arg_context ~env ~full ~state ~nested ?ctx
827833
|> extract_type ~env ~state ~package:full.package
828834
|> Utils.Option.flat_map (fun (typ, type_arg_context) ->
829835
typ |> resolve_nested ?type_arg_context ~env ~state ~full ~nested)
836+
| NDictValue {optional = true}, Tdict (env, typ) ->
837+
(* [?P] matches the value as an option *)
838+
Toption (env, typ)
839+
|> resolve_nested ?type_arg_context ~env ~state ~full ~nested
840+
| NDictValue {optional = false}, Tdict (env, ExtractedType typ) ->
841+
typ |> resolve_nested ?type_arg_context ~env ~state ~full ~nested
842+
| NDictValue {optional = false}, Tdict (env, TypeExpr typ) ->
843+
typ
844+
|> extract_type ~env ~state ~package:full.package
845+
|> Utils.Option.flat_map (fun (typ, type_arg_context) ->
846+
typ |> resolve_nested ?type_arg_context ~env ~state ~full ~nested)
830847
| _ -> None)
831848

832849
let find_type_of_record_field fields ~field_name =
@@ -942,6 +959,15 @@ let rec resolve_nested_pattern_path (typ : inner_type) ~env ~full ~state ~nested
942959
|> resolve_nested_pattern_path ~env ~state ~full ~nested
943960
| NArray, Tarray (env, typ) ->
944961
typ |> resolve_nested_pattern_path ~env ~state ~full ~nested
962+
| NDictValue {optional = true}, Tdict (env, TypeExpr typ) ->
963+
(* [?P] matches the value as an option *)
964+
TypeExpr (Ctype.newconstr Predef.path_option [typ])
965+
|> resolve_nested_pattern_path ~env ~state ~full ~nested
966+
| NDictValue {optional = true}, Tdict (env, (ExtractedType _ as typ)) ->
967+
ExtractedType (Toption (env, typ))
968+
|> resolve_nested_pattern_path ~env ~state ~full ~nested
969+
| NDictValue {optional = false}, Tdict (env, typ) ->
970+
typ |> resolve_nested_pattern_path ~env ~state ~full ~nested
945971
| _ -> None))
946972

947973
let get_args ~env (t : Types.type_expr) ~full ~state =
@@ -995,6 +1021,8 @@ let rec context_path_from_core_type (core_type : Parsetree.core_type) =
9951021
|> Option.map (fun inner_typ -> Completable.CPOption inner_typ)
9961022
| Ptyp_constr ({txt = Lident "array"}, [inner_typ]) ->
9971023
Some (Completable.CPArray (inner_typ |> context_path_from_core_type))
1024+
| Ptyp_constr ({txt = Lident "dict"}, [inner_typ]) ->
1025+
Some (Completable.CPDict (inner_typ |> context_path_from_core_type))
9981026
| Ptyp_constr (lid, _) ->
9991027
Some
10001028
(CPId

‎cli/common/bins.cjs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
const path = require("node:path");
88

9-
const minimumNodeVersion = "20.11.0";
9+
const minimumNodeVersion = "22.0.0";
1010

1111
const target = `${process.platform}-${process.arch}`;
1212

@@ -37,7 +37,9 @@ try {
3737
);
3838
}
3939

40-
// The platform package's entry (bin.js) sits next to its bin directory.
40+
// The platform package's entry (bin.js) sits next to its bin directory. It
41+
// exports the same paths for tools that import it directly, such as
42+
// rescript-vscode, so keep the two lists in sync.
4143
const binDir = path.join(path.dirname(binPackageEntry), "bin");
4244

4345
exports.binDir = binDir;

‎compiler/frontend/ast_core_type.ml‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424

2525
type t = Parsetree.core_type
2626

27-
let lift_option_type ({ptyp_loc} as ty : t) : t =
28-
{
29-
ptyp_desc =
30-
Ptyp_constr ({txt = Ast_literal.predef_option; loc = ptyp_loc}, [ty]);
31-
ptyp_loc;
32-
ptyp_attributes = [];
33-
}
34-
3527
open Ast_helper
3628

3729
(* let replace_result (ty : t) (result : t) : t =

0 commit comments

Comments
 (0)