[vala/staging] check type arguments in DataType.equals
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] check type arguments in DataType.equals
- Date: Sat, 1 Oct 2016 15:54:21 +0000 (UTC)
commit 18fb02c57ac8a1e24c1db3947f2ec3a4dba69597
Author: Matthias Berndt <matthias_berndt gmx de>
Date: Fri Sep 30 10:36:14 2016 +0200
check type arguments in DataType.equals
https://bugzilla.gnome.org/show_bug.cgi?id=641418
tests/Makefile.am | 3 +++
tests/objects/bug641418-1.test | 13 +++++++++++++
tests/objects/bug641418-2.test | 16 ++++++++++++++++
tests/objects/bug641418-3.test | 16 ++++++++++++++++
vala/valadatatype.vala | 11 +++++++++++
vala/valatypeparameter.vala | 8 +-------
6 files changed, 60 insertions(+), 7 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0fd49d9..0276730 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -156,6 +156,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..579f7fd
--- /dev/null
+++ b/tests/objects/bug641418-1.test
@@ -0,0 +1,13 @@
+Invalid Code
+
+interface Foo
+{
+ public abstract GenericArray<string> baz ();
+}
+
+class Bar : Object, Foo
+{
+ public override 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]