Sfoglia il codice sorgente

arrays inited with string literals are arrays of STRING.

Vladislav Folts 9 anni fa
parent
commit
5251807872

BIN
bin/compiled.zip


+ 2 - 1
src/eberon/EberonContextExpression.ob

@@ -238,7 +238,8 @@ END;
 
 PROCEDURE Array.handleExpression(e: Expression.PType);
 BEGIN
-    type <- e.type();
+    type <- e.type() IS Types.PString ? EberonString.string
+                                      : e.type();
     IF SELF.type = NIL THEN
         IF type IS Types.PStorageType THEN
             SELF.type := type;

+ 2 - 0
test/expected/eberon/init_array.js

@@ -4,6 +4,7 @@ var a1 = [1];
 var a2 = [1, 2];
 var a3 = [true, false];
 var a4 = [1 + 2 | 0, 3];
+var a5 = ["a", "bc", "def"];
 
 function passArray(a/*ARRAY OF INTEGER*/){
 }
@@ -16,4 +17,5 @@ for(var $key2 = 0; $key2 < $seq1.length; ++$key2){
 	var e = $seq1[$key2];
 	RTL$.assert(e != 0);
 }
+RTL$.assert(a5.indexOf("a") == 0);
 }();

+ 3 - 0
test/input/eberon/init_array.ob

@@ -5,6 +5,7 @@ CONST
 	a2 = [1, 2];
 	a3 = [TRUE, FALSE];
 	a4 = [1 + 2, 3];
+	a5 = ["a", "bc", "def"];
 
 PROCEDURE passArray(a: ARRAY OF INTEGER);
 END;
@@ -19,4 +20,6 @@ BEGIN
 	FOR e IN a1 DO
 		ASSERT(e # 0);
 	END;
+
+	ASSERT(a5.indexOf("a") = 0);
 END m.

+ 7 - 0
test/test_unit_eberon.js

@@ -1597,5 +1597,12 @@ exports.suite = {
          ),
     fail(["intVarArray(a)", "constant cannot be passed as VAR actual parameter"],
          ["charArray(a)", "type mismatch for argument 1: 'ARRAY 3 OF INTEGER' cannot be converted to 'ARRAY OF CHAR'"])
+    ),
+"CONST array with string literals": testWithContext(
+    context(grammar.expression,
+            "CONST a = [\"a\", \"bc\", \"d\"];"
+            + "PROCEDURE stringArray(a: ARRAY OF STRING): BOOLEAN; RETURN FALSE; END;"
+            ),
+    pass("stringArray(a)")
     )
 };