瀏覽代碼

Made array type errors more readable

Taddeus Kroes 12 年之前
父節點
當前提交
d46894a67c
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      phases/typecheck.ml

+ 7 - 2
phases/typecheck.ml

@@ -34,13 +34,18 @@ let spec = function
   | ArrayDims (ctype, dims) -> (ctype, List.length dims)
   | ctype                   -> (ctype, 0)
 
+let type2str_error = function
+  | ArrayDims (ctype, dims) ->
+    type2str ctype ^ "[" ^ repeat "," (List.length dims - 1) ^ "]"
+  | ctype ->
+    type2str ctype
+
 let check_type ?(msg="") expected node =
   let got = typeof node in
   if (spec got) <> (spec expected) then begin
     let msg = match msg with
       | "" -> sprintf "type mismatch: expected type %s, got %s"
-              (type2str expected) (type2str got)
-              (*(type2str (spec expected)) (type2str (spec got))*)
+              (type2str_error expected) (type2str_error got)
       | _ -> msg
     in raise (NodeError (node, msg))
   end