]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Accept enum-values as length for inline allocated arrays bc8bf47d67d1056522f5e65c188e542b94a95449
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 14 Mar 2020 14:15:51 +0000 (15:15 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 14 Mar 2020 14:24:44 +0000 (15:24 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/935

tests/Makefile.am
tests/arrays/fixed-length-enum-value.vala [new file with mode: 0644]
vala/valaarraytype.vala

index dd3cb46f9bb32e3808296659e785d034cfde3ac2..893392b94ace3e8f91bcdaed73ae1ef075eeec17 100644 (file)
@@ -79,6 +79,7 @@ TESTS = \
        arrays/fixed-length-init0-not-allowed.vala \
        arrays/field-global-length-cname.vala \
        arrays/fixed-length-concat-invalid.test \
+       arrays/fixed-length-enum-value.vala \
        arrays/fixed-length-non-const.test \
        arrays/fixed-length-resize-invalid.test \
        arrays/inline-field.test \
diff --git a/tests/arrays/fixed-length-enum-value.vala b/tests/arrays/fixed-length-enum-value.vala
new file mode 100644 (file)
index 0000000..c195eb1
--- /dev/null
@@ -0,0 +1,19 @@
+enum Foo {
+       BAR = 23;
+}
+
+struct Bar {
+       public char array[Foo.BAR];
+}
+
+void foo (uint array[Foo.BAR]) {
+       assert (array.length == 23);
+}
+
+void main () {
+       int array[Foo.BAR];
+       assert (array.length == 23);
+
+       var bar = Bar ();
+       assert (bar.array.length == 23);
+}
index bb6dceb4465a9db87fcab092420512e759eca37d..9add1d0d4d03dd61bfd46300c983dd0672e27931 100644 (file)
@@ -289,7 +289,8 @@ public class Vala.ArrayType : ReferenceType {
                if (fixed_length && length != null) {
                        length.check (context);
 
-                       if (length.value_type == null || !(length.value_type is IntegerType) || !length.is_constant ()) {
+                       if (length.value_type == null || !(length.value_type is IntegerType || length.value_type is EnumValueType)
+                           || !length.is_constant ()) {
                                error = true;
                                Report.error (length.source_reference, "Expression of constant integer type expected");
                                return false;