[vala/staging] vala: Recognize previously inserted implicit access to with-variable



commit 72a6054150ff3b160eb3664fba1b646d0f1fa572
Author: Nick Schrader <nick schrader mailbox org>
Date:   Sat Sep 26 13:57:13 2020 +0200

    vala: Recognize previously inserted implicit access to with-variable
    
    Replaces b2746b9c3a2edc17ae7d27b30123fe0aeec52f82
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1043

 tests/Makefile.am                                |  3 +++
 tests/objects/with-nested-in-lambda.vala         | 21 ++++++++++++++++
 tests/objects/with-nested-signal.vala            | 32 ++++++++++++++++++++++++
 tests/objects/with-nested-unambigous-signal.vala | 19 ++++++++++++++
 vala/valamemberaccess.vala                       | 13 +++-------
 5 files changed, 79 insertions(+), 9 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5d7cc13ab..817080efe 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -533,7 +533,10 @@ TESTS = \
        objects/with-expression.vala \
        objects/with-instance.vala \
        objects/with-nested.vala \
+       objects/with-nested-in-lambda.vala \
        objects/with-nested-method.vala \
+       objects/with-nested-signal.vala \
+       objects/with-nested-unambigous-signal.vala \
        errors/catch-error-code.vala \
        errors/catch-in-finally.vala \
        errors/default-gtype.vala \
diff --git a/tests/objects/with-nested-in-lambda.vala b/tests/objects/with-nested-in-lambda.vala
new file mode 100644
index 000000000..18a0a582c
--- /dev/null
+++ b/tests/objects/with-nested-in-lambda.vala
@@ -0,0 +1,21 @@
+delegate void FooFunc ();
+
+class Foo {
+       public int bar () {
+               return 23;
+       }
+}
+
+void run (FooFunc func) {
+       func ();
+}
+
+void main () {
+       var foo = new Foo ();
+
+       run (() => {
+               with (foo) {
+                       assert (bar () == 23);
+               }
+       });
+}
diff --git a/tests/objects/with-nested-signal.vala b/tests/objects/with-nested-signal.vala
new file mode 100644
index 000000000..f9e65041e
--- /dev/null
+++ b/tests/objects/with-nested-signal.vala
@@ -0,0 +1,32 @@
+class Foo {
+       public signal void manam ();
+
+       public virtual int foo () {
+               return 23;
+       }
+}
+
+class Bar : Foo {
+       public override int foo () {
+               return 42;
+       }
+}
+
+void main () {
+       var foo = new Foo ();
+       var bar = new Bar ();
+
+       with (foo) {
+               manam.connect (() => {
+                       assert (foo () == 23);
+               });
+               with (bar) {
+                       manam.connect (() => {
+                               assert (foo () == 42);
+                       });
+               }
+       }
+
+       foo.manam ();
+       bar.manam ();
+}
diff --git a/tests/objects/with-nested-unambigous-signal.vala 
b/tests/objects/with-nested-unambigous-signal.vala
new file mode 100644
index 000000000..5fa563b0e
--- /dev/null
+++ b/tests/objects/with-nested-unambigous-signal.vala
@@ -0,0 +1,19 @@
+class Foo {
+       public signal void manam ();
+
+       public int bar () {
+               return 23;
+       }
+}
+
+void main () {
+       var foo = new Foo ();
+
+       with (foo) {
+               manam.connect (() => {
+                       assert (bar () == 23);
+               });
+       }
+
+       foo.manam ();
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 53b167323..b1cc20ada 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -74,6 +74,7 @@ public class Vala.MemberAccess : Expression {
 
        private Expression? _inner;
        private List<DataType> type_argument_list = new ArrayList<DataType> ();
+       bool is_with_variable_access;
 
        /**
         * Creates a new member access expression.
@@ -285,7 +286,7 @@ public class Vala.MemberAccess : Expression {
 
                                symbol_reference = SemanticAnalyzer.symbol_lookup_inherited (sym, 
member_name);
 
-                               if (symbol_reference == null && sym is WithStatement) {
+                               if (!is_with_variable_access && symbol_reference == null && sym is 
WithStatement) {
                                        unowned WithStatement w = (WithStatement) sym;
 
                                        var variable_type = w.with_variable.variable_type;
@@ -297,14 +298,8 @@ public class Vala.MemberAccess : Expression {
                                        symbol_reference = variable_type.get_member (member_name);
                                        if (symbol_reference != null) {
                                                inner = new MemberAccess (null, w.with_variable.name, 
source_reference);
-                                               if (w.with_variable.parent_symbol == w.body) {
-                                                       inner.check (context);
-                                               } else {
-                                                       var old_symbol = context.analyzer.current_symbol;
-                                                       context.analyzer.current_symbol = w.parent_symbol;
-                                                       inner.check (context);
-                                                       context.analyzer.current_symbol = old_symbol;
-                                               }
+                                               ((MemberAccess) inner).is_with_variable_access = true;
+                                               inner.check (context);
                                                may_access_instance_members = true;
                                        }
                                }


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