Skip to content

Commit 4190901

Browse files
committed
no need to check tvar
1 parent 7b979f3 commit 4190901

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Warning number 9
3+
/.../fixtures/dict_pattern_regular_record.res:5:22-33
4+
5+
3 │ let constrainedAsDict = (dict: x) =>
6+
4 │ switch dict {
7+
5 │ | @res.dictPattern {one: "one"} => Js.log("one")
8+
6 │ | _ => Js.log("not one")
9+
7 │ }
10+
11+
the following labels are not bound in this record pattern: dictValuesType
12+
Either bind these labels explicitly or add ', _' to the pattern.
13+
14+
15+
We've found a bug for you!
16+
/.../fixtures/dict_pattern_regular_record.res:5:22-33
17+
18+
3 │ let constrainedAsDict = (dict: x) =>
19+
4 │ switch dict {
20+
5 │ | @res.dictPattern {one: "one"} => Js.log("one")
21+
6 │ | _ => Js.log("not one")
22+
7 │ }
23+
24+
This pattern matches values of type dict<string>
25+
but a pattern was expected which matches values of type x
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type x = {one: int}
2+
3+
let constrainedAsDict = (dict: x) =>
4+
switch dict {
5+
| @res.dictPattern {one: "one"} => Js.log("one")
6+
| _ => Js.log("not one")
7+
}

jscomp/ml/typecore.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,13 +1386,12 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
13861386
| Ppat_record(lid_sp_list, closed) ->
13871387
let has_dict_pattern_attr = Dict_type_helpers.has_dict_pattern_attribute sp.ppat_attributes in
13881388
let opath, record_ty = (
1389-
match (has_dict_pattern_attr, expected_ty.desc) with
1390-
| (true, Tvar _) ->
1389+
if has_dict_pattern_attr then (
13911390
(* When this is a dict pattern and we don't have an actual expected type yet,
13921391
infer the type as a dict with a new type variable. This let us hook into the
13931392
existing inference mechanism for records in dict pattern matching too. *)
13941393
(Some (Predef.path_dict, Predef.path_dict), newgenty (Tconstr (Predef.path_dict, [newvar ()], ref Mnil)))
1395-
| _ ->
1394+
) else
13961395
try
13971396
let (p0, p, _, _) = extract_concrete_record !env expected_ty in
13981397
Some (p0, p), expected_ty

0 commit comments

Comments
 (0)