Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpal committed Jan 29, 2024
1 parent 34ee484 commit cb0f149
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tree_unique_args/src/type_analysis.egg
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,28 @@
((HasType f (FuncT in-ty out-ty)))
:ruleset type-analysis)

(rule (
(= f (Function id body in-ty out-ty))
(HasType body ty)
(!= ty out-ty)
)
((panic "Function body had wrong type :("))
:ruleset type-analysis)

(rule (
(= c (Call f-id arg))
(= f (Function f-id body in-ty out-ty))
(HasType f (FuncT in-ty out-ty))
(HasType arg in-ty)
)
((HasType c out-ty))
:ruleset type-analysis)
:ruleset type-analysis)

(rule (
(= c (Call f-id arg))
(= f (Function f-id body in-ty out-ty))
(HasType arg ty)
(!= ty in-ty)
)
((panic "Function call had wrong argument type :("))
:ruleset type-analysis)
35 changes: 35 additions & 0 deletions tree_unique_args/src/type_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,38 @@ fn func() -> Result<(), egglog::Error> {
);
crate::run_test(build, &check)
}

#[test]
#[should_panic]
fn func_input_type() {
let build = "
(let ctx (Id 0))
(let f-id (Id 1))
(let f (Function f-id (Add (Arg f-id) (Num f-id 2)) (IntT) (IntT)))
(let c (Call f-id (Boolean ctx true)))
";
let check = format!(
"
{SCHED}
"
);

let _ = crate::run_test(build, &check);
}

#[test]
#[should_panic]
fn func_output_type() {
let build = "
(let ctx (Id 0))
(let f-id (Id 1))
(let f (Function f-id (Add (Arg f-id) (Num f-id 2)) (IntT) (BoolT)))
";
let check = format!(
"
{SCHED}
"
);

let _ = crate::run_test(build, &check);
}

0 comments on commit cb0f149

Please sign in to comment.