From: Rico Tzschichholz Date: Sat, 17 Feb 2018 19:56:30 +0000 (+0100) Subject: vala: The rank of an array-initializer should match the target's rank X-Git-Tag: 0.39.92~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30caeacecf9798d40f26f6e1cd13610615324e36;p=thirdparty%2Fvala.git vala: The rank of an array-initializer should match the target's rank https://bugzilla.gnome.org/show_bug.cgi?id=744923 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index ed90923e9..f7ddab646 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..7f2b84b9d --- /dev/null +++ b/tests/basic-types/bug744923.test @@ -0,0 +1,5 @@ +Invalid Code + +void main () { + int[,] i = {}; +} diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala index a43315788..3c6fb2a93 100644 --- a/vala/valaarraycreationexpression.vala +++ b/vala/valaarraycreationexpression.vala @@ -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) {