Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#### :nail_care: Polish

- Improve default argument type mismatch errors. https://github.com/rescript-lang/rescript/pull/8389

#### :house: Internal

# 13.0.0-alpha.4
Expand Down
15 changes: 9 additions & 6 deletions compiler/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,7 @@ and type_expect_ ?deprecated_context ~context ?in_function ?(recarg = Rejected)
in
let smatch =
Exp.match_ ~loc:sloc
~attrs:[(mknoloc "#optional_arg_default", PStr [])]
(Exp.ident ~loc (mknoloc (Longident.Lident "*opt*")))
scases
in
Expand Down Expand Up @@ -2540,13 +2541,15 @@ and type_expect_ ?deprecated_context ~context ?in_function ?(recarg = Rejected)
(* Note: val_caselist = [] and exn_caselist = [], i.e. a fully
empty pattern matching can be generated by Camlp4 with its
revised syntax. Let's accept it for backward compatibility. *)
let has_attr name =
Ext_list.exists sexp.pexp_attributes (fun ({txt}, _) -> txt = name)
in
let call_context =
if
Ext_list.exists sexp.pexp_attributes (fun ({txt}, _) ->
match txt with
| "let.unwrap" -> true
| _ -> false)
then `LetUnwrap
(* Optional-default lowering synthesizes a match expression, but from the
user's point of view this is still part of a function definition. Use
function-style diagnostics instead of reporting a phantom switch. *)
if has_attr "let.unwrap" then `LetUnwrap
else if has_attr "#optional_arg_default" then `Function
else `Switch
in
let val_cases, partial =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
3 │

This has type: float
But it's expected to have type: JSON.t (defined as JSON.t)
But it's expected to have type: JSON.t (defined as JSON.t)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
7 │ }

This has type: Iterable.t<int> (defined as iterable<int>)
But it's expected to have type: asyncIterable<'a>
But it's expected to have type: asyncIterable<'a>
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
4 │ }

This has type: int
But it's expected to have type: iterable<'a>
But it's expected to have type: iterable<'a>
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
6 │ }

This has type: string
But it's expected to have type: iterable<'a>
But it's expected to have type: iterable<'a>
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
This has type: int
But it's expected to have type: string

You can convert int to string with Int.toString.
You can convert int to string with Int.toString.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
18 │ let _ = <Component bar="hello" />
19 │

The prop bar does not belong to the JSX component <Component />


The prop bar does not belong to the JSX component <Component />
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

We've found a bug for you!
/.../fixtures/optional_default_arg_type_mismatch.res:1:29-30

1 │ let f = (~test: option<int>=42) => ()
2 │

This has type: int
But it's expected to have type: option<int>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let f = (~test: option<int>=42) => ()
Loading