[vala/staging] vala: Correctly perform compatibility check of array length-type



commit fcc4a9235540c83f573086d573aae2ba03f63360
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Feb 28 09:36:43 2019 +0100

    vala: Correctly perform compatibility check of array length-type
    
    Regression of 36671ae5def89b46384e627a467247c834948254
    
    https://gitlab.gnome.org/GNOME/vala/issues/607

 tests/Makefile.am                               | 1 +
 tests/arrays/incompatible-integer-elements.test | 5 +++++
 vala/valaarraytype.vala                         | 8 ++++----
 3 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 76b93f2c3..7f10b1606 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 000000000..f2bfc93fb
--- /dev/null
+++ b/tests/arrays/incompatible-integer-elements.test
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+       uint8?[] foo = new int?[13];
+}
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index 8265a8027..84522ca4c 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -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;
                }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]