summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-11-25 03:48:32 +0100
committerPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-11-25 03:48:32 +0100
commit84654a0f57677bf76795f892a6896ca36554dca3 (patch)
tree9b8be55950ed98e8d50c6f9bf3e91bb4ecdef3b8
parentBetter rules for arrays (diff)
MultiVarDecl
-rw-r--r--source/mod_student/typechecker.ml22
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