[vala] Fix checking access to async callback for base methods



commit 9ee54bf41b8cf4ea29bb673e75557014a5f83d9f
Author: Luca Bruno <lucabru src gnome org>
Date:   Fri Apr 22 19:28:42 2011 +0200

    Fix checking access to async callback for base methods
    
    Fixes regression introduced by 474611603ae6df7792f4dc2f107.

 tests/Makefile.am                 |    1 +
 tests/asynchronous/bug646945.vala |   20 ++++++++++++++++++++
 vala/valamemberaccess.vala        |   12 +++++++++++-
 3 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c3c90d3..d5f979d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -95,6 +95,7 @@ TESTS = \
 	asynchronous/bug613484.vala \
 	asynchronous/bug620740.vala \
 	asynchronous/bug639591.vala \
+	asynchronous/bug646945.vala \
 	asynchronous/closures.vala \
 	dbus/basic-types.test \
 	dbus/arrays.test \
diff --git a/tests/asynchronous/bug646945.vala b/tests/asynchronous/bug646945.vala
new file mode 100644
index 0000000..ad17d48
--- /dev/null
+++ b/tests/asynchronous/bug646945.vala
@@ -0,0 +1,20 @@
+class Foo : Object {
+	public virtual async void method1 () { }
+}
+
+interface Bar : Object {
+	public virtual async void method2 () { }
+}
+
+class Baz : Foo, Bar {
+	public override async void method1 () {
+		method1.callback ();
+	}
+
+	public async void method2 () {
+		method2.callback ();
+	}
+}
+
+void main () {
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 26894ea..d7f66cd 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -539,7 +539,17 @@ public class Vala.MemberAccess : Expression {
 				// and also for lambda expressions within async methods
 				var async_method = context.analyzer.current_async_method;
 
-				if (async_method == null || m != async_method.get_callback_method ()) {
+				bool is_valid_access = false;
+				if (async_method != null) {
+					if (m == async_method.get_callback_method ()) {
+						is_valid_access = true;
+					} else if (async_method.base_method != null && m == async_method.base_method.get_callback_method ()) {
+						is_valid_access = true;
+					} else if (async_method.base_interface_method != null && m == async_method.base_interface_method.get_callback_method ()) {
+						is_valid_access = true;
+					}
+				}
+				if (!is_valid_access) {
 					error = true;
 					Report.error (source_reference, "Access to async callback `%s' not allowed in this context".printf (m.get_full_name ()));
 					return false;



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