Skip to content

Commit

Permalink
Function argument validation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
702fbtngus committed Sep 3, 2024
1 parent ad08514 commit 67c5c35
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spectec/src/al/valid.ml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,40 @@ let check_call source id args result_typ =
| ExpA expr, ExpP (_, typ') -> check_match source expr.note typ'
(* Add local variable typ *)
| TypA typ1, TypP id -> env := Env.bind_var !env id (typ1, [])
| DefA aid, DefP (_, pparams, ptyp) ->
(match Env.find_opt_def !env (aid $ no_region) with
| Some (aparams, atyp, _) ->
if not (Eval.sub_typ !env atyp ptyp) then
error_valid
"argument's return type is not a subtype of parameter's return type"
source
(Printf.sprintf " %s !<: %s"
(Il.Print.string_of_typ atyp)
(Il.Print.string_of_typ ptyp)
);
List.iter2 (fun aparam pparam ->
(* TODO: only supports ExpP for param of arg/param now *)
let typ_of_param param = match param.it with
| ExpP (_, typ) -> typ
| _ ->
error_valid "argument param is not an expression" source
(Il.Print.string_of_param aparam);
in

let aptyp = typ_of_param aparam in
let pptyp = typ_of_param pparam in

if not (Eval.sub_typ !env pptyp aptyp) then
error_valid
"parameter's parameter type is not a subtype of argument's return type"
source
(Printf.sprintf " %s !<: %s"
(Il.Print.string_of_typ pptyp)
(Il.Print.string_of_typ aptyp)
);
) aparams pparams;
| _ -> error_valid "no function definition" source aid
);
| _ ->
error_valid "argument type mismatch" source
(Printf.sprintf " %s =/= %s"
Expand Down

0 comments on commit 67c5c35

Please sign in to comment.