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.34.18~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d898864a62bff3781ee038fd7b7d0252af388f0d;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 f0b59b9fc..ea930d585 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -41,6 +41,7 @@ TESTS = \ basic-types/bug686336.vala \ basic-types/bug729907.vala \ basic-types/bug731017.vala \ + basic-types/bug744923.test \ basic-types/bug761307.vala \ basic-types/bug761736.vala \ basic-types/bug771626.test \ 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 589478421..4b9aa6cc7 100644 --- a/vala/valaarraycreationexpression.vala +++ b/vala/valaarraycreationexpression.vala @@ -198,6 +198,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) {