Browse Source

patched forbidden case where an array was used for an array index

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@8204 8c9fc860-2736-0410-a75d-ab315db34111
felixf 7 years ago
parent
commit
d98268c8c9
2 changed files with 15 additions and 1 deletions
  1. 3 1
      source/FoxSemanticChecker.Mod
  2. 12 0
      source/Oberon.Compilation.Test

+ 3 - 1
source/FoxSemanticChecker.Mod

@@ -545,7 +545,9 @@ TYPE
 						IF variableAccessed THEN
 							Error(e.position, "forbidden variable access");
 						END;
-						x.SetLength(e); x.SetForm(SyntaxTree.SemiDynamic);
+						IF CheckSizeType(e) THEN
+							x.SetLength(e); x.SetForm(SyntaxTree.SemiDynamic);
+						END;
 					ELSE
 						x.SetLength(ConstantIntegerGeq0(e (*x.length*)));
 					END;

+ 12 - 0
source/Oberon.Compilation.Test

@@ -39479,3 +39479,15 @@ negative: conversion float to unsigned data type
 	    unsigned8 := UNSIGNED8(real);
 	END Test.
 
+negative: use array of size for array size
+	MODULE Test;
+	CONST Data = [10,20];
+	VAR a: ARRAY LEN(Data) OF LONGINT;
+	END Test.
+
+positive: use array size for array size
+	MODULE Test;
+	CONST Data = [10,20];
+	VAR a: ARRAY LEN(Data,0) OF LONGINT;
+	END Test.
+