diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/mod_student/typechecker.ml | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/source/mod_student/typechecker.ml b/source/mod_student/typechecker.ml index b12bc67..d261f1e 100644 --- a/source/mod_student/typechecker.ml +++ b/source/mod_student/typechecker.ml @@ -230,9 +230,25 @@ module Make() = struct check_expression env lhs_tp rhs; env, RT_Unit - | STMT_MultiVarDecl {vars; init; _} -> - - failwith "not yet implemented" + | STMT_MultiVarDecl {vars; init; loc} -> + begin + let ret_types=check_function_args env init in + let expected = List.length ret_types in + let actual = List.length vars in + match init with Call {loc;callee;_} -> + if expected!=actual then ErrorReporter.report_expected_function_returning_many_values ~loc ~id:callee ~expected ~actual else + begin + let rec aux vars types bindings= match vars,types with + | [] , [] -> bindings + | None::vars , t::types -> aux vars types bindings + | (Some (VarDecl{tp;loc;id} as v) )::vars, t::types -> + let expected =te2type tp in + if expected==t then aux vars types (v::bindings) + else ErrorReporter.report_binding_type_mismatch ~loc ~expected ~id ~actual:t + | _ -> failwith "Should not happen" + in (List.fold_left add_var_decl env (aux vars ret_types [])),RT_Unit + end + end | STMT_Block body -> check_statement_block env body |