summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--source/mod_student/typechecker.ml17
1 files changed, 14 insertions, 3 deletions
diff --git a/source/mod_student/typechecker.ml b/source/mod_student/typechecker.ml
index d261f1e..eb5c2a4 100644
--- a/source/mod_student/typechecker.ml
+++ b/source/mod_student/typechecker.ml
@@ -72,7 +72,7 @@ module Make() = struct
         check_expression env  TP_Int index;
         begin
           match  infer_expression env expr with
-          | (TP_Array _) as tp -> tp
+          | TP_Array tp -> tp
           | TP_Int   -> ErrorReporter.report_expected_array ~loc ~actual:TP_Int
           | TP_Bool  -> ErrorReporter.report_expected_array ~loc ~actual:TP_Bool
         end
@@ -214,10 +214,21 @@ module Make() = struct
 
     let infer_lvalue env = function
       | LVALUE_Id {id;loc;_} -> 
-        failwith "not yet implemented"
+      begin
+        match TypingEnvironment.lookup id env with
+        | None -> ErrorReporter.report_unknown_identifier ~loc ~id
+        | Some ENVTP_Fn _ -> ErrorReporter.report_identifier_is_not_variable ~loc ~id
+        | Some ENVTP_Var tp ->tp
+      end
 
       | LVALUE_Index {index; sub; loc} ->
-        failwith "not yet implemented"
+        check_expression env TP_Int index;
+        begin
+          match infer_expression env sub with
+            | TP_Int -> ErrorReporter.report_expected_array ~loc ~actual:TP_Int
+            | TP_Bool -> ErrorReporter.report_expected_array ~loc ~actual:TP_Bool
+            | TP_Array tp -> tp
+        end
 
 
     (* --------------------------------------------------- *)