Skip to content

Commit

Permalink
Fix a warning in sail-riscv
Browse files Browse the repository at this point in the history
Make sure we bind existential type variables introduced by
match head expressions before checking completeness, otherwise
we can miss some obvious cases
  • Loading branch information
Alasdair committed Dec 6, 2023
1 parent 3d97877 commit d72950e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/type_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1855,8 +1855,9 @@ let rec check_exp env (E_aux (exp_aux, (l, uannot)) as exp : uannot exp) (Typ_au
if Option.is_some (get_attribute "complete" uannot) || Option.is_some (get_attribute "incomplete" uannot) then
(checked_cases, fun attrs -> attrs)
else (
let completeness_typ, env = bind_existential (exp_loc exp) None inferred_typ env in
let ctx = pattern_completeness_ctx env in
match PC.is_complete_wildcarded l ctx checked_cases inferred_typ with
match PC.is_complete_wildcarded l ctx checked_cases completeness_typ with
| Some wildcarded -> (wildcarded, add_attribute (gen_loc l) "complete" "")
| None -> (checked_cases, add_attribute (gen_loc l) "incomplete" "")
)
Expand Down
1 change: 1 addition & 0 deletions test/c/struct_fn_arg.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f1 = 3
16 changes: 16 additions & 0 deletions test/c/struct_fn_arg.sail
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
default Order dec

$include <prelude.sail>

struct S = {
f1 : int,
f2 : int,
}

function foo(struct { f1, _ } : S, x : nat) -> unit = {
print_int("f1 = ", f1);
}

function main() -> unit = {
foo(struct { f1 = 3, f2 = 4 }, 5);
}
13 changes: 13 additions & 0 deletions test/pattern_completeness/set_match.sail
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
default Order dec

$include <prelude.sail>

val foo : unit -> {1, 2, 3}

function bar() -> unit = {
match foo() {
1 => (),
2 => (),
3 => (),
}
}
16 changes: 16 additions & 0 deletions test/typecheck/struct_fn_arg.sail
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
default Order dec

$include <prelude.sail>

struct S = {
f1 : int,
f2 : int,
}

function foo(struct { f1, _ } : S, x : nat) -> unit = {
print_int("f1 = ", f1);
}

function main() -> unit = {
foo(struct { f1 = 3, f2 = 4 }, 5);
}

0 comments on commit d72950e

Please sign in to comment.