[vala] Fix member access for derived generic types



commit 2a02ef9dbaaf496990d3e1f8747e91642ad6d5ee
Author: Jürg Billeter <j bitron ch>
Date:   Sun Mar 21 15:20:16 2010 +0100

    Fix member access for derived generic types
    
    Fixes bug 613486.

 tests/Makefile.am            |    1 +
 tests/objects/bug613486.vala |   12 ++++++++++++
 vala/valamemberaccess.vala   |    6 +++++-
 3 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 992d462..b813e18 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -61,6 +61,7 @@ TESTS = \
 	objects/bug596621.vala \
 	objects/bug597155.vala \
 	objects/bug597161.vala \
+	objects/bug613486.vala \
 	errors/errors.vala \
 	errors/bug567181.vala \
 	errors/bug579101.vala \
diff --git a/tests/objects/bug613486.vala b/tests/objects/bug613486.vala
new file mode 100644
index 0000000..ad08b53
--- /dev/null
+++ b/tests/objects/bug613486.vala
@@ -0,0 +1,12 @@
+class Foo<T> {
+	public void do_foo (T t) {
+	}
+}
+
+class Bar : Foo<int> {
+}
+
+void main () {
+	var b = new Bar ();
+	b.do_foo (42);
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 1b74302..63127c2 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -657,7 +657,11 @@ public class Vala.MemberAccess : Expression {
 				instance_type = pointer_type.base_type;
 			}
 
-			if (instance_type.get_type_arguments ().size == 0) {
+			// instance type might be a subtype of the parent symbol of the member
+			// that subtype might not be generic, so do not report an error in that case
+			var object_type = instance_type as ObjectType;
+			if (object_type != null && object_type.type_symbol.get_type_parameters ().size > 0 &&
+			    instance_type.get_type_arguments ().size == 0) {
 				error = true;
 				Report.error (inner.source_reference, "missing generic type arguments");
 				return false;



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