]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Correctly perform compatibility check of array length-type
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 28 Feb 2019 08:36:43 +0000 (09:36 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 28 Feb 2019 10:05:28 +0000 (11:05 +0100)
Regression of 36671ae5def89b46384e627a467247c834948254

https://gitlab.gnome.org/GNOME/vala/issues/607

tests/Makefile.am
tests/arrays/incompatible-integer-elements.test [new file with mode: 0644]
vala/valaarraytype.vala

index 76b93f2c34845b5ce99846eec784b6e972d0a528..7f10b16065163c6b576c2b3e509e8c217066ce92 100644 (file)
@@ -70,6 +70,7 @@ TESTS = \
        arrays/class-field-length-cname.vala \
        arrays/field-global-length-cname.vala \
        arrays/struct-field-length-cname.vala \
+       arrays/incompatible-integer-elements.test \
        chainup/base-class-invalid.test \
        chainup/base-enum-invalid.test \
        chainup/base-invalid.test \
diff --git a/tests/arrays/incompatible-integer-elements.test b/tests/arrays/incompatible-integer-elements.test
new file mode 100644 (file)
index 0000000..f2bfc93
--- /dev/null
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+       uint8?[] foo = new int?[13];
+}
index 8265a8027055c1fa4fa30148b57b14bbacf0b069..84522ca4ce47e3ca1cea50711479899d446c306d 100644 (file)
@@ -235,12 +235,12 @@ public class Vala.ArrayType : ReferenceType {
                        return false;
                }
 
-               if (element_type.compatible (target_array_type.element_type)
-                   && target_array_type.element_type.compatible (element_type)) {
-                       return true;
+               if (!length_type.compatible (target_array_type.length_type)) {
+                       return false;
                }
 
-               if (length_type.compatible (target_array_type.length_type)) {
+               if (element_type.compatible (target_array_type.element_type)
+                   && target_array_type.element_type.compatible (element_type)) {
                        return true;
                }