Skip to content

Commit

Permalink
fix(compiler): Allow proper disambiguation of enum variants (#2068)
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer committed Mar 13, 2024
1 parent 9eeb0f2 commit f3007b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compiler/src/typed/typepat.re
Expand Up @@ -819,10 +819,12 @@ and type_pat_aux =
([{ppat_desc: desc, ppat_loc: loc}], true);
};
let opath =
/*try
let (p0, p, _) = extract_concrete_variant !env expected_ty in
Some (p0, p, true)
with Not_found ->*/ None;
try({
let (p0, p, _) = extract_concrete_variant(env^, expected_ty);
Some((p0, p, true));
}) {
| Not_found => None
};

let candidates =
switch (lid.txt, constrs) {
Expand Down
20 changes: 20 additions & 0 deletions compiler/test/suites/types.re
Expand Up @@ -199,6 +199,26 @@ describe("aliased types", ({test, testSkip}) => {
|},
"expression was expected of type Aliases.Foo = Number",
);
assertRun(
"disambiguation_enum_1",
{|
enum A { V }
enum B { V }
let f = x => match (x) { V: A => print(true) }
f(V)
|},
"true\n",
);
assertRun(
"disambiguation_record_1",
{|
record A { v: Number }
record B { v: Number }
let f = x => match (x) { { v }: A => print(v) }
f({v: 5})
|},
"5\n",
);
assertRun(
"regression_annotated_type_func_1",
{|
Expand Down

0 comments on commit f3007b4

Please sign in to comment.