Skip to content

Commit 16fd1b7

Browse files
authored
Merge 11.0.1 changes into master (#6579)
1 parent 3bb11b4 commit 16fd1b7

28 files changed

+537
-166
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
1313
# 12.0.0-alpha.1 (Unreleased)
1414

15+
# 11.0.1
16+
17+
#### :bug: Bug Fix
18+
19+
- Renamed inline record fields: fix renamed field access in inline records. https://github.com/rescript-lang/rescript-compiler/pull/6551
20+
- Fixed issue with coercions sometimes raising a `Not_found` instead of giving a proper error message. https://github.com/rescript-lang/rescript-compiler/pull/6574
21+
- Fix issue with recursive modules and uncurried. https://github.com/rescript-lang/rescript-compiler/pull/6575
22+
23+
#### :nail_care: Polish
24+
25+
- Improve error message for missing label(s) in function application. https://github.com/rescript-lang/rescript-compiler/pull/6576
26+
1527
# 11.0.0
1628

1729
No changes compared to rc.9.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/missing_label.res:3:9
4+
5+
1 │ let f = (~a) => a ++ ""
6+
2 │
7+
3 │ let _ = f("")
8+
4 │
9+
10+
Label ~a was omitted in the application of this labeled function.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/missing_labels.res:3:9
4+
5+
1 │ let f = (~a, ~b) => a ++ b
6+
2 │
7+
3 │ let _ = f("", "")
8+
4 │
9+
10+
Labels ~a, ~b were omitted in the application of this labeled function.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let f = (~a) => a ++ ""
2+
3+
let _ = f("")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let f = (~a, ~b) => a ++ b
2+
3+
let _ = f("", "")

jscomp/core/bs_conditional_initial.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ let setup_env () =
4444
Builtin_attributes.check_bs_attributes_inclusion := Record_attributes_check.check_bs_attributes_inclusion;
4545
Builtin_attributes.check_duplicated_labels :=
4646
Record_attributes_check.check_duplicated_labels;
47-
Lambda.fld_record := Record_attributes_check.fld_record;
48-
Lambda.fld_record_set := Record_attributes_check.fld_record_set;
49-
Lambda.blk_record := Record_attributes_check.blk_record;
50-
Lambda.blk_record_inlined := Record_attributes_check.blk_record_inlined;
5147
Matching.names_from_construct_pattern :=
5248
Matching_polyfill.names_from_construct_pattern;
5349

jscomp/core/record_attributes_check.ml

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
type label = Types.label_description
2626

27-
let find_name = Matching.find_name
27+
let find_name = Lambda.find_name
2828

2929
let find_name_with_loc (attr : Parsetree.attribute) : string Asttypes.loc option
3030
=
@@ -40,34 +40,6 @@ let find_name_with_loc (attr : Parsetree.attribute) : string Asttypes.loc option
4040
Some { txt = s; loc }
4141
| _ -> None
4242

43-
let fld_record (lbl : label) =
44-
Lambda.Fld_record
45-
{
46-
name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name;
47-
mutable_flag = lbl.lbl_mut;
48-
}
49-
50-
let fld_record_set (lbl : label) =
51-
Lambda.Fld_record_set
52-
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
53-
54-
let blk_record (fields : (label * _) array) mut record_repr =
55-
let all_labels_info =
56-
Ext_array.map fields (fun (lbl, _) ->
57-
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
58-
in
59-
Lambda.Blk_record
60-
{ fields = all_labels_info; mutable_flag = mut; record_repr }
61-
62-
let blk_record_inlined fields name num_nonconst optional_labels ~tag ~attrs mutable_flag =
63-
let fields =
64-
Array.map
65-
(fun ((lbl : label), _) ->
66-
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
67-
fields
68-
in
69-
Lambda.Blk_record_inlined {fields; name; num_nonconst; tag; mutable_flag; optional_labels; attrs }
70-
7143
let check_bs_attributes_inclusion (attrs1 : Parsetree.attributes)
7244
(attrs2 : Parsetree.attributes) lbl_name =
7345
let a = Ext_list.find_def attrs1 find_name lbl_name in

jscomp/gentype_tests/typescript-react-example/package-lock.json

Lines changed: 26 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/gentype_tests/typescript-react-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "eslint src"
1111
},
1212
"dependencies": {
13-
"@rescript/react": "^0.11.0",
13+
"@rescript/react": "^0.12.0",
1414
"react": "^18.2.0",
1515
"react-dom": "^18.2.0"
1616
},

jscomp/gentype_tests/typescript-react-example/src/Hooks.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module ForwardRef = {
9999
)
100100
}
101101

102-
@genType type callback<'input, 'output> = React.callback<'input, 'output>
102+
@genType type callback<'input, 'output> = 'input => 'output
103103

104104
@genType type testReactContext = React.Context.t<int>
105105

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
open ReactV3
22

33
@genType
4-
type cb = React.callback<int, string>
4+
type cb = int => string

jscomp/ml/ctype.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3904,6 +3904,11 @@ let subtypes = TypePairs.create 17
39043904
let subtype_error env trace =
39053905
raise (Subtype (expand_trace env (List.rev trace), []))
39063906

3907+
let extract_concrete_typedecl_opt env t =
3908+
match extract_concrete_typedecl env t with
3909+
| v -> Some v
3910+
| exception Not_found -> None
3911+
39073912
let rec subtype_rec env trace t1 t2 cstrs =
39083913
let t1 = repr t1 in
39093914
let t2 = repr t2 in
@@ -3960,23 +3965,23 @@ let rec subtype_rec env trace t1 t2 cstrs =
39603965
| (Tconstr(p1, [], _), Tconstr(p2, [], _)) when Path.same p1 Predef.path_int && Path.same p2 Predef.path_float ->
39613966
cstrs
39623967
| (Tconstr(path, [], _), Tconstr(_, [], _)) when Variant_coercion.can_coerce_primitive path &&
3963-
extract_concrete_typedecl env t2 |> Variant_coercion.can_try_coerce_variant_to_primitive |> Option.is_some
3968+
extract_concrete_typedecl_opt env t2 |> Variant_coercion.can_try_coerce_variant_to_primitive_opt |> Option.is_some
39643969
->
39653970
(* type coercion for primitives (int/float/string) to elgible unboxed variants:
39663971
- must be unboxed
39673972
- must have a constructor case with a supported and matching primitive payload *)
3968-
(match Variant_coercion.can_try_coerce_variant_to_primitive (extract_concrete_typedecl env t2) with
3973+
(match Variant_coercion.can_try_coerce_variant_to_primitive_opt (extract_concrete_typedecl_opt env t2) with
39693974
| Some (constructors, true) ->
39703975
if Variant_coercion.variant_has_catch_all_case constructors (fun p -> Path.same p path) then
39713976
cstrs
39723977
else
39733978
(trace, t1, t2, !univar_pairs)::cstrs
39743979
| _ -> (trace, t1, t2, !univar_pairs)::cstrs)
39753980
| (Tconstr(_, [], _), Tconstr(path, [], _)) when Variant_coercion.can_coerce_primitive path &&
3976-
extract_concrete_typedecl env t1 |> Variant_coercion.can_try_coerce_variant_to_primitive |> Option.is_some
3981+
extract_concrete_typedecl_opt env t1 |> Variant_coercion.can_try_coerce_variant_to_primitive_opt |> Option.is_some
39773982
->
39783983
(* type coercion for variants to primitives *)
3979-
(match Variant_coercion.can_try_coerce_variant_to_primitive (extract_concrete_typedecl env t1) with
3984+
(match Variant_coercion.can_try_coerce_variant_to_primitive_opt (extract_concrete_typedecl_opt env t1) with
39803985
| Some (constructors, unboxed) ->
39813986
if constructors |> Variant_coercion.variant_has_same_runtime_representation_as_target ~targetPath:path ~unboxed then
39823987
cstrs

jscomp/ml/lambda.ml

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,47 @@ let mutable_flag_of_tag_info (tag : tag_info) =
8686
| Blk_some
8787
-> Immutable
8888

89+
type label = Types.label_description
90+
91+
let find_name (attr : Parsetree.attribute) =
92+
match attr with
93+
| ( { txt = "bs.as" | "as" },
94+
PStr
95+
[
96+
{
97+
pstr_desc =
98+
Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (s, _)) }, _);
99+
};
100+
] ) ->
101+
Some s
102+
| _ -> None
103+
104+
let blk_record (fields : (label * _) array) mut record_repr =
105+
let all_labels_info =
106+
Ext_array.map fields (fun (lbl, _) ->
107+
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
108+
in
109+
Blk_record
110+
{ fields = all_labels_info; mutable_flag = mut; record_repr }
89111

90-
let blk_record = ref (fun _ _ _ ->
91-
assert false
92-
)
93-
94-
95-
let blk_record_ext = ref (fun fields mutable_flag ->
96-
let all_labels_info = fields |> Array.map (fun (x,_) -> x.Types.lbl_name) in
97-
Blk_record_ext {fields = all_labels_info; mutable_flag }
98-
)
99112

100-
let blk_record_inlined = ref (fun fields name num_nonconst optional_labels ~tag ~attrs mutable_flag ->
101-
let fields = fields |> Array.map (fun (x,_) -> x.Types.lbl_name) in
113+
let blk_record_ext fields mutable_flag =
114+
let all_labels_info =
115+
Array.map
116+
(fun ((lbl : label), _) ->
117+
Ext_list.find_def lbl.Types.lbl_attributes find_name lbl.lbl_name)
118+
fields
119+
in
120+
Blk_record_ext {fields = all_labels_info; mutable_flag }
121+
122+
let blk_record_inlined fields name num_nonconst optional_labels ~tag ~attrs mutable_flag =
123+
let fields =
124+
Array.map
125+
(fun ((lbl : label), _) ->
126+
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
127+
fields
128+
in
102129
Blk_record_inlined {fields; name; num_nonconst; tag; mutable_flag; optional_labels; attrs }
103-
)
104130

105131
let ref_tag_info : tag_info =
106132
Blk_record {fields = [| "contents" |]; mutable_flag = Mutable; record_repr = Record_regular}
@@ -117,9 +143,17 @@ type field_dbg_info =
117143
| Fld_variant
118144
| Fld_cons
119145
| Fld_array
120-
121-
let fld_record = ref (fun (lbl : Types.label_description) ->
122-
Fld_record {name = lbl.lbl_name; mutable_flag = Mutable})
146+
147+
let fld_record (lbl : label) =
148+
Fld_record
149+
{
150+
name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name;
151+
mutable_flag = lbl.lbl_mut;
152+
}
153+
154+
let fld_record_extension (lbl : label) =
155+
Fld_record_extension
156+
{ name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name }
123157

124158
let ref_field_info : field_dbg_info =
125159
Fld_record { name = "contents"; mutable_flag = Mutable}
@@ -131,8 +165,21 @@ type set_field_dbg_info =
131165
| Fld_record_extension_set of string
132166

133167
let ref_field_set_info : set_field_dbg_info = Fld_record_set "contents"
134-
let fld_record_set = ref ( fun (lbl : Types.label_description) ->
135-
Fld_record_set lbl.lbl_name )
168+
let fld_record_set (lbl : label) =
169+
Fld_record_set
170+
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
171+
172+
let fld_record_inline (lbl : label) =
173+
Fld_record_inline
174+
{ name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name }
175+
176+
let fld_record_inline_set (lbl : label) =
177+
Fld_record_inline_set
178+
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
179+
180+
let fld_record_extension_set (lbl : label) =
181+
Fld_record_extension_set
182+
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
136183

137184
type immediate_or_pointer =
138185
| Immediate

0 commit comments

Comments
 (0)