]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Recognize previously inserted implicit access to with-variable
authorNick Schrader <nick.schrader@mailbox.org>
Sat, 26 Sep 2020 11:57:13 +0000 (13:57 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 27 Sep 2020 06:48:27 +0000 (08:48 +0200)
Replaces b2746b9c3a2edc17ae7d27b30123fe0aeec52f82

Fixes https://gitlab.gnome.org/GNOME/vala/issues/1043

tests/Makefile.am
tests/objects/with-nested-in-lambda.vala [new file with mode: 0644]
tests/objects/with-nested-signal.vala [new file with mode: 0644]
tests/objects/with-nested-unambigous-signal.vala [new file with mode: 0644]
vala/valamemberaccess.vala

index 5d7cc13ab7aab0ae0531ddfb3482319eaf3f7b4a..817080efed55fe615718149a37722a46a1893f3f 100644 (file)
@@ -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 (file)
index 0000000..18a0a58
--- /dev/null
@@ -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 (file)
index 0000000..f9e6504
--- /dev/null
@@ -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 (file)
index 0000000..5fa563b
--- /dev/null
@@ -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 ();
+}
index 53b167323563a05765e71944cd99fb8480db5c45..b1cc20ada6533f101918adc6c3314026208e8964 100644 (file)
@@ -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;
                                        }
                                }