فهرست منبع

Fixed buf that caused fundec calls and conditional expressions not to be typechecked correctly

Taddeus Kroes 12 سال پیش
والد
کامیت
153ac60c5d
1فایلهای تغییر یافته به همراه9 افزوده شده و 3 حذف شده
  1. 9 3
      phases/typecheck.ml

+ 9 - 3
phases/typecheck.ml

@@ -67,7 +67,10 @@ let check_dims_match dims dec_type errnode =
     | _ -> ()
 
 let rec typecheck node = match node with
-    | FunUse (FunCall (_, args, _), FunDef (_, ftype, name, params, _, _), _) ->
+    | FunUse (FunCall (fname, args, floc),
+                (FunDec (ftype, name, params, _) as dec), loc)
+    | FunUse (FunCall (fname, args, floc),
+                (FunDef (_, ftype, name, params, _, _) as dec), loc) ->
         (match (list_size args, list_size params) with
         | (nargs, nparams) when nargs != nparams ->
             let msg = sprintf
@@ -76,11 +79,12 @@ let rec typecheck node = match node with
             in
             raise (NodeError (node, msg))
         | _ ->
+            let args = List.map typecheck args in
             let check_arg_type arg param =
-                check_type (ctypeof param) (typecheck arg);
+                check_type (ctypeof param) arg;
             in
             List.iter2 check_arg_type args params;
-            Type (node, ftype)
+            Type (FunUse (FunCall (fname, args, floc), dec, loc), ftype)
         )
 
     | Arg (Type (_, vtype)) -> Type (node, vtype)
@@ -104,6 +108,8 @@ let rec typecheck node = match node with
     | Cond (Type (cond, condtype), Type (texpr, ttype), fexpr, loc) ->
         check_type ttype fexpr;
         Type (node, ttype)
+    | Cond (cond, texpr, fexpr, loc) ->
+        typecheck (Cond (typecheck cond, typecheck texpr, typecheck fexpr, loc))
 
     | VarLet (Assign (_, None, (Type _ as value), _), dec_type, depth) ->
         check_type dec_type value;