[vala/staging] vala: Check type arguments in DataType.equals



commit 1a7f75771b9620ec82592f09797b27d0aa4dd5d7
Author: Matthias Berndt <matthias_berndt gmx de>
Date:   Fri Sep 30 10:36:14 2016 +0200

    vala: Check type arguments in DataType.equals
    
    This also reverts "Report internal error for invalid type parameter
    comparison" b0191489cb87d15b7c97bb82af2269de6c80fadb
    
    https://bugzilla.gnome.org/show_bug.cgi?id=641418

 tests/Makefile.am              |    3 +++
 tests/objects/bug641418-1.test |   11 +++++++++++
 tests/objects/bug641418-2.test |   16 ++++++++++++++++
 tests/objects/bug641418-3.test |   16 ++++++++++++++++
 vala/valadatatype.vala         |   11 +++++++++++
 vala/valatypeparameter.vala    |    8 +-------
 6 files changed, 58 insertions(+), 7 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7f46a2b..8fcf079 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -158,6 +158,9 @@ TESTS = \
        objects/bug626038.vala \
        objects/bug628639.vala \
        objects/bug634782.vala \
+       objects/bug641418-1.test \
+       objects/bug641418-2.test \
+       objects/bug641418-3.test \
        objects/bug642809.vala \
        objects/bug643711.vala \
        objects/bug646362.vala \
diff --git a/tests/objects/bug641418-1.test b/tests/objects/bug641418-1.test
new file mode 100644
index 0000000..5d0e8f6
--- /dev/null
+++ b/tests/objects/bug641418-1.test
@@ -0,0 +1,11 @@
+Invalid Code
+
+interface Foo {
+       public abstract GenericArray<string> baz ();
+}
+
+class Bar : Object, Foo {
+       public GenericArray<int> baz () {
+               return null;
+       }
+}
diff --git a/tests/objects/bug641418-2.test b/tests/objects/bug641418-2.test
new file mode 100644
index 0000000..f6da05b
--- /dev/null
+++ b/tests/objects/bug641418-2.test
@@ -0,0 +1,16 @@
+Invalid Code
+
+class Foo<K, V> {
+}
+
+class Bar {
+       public virtual Foo<K, V> f<K, V>() {
+               return null;
+       }
+}
+
+class Baz : Bar {
+       public override Foo<A, B> f<B, A>() {
+               return null;
+       }
+}
diff --git a/tests/objects/bug641418-3.test b/tests/objects/bug641418-3.test
new file mode 100644
index 0000000..6d76de9
--- /dev/null
+++ b/tests/objects/bug641418-3.test
@@ -0,0 +1,16 @@
+Invalid Code
+
+class Foo<A, B> {
+}
+
+class Bar<A> {
+       public virtual Foo<A, B> f<B>() {
+               return f();
+       }
+}
+
+class Baz<A> : Bar<A> {
+       public override Foo<B, A> f<B>() {
+               return f();
+       }
+}
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index 5fe8c7b..f3f9bf9 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -208,6 +208,17 @@ public abstract class Vala.DataType : CodeNode {
                if (type2.floating_reference != floating_reference) {
                        return false;
                }
+
+               var type_args = get_type_arguments ();
+               var type2_args = type2.get_type_arguments ();
+               if (type2_args.size != type_args.size) {
+                       return false;
+               }
+
+               for (int i = 0; i < type_args.size; i++) {
+                       if (!type2_args[i].equals (type_args[i]))
+                               return false;
+               }
        
                return true;
        }
diff --git a/vala/valatypeparameter.vala b/vala/valatypeparameter.vala
index 0fa3bd8..f875f30 100644
--- a/vala/valatypeparameter.vala
+++ b/vala/valatypeparameter.vala
@@ -49,12 +49,6 @@ public class Vala.TypeParameter : Symbol {
         *              otherwise
         */
        public bool equals (TypeParameter param2) {
-               /* only type parameters with the same parent are comparable */
-               if (parent_symbol != param2.parent_symbol) {
-                       Report.error (source_reference, "internal error: comparing type parameters with 
different parents");
-                       return false;
-               }
-
-               return name == param2.name;
+               return name == param2.name && parent_symbol == param2.parent_symbol;
        }
 }


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