Skip to content

Commit 3a07374

Browse files
committed
Merge branch 'master' into show-variant-inline-record-hover
2 parents b609762 + dd1f753 commit 3a07374

File tree

440 files changed

+6347
-6293
lines changed

Some content is hidden

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

440 files changed

+6347
-6293
lines changed

.github/workflows/ci.yml

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -137,32 +137,32 @@ jobs:
137137
shell: bash
138138

139139
# matrix.ocaml_compiler may contain commas
140-
# - name: Get OPAM cache key
141-
# shell: bash
142-
# run: echo "opam_cache_key=opam-env-v8-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('*.opam') }}" | sed 's/,/-/g' >> $GITHUB_ENV
140+
- name: Get OPAM cache key
141+
shell: bash
142+
run: echo "opam_cache_key=opam-env-v8-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('*.opam') }}" | sed 's/,/-/g' >> $GITHUB_ENV
143143

144-
# - name: Restore OPAM environment
145-
# id: cache-opam-env
146-
# uses: actions/cache/restore@v4
147-
# with:
148-
# path: |
149-
# ${{ runner.tool_cache }}/opam
150-
# ~/.opam
151-
# _opam
152-
# .opam-path
153-
# D:\cygwin
154-
# D:\.opam
155-
# key: ${{ env.opam_cache_key }}
144+
- name: Restore OPAM environment
145+
id: cache-opam-env
146+
uses: actions/cache/restore@v4
147+
with:
148+
path: |
149+
${{ runner.tool_cache }}/opam
150+
~/.opam
151+
_opam
152+
.opam-path
153+
D:\cygwin
154+
D:\.opam
155+
key: ${{ env.opam_cache_key }}
156156

157157
- name: Use OCaml ${{matrix.ocaml_compiler}}
158158
uses: ocaml/[email protected]
159-
# if: steps.cache-opam-env.outputs.cache-hit != 'true'
159+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
160160
with:
161161
ocaml-compiler: ${{matrix.ocaml_compiler}}
162162
opam-pin: false
163163

164164
- name: Get OPAM executable path
165-
# if: steps.cache-opam-env.outputs.cache-hit != 'true'
165+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
166166
uses: actions/github-script@v7
167167
with:
168168
script: |
@@ -174,63 +174,63 @@ jobs:
174174
console.log('stored path to .opam-path');
175175
176176
- name: Install OPAM dependencies
177-
# if: steps.cache-opam-env.outputs.cache-hit != 'true'
177+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
178178
run: opam install . --deps-only --with-test
179179

180-
# - name: Cache OPAM environment
181-
# # if: steps.cache-opam-env.outputs.cache-hit != 'true'
182-
# uses: actions/cache/save@v4
183-
# with:
184-
# path: |
185-
# ${{ runner.tool_cache }}/opam
186-
# ~/.opam
187-
# _opam
188-
# .opam-path
189-
# D:\cygwin
190-
# D:\.opam
191-
# key: ${{ env.opam_cache_key }}
192-
193-
# - name: Use cached OPAM environment
194-
# if: steps.cache-opam-env.outputs.cache-hit == 'true'
195-
# run: |
196-
# # https://github.com/ocaml/setup-ocaml/blob/b2105f9/packages/setup-ocaml/src/installer.ts#L33
197-
# echo "OPAMVERBOSE=$RUNNER_DEBUG" >> "$GITHUB_ENV"
198-
# echo "OPAMCOLOR=always" >> "$GITHUB_ENV"
199-
# echo "OPAMCONFIRMLEVEL=unsafe-yes" >> "$GITHUB_ENV"
200-
# echo "OPAMERRLOGLEN=0" >> "$GITHUB_ENV"
201-
# echo "OPAMPRECISETRACKING=1" >> "$GITHUB_ENV"
202-
# echo "OPAMYES=1" >> "$GITHUB_ENV"
203-
204-
# if [[ "$RUNNER_OS" != "Windows" ]]; then
205-
# echo "OPAMROOT=$HOME/.opam" >> "$GITHUB_ENV"
206-
# else
207-
# echo "OPAMROOT=D:\\.opam" >> "$GITHUB_ENV"
208-
# fi
209-
210-
# OPAM_PATH="$(cat .opam-path)"
211-
# chmod +x "$OPAM_PATH"
212-
# dirname "$OPAM_PATH" >> "$GITHUB_PATH"
213-
214-
# if [[ "$RUNNER_OS" == "Windows" ]]; then
215-
# fsutil behavior query SymlinkEvaluation
216-
# fsutil behavior set symlinkEvaluation R2L:1 R2R:1
217-
# fsutil behavior query SymlinkEvaluation
218-
219-
# CYGWIN="winsymlinks:native"
220-
# CYGWIN_ROOT="D:\\cygwin"
221-
# CYGWIN_ROOT_BIN="D:\\cygwin\\bin"
222-
# CYGWIN_ROOT_WRAPPERBIN="D:\\cygwin\\wrapperbin"
223-
224-
# echo "HOME=$USERPROFILE" >> "$GITHUB_ENV"
225-
# echo "MSYS=winsymlinks:native" >> "$GITHUB_ENV"
226-
# echo "CYGWIN=$CYGWIN" >> "$GITHUB_ENV"
227-
# echo "CYGWIN_ROOT=$CYGWIN_ROOT" >> "$GITHUB_ENV"
228-
# echo "CYGWIN_ROOT_BIN=$CYGWIN_ROOT_BIN" >> "$GITHUB_ENV"
229-
# echo "CYGWIN_ROOT_WRAPPERBIN=$CYGWIN_ROOT_WRAPPERBIN" >> "$GITHUB_ENV"
230-
231-
# echo "$CYGWIN_ROOT_WRAPPERBIN" >> "$GITHUB_PATH"
232-
# fi
233-
# shell: bash
180+
- name: Cache OPAM environment
181+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
182+
uses: actions/cache/save@v4
183+
with:
184+
path: |
185+
${{ runner.tool_cache }}/opam
186+
~/.opam
187+
_opam
188+
.opam-path
189+
D:\cygwin
190+
D:\.opam
191+
key: ${{ env.opam_cache_key }}
192+
193+
- name: Use cached OPAM environment
194+
if: steps.cache-opam-env.outputs.cache-hit == 'true'
195+
run: |
196+
# https://github.com/ocaml/setup-ocaml/blob/b2105f9/packages/setup-ocaml/src/installer.ts#L33
197+
echo "OPAMVERBOSE=$RUNNER_DEBUG" >> "$GITHUB_ENV"
198+
echo "OPAMCOLOR=always" >> "$GITHUB_ENV"
199+
echo "OPAMCONFIRMLEVEL=unsafe-yes" >> "$GITHUB_ENV"
200+
echo "OPAMERRLOGLEN=0" >> "$GITHUB_ENV"
201+
echo "OPAMPRECISETRACKING=1" >> "$GITHUB_ENV"
202+
echo "OPAMYES=1" >> "$GITHUB_ENV"
203+
204+
if [[ "$RUNNER_OS" != "Windows" ]]; then
205+
echo "OPAMROOT=$HOME/.opam" >> "$GITHUB_ENV"
206+
else
207+
echo "OPAMROOT=D:\\.opam" >> "$GITHUB_ENV"
208+
fi
209+
210+
OPAM_PATH="$(cat .opam-path)"
211+
chmod +x "$OPAM_PATH"
212+
dirname "$OPAM_PATH" >> "$GITHUB_PATH"
213+
214+
if [[ "$RUNNER_OS" == "Windows" ]]; then
215+
fsutil behavior query SymlinkEvaluation
216+
fsutil behavior set symlinkEvaluation R2L:1 R2R:1
217+
fsutil behavior query SymlinkEvaluation
218+
219+
CYGWIN="winsymlinks:native"
220+
CYGWIN_ROOT="D:\\cygwin"
221+
CYGWIN_ROOT_BIN="D:\\cygwin\\bin"
222+
CYGWIN_ROOT_WRAPPERBIN="D:\\cygwin\\wrapperbin"
223+
224+
echo "HOME=$USERPROFILE" >> "$GITHUB_ENV"
225+
echo "MSYS=winsymlinks:native" >> "$GITHUB_ENV"
226+
echo "CYGWIN=$CYGWIN" >> "$GITHUB_ENV"
227+
echo "CYGWIN_ROOT=$CYGWIN_ROOT" >> "$GITHUB_ENV"
228+
echo "CYGWIN_ROOT_BIN=$CYGWIN_ROOT_BIN" >> "$GITHUB_ENV"
229+
echo "CYGWIN_ROOT_WRAPPERBIN=$CYGWIN_ROOT_WRAPPERBIN" >> "$GITHUB_ENV"
230+
231+
echo "$CYGWIN_ROOT_WRAPPERBIN" >> "$GITHUB_PATH"
232+
fi
233+
shell: bash
234234

235235
- name: Compiler build state key
236236
id: compiler-build-state-key

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
- Complete from `RegExp` stdlib module for regexes. https://github.com/rescript-lang/rescript/pull/7425
2929
- Allow oneliner formatting when including module with single type alias. https://github.com/rescript-lang/rescript/pull/7502
3030
- Improve error messages for JSX type mismatches, passing objects where record is expected, passing array literal where tuple is expected, and more. https://github.com/rescript-lang/rescript/pull/7500
31+
- Show in error messages when coercion can be used to fix a type mismatch. https://github.com/rescript-lang/rescript/pull/7505
32+
- Remove deprecated pipe last (|>) syntax. https://github.com/rescript-lang/rescript/pull/7512
3133

3234
# 12.0.0-alpha.13
3335

analysis/reanalyze/src/Exception.ml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,17 +304,6 @@ let traverseAst () =
304304
let exceptions = [arg] |> raiseArgs in
305305
currentEvents := {Event.exceptions; loc; kind = Raises} :: !currentEvents;
306306
arg |> snd |> iterExprOpt self
307-
| Texp_apply
308-
{
309-
funct = {exp_desc = Texp_ident (atat, _, _)};
310-
args = [arg; (_lbl1, Some {exp_desc = Texp_ident (callee, _, _)})];
311-
}
312-
when (* Exn(...) |> raise *)
313-
atat |> Path.name = "Pervasives.|>" && callee |> Path.name |> isRaise
314-
->
315-
let exceptions = [arg] |> raiseArgs in
316-
currentEvents := {Event.exceptions; loc; kind = Raises} :: !currentEvents;
317-
arg |> snd |> iterExprOpt self
318307
| Texp_apply {funct = {exp_desc = Texp_ident (callee, _, _)} as e; args} ->
319308
let calleeName = Path.name callee in
320309
if calleeName |> isRaise then

compiler/ml/error_message_utils.ml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ let with_configured_jsx_module s =
1111
module Parser : sig
1212
type comment
1313

14+
val extract_text_at_loc : Location.t -> string
15+
1416
val parse_source : (string -> Parsetree.structure * comment list) ref
1517

1618
val reprint_source : (Parsetree.structure -> comment list -> string) ref
@@ -38,10 +40,13 @@ end = struct
3840
let end_offset = end_pos.pos_cnum in
3941
String.sub src start_offset (end_offset - start_offset)
4042

41-
let parse_expr_at_loc loc =
43+
let extract_text_at_loc loc =
4244
(* TODO: Maybe cache later on *)
4345
let src = Ext_io.load_file loc.Location.loc_start.pos_fname in
44-
let sub_src = extract_location_string ~src loc in
46+
extract_location_string ~src loc
47+
48+
let parse_expr_at_loc loc =
49+
let sub_src = extract_text_at_loc loc in
4550
let parsed, comments = !parse_source sub_src in
4651
match parsed with
4752
| [{Parsetree.pstr_desc = Pstr_eval (exp, _)}] -> Some (exp, comments)
@@ -59,6 +64,11 @@ end = struct
5964
| None -> None
6065
end
6166
67+
let type_expr ppf typ =
68+
(* print a type and avoid infinite loops *)
69+
Printtyp.reset_and_mark_loops typ;
70+
Printtyp.type_expr ppf typ
71+
6272
type type_clash_statement = FunctionCall
6373
type type_clash_context =
6474
| SetRecordField
@@ -345,6 +355,43 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env loc ppf
345355
single JSX element.@,"
346356
(with_configured_jsx_module "array")
347357
| _ -> ())
358+
| _, Some (t1, t2) ->
359+
let is_subtype =
360+
try
361+
Ctype.subtype env t1 t2 ();
362+
true
363+
with _ -> false
364+
in
365+
let target_type_string = Format.asprintf "%a" type_expr t2 in
366+
let target_expr_text = Parser.extract_text_at_loc loc in
367+
let suggested_rewrite =
368+
match
369+
!Parser.parse_source
370+
(Printf.sprintf "(%s :> %s)" target_expr_text target_type_string)
371+
with
372+
| [], _ -> None
373+
| structure, comments -> Some (!Parser.reprint_source structure comments)
374+
in
375+
376+
(* Suggesting coercion only makes sense for non-constant values. *)
377+
let is_constant =
378+
match !Parser.parse_source target_expr_text with
379+
| ( [{Parsetree.pstr_desc = Pstr_eval ({pexp_desc = Pexp_constant _}, _)}],
380+
_ ) ->
381+
true
382+
| _ -> false
383+
in
384+
385+
if is_subtype && not is_constant then (
386+
fprintf ppf
387+
"@,\
388+
@,\
389+
Possible solutions: @,\
390+
- These types are compatible at runtime. You can use the coercion \
391+
operator to convert to the expected type";
392+
match suggested_rewrite with
393+
| Some rewrite -> fprintf ppf ": @{<info>%s@}@," rewrite
394+
| None -> fprintf ppf ": @{<info>:>@}@,")
348395
| _ -> ()
349396
350397
let type_clash_context_from_function sexp sfunct =

compiler/ml/typecore.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,10 +4168,8 @@ let longident = Printtyp.longident
41684168
let super_report_unification_error = Printtyp.super_report_unification_error
41694169
let report_ambiguous_type_error = Printtyp.report_ambiguous_type_error
41704170
let report_subtyping_error = Printtyp.report_subtyping_error
4171-
let type_expr ppf typ =
4172-
(* print a type and avoid infinite loops *)
4173-
Printtyp.reset_and_mark_loops typ;
4174-
Printtyp.type_expr ppf typ
4171+
4172+
let type_expr = Error_message_utils.type_expr
41754173
41764174
let report_error env loc ppf error =
41774175
match error with

compiler/syntax/src/res_comments_table.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,9 +1483,8 @@ and walk_expression expr t comments =
14831483
txt =
14841484
Longident.Lident
14851485
( ":=" | "||" | "&&" | "==" | "===" | "<" | ">" | "!="
1486-
| "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-."
1487-
| "++" | "^" | "*" | "*." | "/" | "/." | "**" | "->"
1488-
| "<>" );
1486+
| "!==" | "<=" | ">=" | "+" | "+." | "-" | "-." | "++"
1487+
| "^" | "*" | "*." | "/" | "/." | "**" | "->" | "<>" );
14891488
};
14901489
};
14911490
args = [(Nolabel, operand1); (Nolabel, operand2)];

compiler/syntax/src/res_core.ml

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,25 +2186,9 @@ and parse_binary_expr ?(context = OrdinaryExpr) ?a p prec =
21862186
let b = parse_binary_expr ~context p token_prec in
21872187
let loc = mk_loc a.Parsetree.pexp_loc.loc_start b.pexp_loc.loc_end in
21882188
let expr =
2189-
match (token, b.pexp_desc) with
2190-
| ( BarGreater,
2191-
Pexp_apply {funct = fun_expr; args; partial; transformed_jsx} ) ->
2192-
{
2193-
b with
2194-
pexp_desc =
2195-
Pexp_apply
2196-
{
2197-
funct = fun_expr;
2198-
args = args @ [(Nolabel, a)];
2199-
partial;
2200-
transformed_jsx;
2201-
};
2202-
}
2203-
| BarGreater, _ -> Ast_helper.Exp.apply ~loc b [(Nolabel, a)]
2204-
| _ ->
2205-
Ast_helper.Exp.apply ~loc
2206-
(make_infix_operator p token start_pos end_pos)
2207-
[(Nolabel, a); (Nolabel, b)]
2189+
Ast_helper.Exp.apply ~loc
2190+
(make_infix_operator p token start_pos end_pos)
2191+
[(Nolabel, a); (Nolabel, b)]
22082192
in
22092193
Parser.eat_breadcrumb p;
22102194
loop expr)

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ let operator_precedence operator =
280280
| "&&" -> 3
281281
| "^" -> 4
282282
| "&" -> 5
283-
| "==" | "===" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 6
283+
| "==" | "===" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" -> 6
284284
| "<<" | ">>" | ">>>" -> 7
285285
| "+" | "+." | "-" | "-." | "++" -> 8
286286
| "*" | "*." | "/" | "/." | "%" -> 9
@@ -317,8 +317,8 @@ let is_unary_bitnot_expression expr =
317317
let is_binary_operator operator =
318318
match operator with
319319
| ":=" | "||" | "&&" | "==" | "===" | "<" | ">" | "!=" | "!==" | "<=" | ">="
320-
| "|>" | "+" | "+." | "-" | "-." | "++" | "*" | "*." | "/" | "/." | "**"
321-
| "->" | "<>" | "%" | "&" | "^" | "<<" | ">>" | ">>>" ->
320+
| "+" | "+." | "-" | "-." | "++" | "*" | "*." | "/" | "/." | "**" | "->"
321+
| "<>" | "%" | "&" | "^" | "<<" | ">>" | ">>>" ->
322322
true
323323
| _ -> false
324324

@@ -715,7 +715,7 @@ let is_single_pipe_expr expr =
715715
match expr.pexp_desc with
716716
| Pexp_apply
717717
{
718-
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("->" | "|>")}};
718+
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "->"}};
719719
args = [(Nolabel, _operand1); (Nolabel, _operand2)];
720720
} ->
721721
true
@@ -724,7 +724,7 @@ let is_single_pipe_expr expr =
724724
match expr.pexp_desc with
725725
| Pexp_apply
726726
{
727-
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("->" | "|>")}};
727+
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "->"}};
728728
args = [(Nolabel, operand1); (Nolabel, _operand2)];
729729
}
730730
when not (is_pipe_expr operand1) ->

0 commit comments

Comments
 (0)