Skip to content

Commit 239f653

Browse files
committed
Merge branch 'master' into jsx-ast
2 parents 26cee66 + 9da9b19 commit 239f653

28 files changed

+184
-128
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
- Fix `%external` extension. https://github.com/rescript-lang/rescript/pull/7272
2323
- Fix issue with type environment for unified ops. https://github.com/rescript-lang/rescript/pull/7277
2424
- Fix completion for application with tagged template. https://github.com/rescript-lang/rescript/pull/7278
25+
- Fix error message for arity in the presence of optional arguments. https://github.com/rescript-lang/rescript/pull/7284
26+
- Fix issue in functors with more than one argument (which are curried): emit nested function always. https://github.com/rescript-lang/rescript/pull/7273
27+
28+
#### :house: Internal
29+
30+
- Remove ignore in res_scanner.ml . https://github.com/rescript-lang/rescript/pull/7280
2531

2632
# 12.0.0-alpha.8
2733

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ node_modules/.bin/semver:
3232
test: lib
3333
node scripts/test.js -all
3434

35+
test-analysis:
36+
make -C tests/analysis_tests clean test
37+
38+
test-tools:
39+
make -C tests/tools_tests clean test
40+
3541
test-syntax:
3642
bash ./scripts/test_syntax.sh
3743
make reanalyze
@@ -45,7 +51,7 @@ test-syntax-roundtrip:
4551
test-gentype:
4652
make -C tests/gentype_tests/typescript-react-example clean test
4753

48-
test-all: test test-gentype
54+
test-all: test test-gentype test-analysis test-tools
4955

5056
reanalyze:
5157
reanalyze.exe -set-exit-code -all-cmt _build/default/compiler _build/default/tests -exclude-paths compiler/outcome_printer,compiler/ml,compiler/js_parser,compiler/frontend,compiler/ext,compiler/depends,compiler/core,compiler/common,compiler/cmij,compiler/bsb_helper,compiler/bsb
@@ -95,4 +101,4 @@ dev-container:
95101

96102
.DEFAULT_GOAL := build
97103

98-
.PHONY: build watch rewatch ninja bench dce test test-syntax test-syntax-roundtrip test-gentype test-all lib playground playground-cmijs playground-release artifacts format checkformat clean-gentype clean-rewatch clean clean-all dev-container
104+
.PHONY: build watch rewatch ninja bench dce test test-syntax test-syntax-roundtrip test-gentype test-analysis test-tools test-all lib playground playground-cmijs playground-release artifacts format checkformat clean-gentype clean-rewatch clean clean-all dev-container

compiler/ml/translmod.ml

Lines changed: 45 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
open Typedtree
2020

21-
type error = Conflicting_inline_attributes | Fragile_pattern_in_toplevel
21+
type error = Fragile_pattern_in_toplevel
2222

2323
exception Error of Location.t * error
2424

@@ -78,37 +78,30 @@ let rec apply_coercion loc strict (restr : Typedtree.module_coercion) arg =
7878
| Tcoerce_functor (cc_arg, cc_res) ->
7979
let param = Ident.create "funarg" in
8080
let carg = apply_coercion loc Alias cc_arg (Lvar param) in
81-
apply_coercion_result loc strict arg [param] [carg] cc_res
81+
apply_coercion_result loc strict arg param carg cc_res
8282
| Tcoerce_primitive {pc_loc; pc_desc; pc_env; pc_type} ->
8383
Translcore.transl_primitive pc_loc pc_desc pc_env pc_type
8484
| Tcoerce_alias (path, cc) ->
8585
Lambda.name_lambda strict arg (fun _ ->
8686
apply_coercion loc Alias cc (Lambda.transl_normal_path path))
8787

88-
and apply_coercion_result loc strict funct params args cc_res =
89-
match cc_res with
90-
| Tcoerce_functor (cc_arg, cc_res) ->
91-
let param = Ident.create "funarg" in
92-
let arg = apply_coercion loc Alias cc_arg (Lvar param) in
93-
apply_coercion_result loc strict funct (param :: params) (arg :: args)
94-
cc_res
95-
| _ ->
96-
Lambda.name_lambda strict funct (fun id ->
97-
Lfunction
98-
{
99-
params = List.rev params;
100-
attr = {Lambda.default_function_attribute with is_a_functor = true};
101-
loc;
102-
body =
103-
apply_coercion loc Strict cc_res
104-
(Lapply
105-
{
106-
ap_loc = loc;
107-
ap_func = Lvar id;
108-
ap_args = List.rev args;
109-
ap_inlined = Default_inline;
110-
});
111-
})
88+
and apply_coercion_result loc strict funct param arg cc_res =
89+
Lambda.name_lambda strict funct (fun id ->
90+
Lfunction
91+
{
92+
params = [param];
93+
attr = {Lambda.default_function_attribute with is_a_functor = true};
94+
loc;
95+
body =
96+
apply_coercion loc Strict cc_res
97+
(Lapply
98+
{
99+
ap_loc = loc;
100+
ap_func = Lvar id;
101+
ap_args = [arg];
102+
ap_inlined = Default_inline;
103+
});
104+
})
112105

113106
and wrap_id_pos_list loc id_pos_list get_field lam =
114107
let fv = Lambda.free_variables lam in
@@ -210,64 +203,41 @@ let rec bound_value_identifiers : Types.signature_item list -> Ident.t list =
210203
functor(s) being merged with. Such an attribute will be placed on the
211204
resulting merged functor. *)
212205

213-
let merge_inline_attributes (attr1 : Lambda.inline_attribute)
214-
(attr2 : Lambda.inline_attribute) loc =
215-
match (attr1, attr2) with
216-
| Lambda.Default_inline, _ -> attr2
217-
| _, Lambda.Default_inline -> attr1
218-
| _, _ ->
219-
if attr1 = attr2 then attr1
220-
else raise (Error (loc, Conflicting_inline_attributes))
221-
222-
let merge_functors mexp coercion root_path =
223-
let rec merge mexp coercion path acc inline_attribute =
224-
let finished = (acc, mexp, path, coercion, inline_attribute) in
225-
match mexp.mod_desc with
226-
| Tmod_functor (param, _, _, body) ->
227-
let inline_attribute' =
228-
Translattribute.get_inline_attribute mexp.mod_attributes
229-
in
230-
let arg_coercion, res_coercion =
231-
match coercion with
232-
| Tcoerce_none -> (Tcoerce_none, Tcoerce_none)
233-
| Tcoerce_functor (arg_coercion, res_coercion) ->
234-
(arg_coercion, res_coercion)
235-
| _ -> Misc.fatal_error "Translmod.merge_functors: bad coercion"
236-
in
237-
let loc = mexp.mod_loc in
238-
let path = functor_path path param in
239-
let inline_attribute =
240-
merge_inline_attributes inline_attribute inline_attribute' loc
241-
in
242-
merge body res_coercion path
243-
((param, loc, arg_coercion) :: acc)
244-
inline_attribute
245-
| _ -> finished
246-
in
247-
merge mexp coercion root_path [] Default_inline
206+
let get_functor_params mexp coercion root_path =
207+
match mexp.mod_desc with
208+
| Tmod_functor (param, _, _, body) ->
209+
let inline_attribute =
210+
Translattribute.get_inline_attribute mexp.mod_attributes
211+
in
212+
let arg_coercion, res_coercion =
213+
match coercion with
214+
| Tcoerce_none -> (Tcoerce_none, Tcoerce_none)
215+
| Tcoerce_functor (arg_coercion, res_coercion) ->
216+
(arg_coercion, res_coercion)
217+
| _ -> Misc.fatal_error "Translmod.get_functor_params: bad coercion"
218+
in
219+
let loc = mexp.mod_loc in
220+
let path = functor_path root_path param in
221+
((param, loc, arg_coercion), body, path, res_coercion, inline_attribute)
222+
| _ -> assert false
248223

249224
let export_identifiers : Ident.t list ref = ref []
250225

251226
let rec compile_functor mexp coercion root_path loc =
252-
let functor_params_rev, body, body_path, res_coercion, inline_attribute =
253-
merge_functors mexp coercion root_path
227+
let functor_param, body, body_path, res_coercion, inline_attribute =
228+
get_functor_params mexp coercion root_path
254229
in
255-
assert (functor_params_rev <> []);
256230
(* cf. [transl_module] *)
257-
let params, body =
258-
List.fold_left
259-
(fun (params, body) (param, loc, arg_coercion) ->
260-
let param' = Ident.rename param in
261-
let arg = apply_coercion loc Alias arg_coercion (Lvar param') in
262-
let params = param' :: params in
263-
let body = Lambda.Llet (Alias, Pgenval, param, arg, body) in
264-
(params, body))
265-
([], transl_module res_coercion body_path body)
266-
functor_params_rev
231+
let param, loc_, arg_coercion = functor_param in
232+
let param' = Ident.rename param in
233+
let arg = apply_coercion loc_ Alias arg_coercion (Lvar param') in
234+
let body =
235+
Lambda.Llet
236+
(Alias, Pgenval, param, arg, transl_module res_coercion body_path body)
267237
in
268238
Lambda.Lfunction
269239
{
270-
params;
240+
params = [param'];
271241
attr =
272242
{
273243
inline = inline_attribute;
@@ -513,8 +483,6 @@ let transl_implementation module_name (str, cc) =
513483
(* Error report *)
514484

515485
let report_error ppf = function
516-
| Conflicting_inline_attributes ->
517-
Format.fprintf ppf "@[Conflicting ``inline'' attributes@]"
518486
| Fragile_pattern_in_toplevel ->
519487
Format.fprintf ppf "@[Such fragile pattern not allowed in the toplevel@]"
520488

compiler/ml/typecore.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3517,13 +3517,14 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
35173517
| Some arity ->
35183518
let newarity = arity - nargs in
35193519
let fully_applied = newarity <= 0 in
3520-
if total_app && not fully_applied then
3521-
raise
3522-
(Error
3523-
( funct.exp_loc,
3524-
env,
3525-
Uncurried_arity_mismatch
3526-
(funct.exp_type, arity, List.length sargs) ));
3520+
(if total_app && not fully_applied then
3521+
let required_args = List.length sargs in
3522+
raise
3523+
(Error
3524+
( funct.exp_loc,
3525+
env,
3526+
Uncurried_arity_mismatch
3527+
(funct.exp_type, required_args + newarity, required_args) )));
35273528
let new_t =
35283529
if fully_applied then new_t
35293530
else
@@ -4466,7 +4467,7 @@ let report_error env ppf error =
44664467
"@ @[It is applied with @{<error>%d@} argument%s but it requires \
44674468
@{<info>%d@}.@]@]"
44684469
args
4469-
(if args = 0 then "" else "s")
4470+
(if args = 1 then "" else "s")
44704471
arity
44714472
| Field_not_optional (name, typ) ->
44724473
fprintf ppf "Field @{<info>%s@} is not optional in type %a. Use without ?"

compiler/syntax/src/res_scanner.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ let scan_number scanner =
257257
8)
258258
| _ -> 10
259259
in
260-
ignore (scan_digits scanner ~base);
260+
let _ : bool = scan_digits scanner ~base in
261261

262262
(* *)
263263
let is_float =
264264
if '.' == scanner.ch then (
265265
next scanner;
266-
ignore (scan_digits scanner ~base);
266+
let _ : bool = scan_digits scanner ~base in
267267
true)
268268
else false
269269
in

scripts/format.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ shopt -s extglob
44

55
dune build @fmt --auto-promote
66

7-
files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -path "tests/syntax_*" ! -path "tests/analysis_tests/tests*" ! -path "tests/gentype_tests/typescript-react-example/node_modules")
7+
files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -path "tests/syntax_*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
88
./cli/rescript format $files
99

1010
npm run format

scripts/format_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ case "$(uname -s)" in
1717
fi
1818

1919
echo "Checking ReScript code formatting..."
20-
files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -path "tests/syntax_*" ! -path "tests/analysis_tests/tests*" ! -path "tests/gentype_tests/typescript-react-example/node_modules")
20+
files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -path "tests/syntax_*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
2121
if ./cli/rescript format -check $files; then
2222
printf "${successGreen}✅ ReScript code formatting ok.${reset}\n"
2323
else

tests/analysis_tests/tests-generic-jsx-transform/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test: build
1010
./test.sh
1111

1212
clean:
13-
rm -r node_modules lib
13+
rm -rf node_modules lib
1414

1515
.DEFAULT_GOAL := test
1616

tests/analysis_tests/tests-incremental-typechecking/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test: build
1010
./test.sh
1111

1212
clean:
13-
rm -r node_modules lib
13+
rm -rf node_modules lib
1414

1515
.DEFAULT_GOAL := test
1616

tests/analysis_tests/tests-reanalyze/deadcode/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test: build node_modules/.bin/rescript
1010
./test.sh
1111

1212
clean:
13-
rm -r node_modules lib
13+
rm -rf node_modules lib
1414

1515
.DEFAULT_GOAL := build
1616

0 commit comments

Comments
 (0)