[vala/0.40] vala: Keep formal_target_type when transforming method-call/object-creation



commit 3e0acab1341110b400c8892fca3a0f8510bd1102
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Nov 19 09:11:39 2019 +0100

    vala: Keep formal_target_type when transforming method-call/object-creation
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/835

 tests/Makefile.am                               |  1 +
 tests/generics/inference-argument-may-fail.vala | 20 ++++++++++++++++++++
 vala/valamethodcall.vala                        |  2 ++
 vala/valaobjectcreationexpression.vala          |  3 +++
 4 files changed, 26 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f8d6004ca..daa99adee 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -444,6 +444,7 @@ TESTS = \
        asynchronous/yield.vala \
        generics/arrays-not-supported.test \
        generics/constructor-chain-up.vala \
+       generics/inference-argument-may-fail.vala \
        generics/inference-static-function.vala \
        generics/parameter-sizeof-initializer.vala \
        generics/type-parameter-properties.vala \
diff --git a/tests/generics/inference-argument-may-fail.vala b/tests/generics/inference-argument-may-fail.vala
new file mode 100644
index 000000000..b99b97153
--- /dev/null
+++ b/tests/generics/inference-argument-may-fail.vala
@@ -0,0 +1,20 @@
+class Foo<G> {
+       public Foo () throws Error {
+       }
+}
+
+Foo<string>? foo () throws Error {
+       return null;
+}
+
+G bar<G> (Foo<G>? foo) {
+       return null;
+}
+
+void main () {
+       try {
+               bar (foo ());
+               bar (new Foo<string> ());
+       } catch {
+       }
+}
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 1756dd3dd..0e7b13b9f 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -643,6 +643,7 @@ public class Vala.MethodCall : Expression {
                        }
                }
 
+               // FIXME code duplication in ObjectCreationExpression.check
                if (may_throw) {
                        if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
                                // simple statements, no side effects after method call
@@ -659,6 +660,7 @@ public class Vala.MethodCall : Expression {
                                insert_statement (context.analyzer.insert_block, decl);
 
                                var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
+                               temp_access.formal_target_type = formal_target_type;
 
                                // don't set initializer earlier as this changes parent_node and 
parent_statement
                                local.initializer = this;
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index a54291925..21dc7c455 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -507,6 +507,7 @@ public class Vala.ObjectCreationExpression : Expression {
                        context.analyzer.visit_member_initializer (init, type_reference);
                }
 
+               // FIXME code duplication in MethodCall.check
                if (may_throw) {
                        if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
                                // simple statements, no side effects after method call
@@ -523,6 +524,8 @@ public class Vala.ObjectCreationExpression : Expression {
                                insert_statement (context.analyzer.insert_block, decl);
 
                                var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
+                               temp_access.formal_target_type = formal_target_type;
+
                                // don't set initializer earlier as this changes parent_node and 
parent_statement
                                local.initializer = this;
                                decl.check (context);


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