فهرست منبع

Imported array pointers may not be used directly, added an error message for this

Taddeus Kroes 12 سال پیش
والد
کامیت
7b56ec4f65
2فایلهای تغییر یافته به همراه14 افزوده شده و 0 حذف شده
  1. 6 0
      phases/typecheck.ml
  2. 8 0
      test/arrays/check_error/extern_array_arg.cvc

+ 6 - 0
phases/typecheck.ml

@@ -212,6 +212,12 @@ let rec typecheck node =
   | Const (FloatVal value, ann) ->
     Const (FloatVal value, Type Float :: ann)
 
+  (* Extern arrays variables are transformed to imported functions, so the
+   * pointer cannot be passed *)
+  | VarUse (GlobalDec (ArrayDims _, _, _), None, _) ->
+    raise (NodeError (node, "imported array pointers may only be \
+                             dereferenced, not used directly"))
+
   (* Variables inherit the type of their declaration *)
   | VarUse (dec, None, ann) ->
     VarUse (dec, None, Type (typeof dec) :: ann)

+ 8 - 0
test/arrays/check_error/extern_array_arg.cvc

@@ -0,0 +1,8 @@
+extern int[n] arr;
+
+void foo(int[m] a) {}
+
+export int main() {
+    foo(arr);
+    return 0;
+}