Skip to content

Commit 38e3336

Browse files
authored
Make Equality Check Pattern Asciptions (#2059)
2 parents c1e7843 + 85bb8b9 commit 38e3336

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/language/term/Equality.re

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ let equality =
403403
(alphas_exp: Alphas.t, alphas_typ: Alphas.t, p1: Pat.t, p2: Pat.t)
404404
: option(Alphas.t) => {
405405
let pat' = pat(alphas_exp, alphas_typ);
406+
let typ' = typ(alphas_exp, alphas_typ);
406407
let any' = any(alphas_exp, alphas_typ);
407408
switch (p1 |> Grammar.Annotated.term_of, p2 |> Grammar.Annotated.term_of) {
408409
// Wrappers when ignored: unwrap.
@@ -414,7 +415,12 @@ let equality =
414415
// Wrappers otherwise: compare.
415416
| (Parens(x), Parens(y)) => pat'(x, y)
416417
| (Parens(_), _) => None
417-
| (Asc(x, _), Asc(y, _)) => pat'(x, y)
418+
| (Asc(x, t1), Asc(y, t2)) =>
419+
if (typ'(t1, t2)) {
420+
pat'(x, y);
421+
} else {
422+
None;
423+
}
418424
| (Asc(_), _) => None
419425

420426
// Variables: special case depending on alpha equivalence.

test/Test_Equality.re

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,35 @@ let tests = (
2020
);
2121
},
2222
),
23+
test_case(
24+
"forall type inequality",
25+
`Quick,
26+
() => {
27+
let forall_string =
28+
Exp.forall(
29+
Pat.asc(Pat.var("x"), Typ.string()),
30+
Exp.bin_op(
31+
Operators.Poly(Operators.Equals),
32+
Exp.var("x"),
33+
Exp.var("x"),
34+
),
35+
);
36+
let forall_int =
37+
Exp.forall(
38+
Pat.asc(Pat.var("x"), Typ.int()),
39+
Exp.bin_op(
40+
Operators.Poly(Operators.Equals),
41+
Exp.var("x"),
42+
Exp.var("x"),
43+
),
44+
);
45+
check(
46+
bool,
47+
"forall x : String -> x == x !== forall x : Int -> x == x",
48+
false,
49+
Equality.semantic.exp(forall_string, forall_int),
50+
);
51+
},
52+
),
2353
],
2454
);

0 commit comments

Comments
 (0)