[vala] Fix protected member access in interfaces



commit c007777b3b63958929a0d424173d2fe98edeae92
Author: Adam Folmert <afolmert gmail com>
Date:   Fri Feb 12 11:10:33 2010 +0100

    Fix protected member access in interfaces
    
    Fixes bug 609726.

 tests/objects/interfaces.vala |   28 ++++++++++++++++++++++++++--
 vala/valamemberaccess.vala    |    7 +++++++
 2 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/tests/objects/interfaces.vala b/tests/objects/interfaces.vala
index d9fcdb9..e6895d6 100644
--- a/tests/objects/interfaces.vala
+++ b/tests/objects/interfaces.vala
@@ -4,6 +4,21 @@ interface Maman.Ibaz : Object {
 	public abstract void do_action ();
 
 	public abstract void do_virtual_action ();
+
+	protected void protected_mixin_1() {
+		stdout.puts("protected_mixin_1\n");
+		protected_mixin_2();
+	}
+
+	protected void protected_mixin_2() {
+		stdout.puts("protected_mixin_2\n");
+	}
+
+	public void public_mixin() {
+		protected_mixin_1();
+		protected_mixin_2();
+
+	}
 }
 
 class Maman.Baz : Object, Ibaz {
@@ -14,6 +29,10 @@ class Maman.Baz : Object, Ibaz {
 	public virtual void do_virtual_action () {
 		stdout.printf (" 4");
 	}
+
+	public void do_mixin() {
+		public_mixin();
+	}
 }
 
 class Maman.SubBaz : Baz {
@@ -21,11 +40,13 @@ class Maman.SubBaz : Baz {
 		stdout.printf (" 6");
 	}
 
-	public static int main () {
+	public static int main_func () {
 		stdout.printf ("Interface Test: 1");
 
 		Ibaz ibaz = new Baz ();
 		ibaz.do_action ();
+		ibaz.public_mixin();
+		(ibaz as Baz).do_mixin();
 	
 		stdout.printf (" 3");
 
@@ -38,11 +59,14 @@ class Maman.SubBaz : Baz {
 
 		stdout.printf (" 7\n");
 
+		subbaz.public_mixin();
+		(subbaz as Baz).public_mixin();
+
 		return 0;
 	}
 }
 
 void main () {
-	Maman.SubBaz.main ();
+	Maman.SubBaz.main_func ();
 }
 
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 981981e..2914eba 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -637,6 +637,13 @@ public class Vala.MemberAccess : Expression {
 
 			bool in_subtype = false;
 			for (Symbol this_symbol = analyzer.current_symbol; this_symbol != null; this_symbol = this_symbol.parent_symbol) {
+				if (this_symbol == target_type) {
+					// required for interfaces with non-abstract methods
+					// accessing protected interface members
+					in_subtype = true;
+					break;
+				}
+
 				var cl = this_symbol as Class;
 				if (cl != null && cl.is_subtype_of (target_type)) {
 					in_subtype = true;



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