]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: The rank of an array-initializer should match the target's rank
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 17 Feb 2018 19:56:30 +0000 (20:56 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 17 Feb 2018 19:56:30 +0000 (20:56 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=744923

tests/Makefile.am
tests/basic-types/bug744923.test [new file with mode: 0644]
vala/valaarraycreationexpression.vala

index ed90923e944feb379764c85486308c2d8d0cfd8a..f7ddab646e7c2d5965e9f5ca21edba0b3fa6a8f4 100644 (file)
@@ -42,6 +42,7 @@ TESTS = \
        basic-types/bug686336.vala \
        basic-types/bug729907.vala \
        basic-types/bug731017.vala \
+       basic-types/bug744923.test \
        basic-types/bug756376.vala \
        basic-types/bug761307.vala \
        basic-types/bug761736.vala \
diff --git a/tests/basic-types/bug744923.test b/tests/basic-types/bug744923.test
new file mode 100644 (file)
index 0000000..7f2b84b
--- /dev/null
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+       int[,] i = {};
+}
index a43315788a116b31a6bedf44010a8f62d12e28a0..3c6fb2a93b7c0796762f16c5be5c1e7361b74501 100644 (file)
@@ -212,6 +212,12 @@ public class Vala.ArrayCreationExpression : Expression {
                        if (ret == -1) {
                                error = true;
                        }
+
+                       if (calc_sizes.size != rank) {
+                               error = true;
+                               var actual_type = new ArrayType (element_type, calc_sizes.size, source_reference);
+                               Report.error (initlist.source_reference, "Expected initializer for `%s' but got `%s'".printf (target_type.to_string (), actual_type.to_string ()));
+                       }
                }
 
                if (sizes.size > 0) {