Taddeus Kroes hace 12 años
padre
commit
dd6930eb07
Se han modificado 3 ficheros con 9 adiciones y 0 borrados
  1. 5 0
      phases/typecheck.ml
  2. 2 0
      util.ml
  3. 2 0
      util.mli

+ 5 - 0
phases/typecheck.ml

@@ -190,6 +190,11 @@ let rec typecheck node =
         check_dims_match dims (typeof dec) node;
         VarUse (dec, Some dims, Type (basetypeof dec) :: ann)
 
+    (* Array pointers cannot be re-assigned, because array dimension reduction
+     * makes assumptions about dimensions of an array *)
+    | VarLet (dec, None, _, _) when is_array dec ->
+        raise (NodeError (node, "cannot re-assign array pointer"))
+
     (* Assigned values must match variable declaration *)
     | VarLet (dec, None, value, ann) ->
         VarLet (dec, None, check_trav (typeof dec) value, ann)

+ 2 - 0
util.ml

@@ -428,3 +428,5 @@ let mapi f lst =
 
 let is_immediate_const const =
     if args.optimize then List.mem const immediate_consts else false
+
+let is_array node = match typeof node with Array _ -> true | _ -> false

+ 2 - 0
util.mli

@@ -67,3 +67,5 @@ val optmapl : ('a -> 'b) -> 'a list option -> 'b list
 val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list
 
 val is_immediate_const : Types.const -> bool
+
+val is_array : Types.node -> bool