Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): Allow proper disambiguation of enum variants #2068

Merged
merged 1 commit into from Mar 14, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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