[vala] Fix regression in method calls that throw errors with Value target type



commit db462e6f919da758fbb2f4e7b3cbbf2897ec852b
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jan 28 20:34:47 2014 +0100

    Fix regression in method calls that throw errors with Value target type
    
    Related to bug 723009

 tests/Makefile.am                      |    1 +
 tests/methods/bug723009.vala           |    9 +++++++++
 vala/valaassignment.vala               |    4 ++--
 vala/valamethodcall.vala               |    7 ++++---
 vala/valaobjectcreationexpression.vala |    6 +++---
 5 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f8f882c..9c47ec5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -56,6 +56,7 @@ TESTS = \
        methods/bug653391.vala \
        methods/bug653908.vala \
        methods/bug663210.vala \
+       methods/bug723009.vala \
        methods/generics.vala \
        control-flow/break.vala \
        control-flow/expressions-conditional.vala \
diff --git a/tests/methods/bug723009.vala b/tests/methods/bug723009.vala
new file mode 100644
index 0000000..d148c34
--- /dev/null
+++ b/tests/methods/bug723009.vala
@@ -0,0 +1,9 @@
+public string foo () throws Error {
+       return "foo";
+}
+
+void main () {
+       Value bar;
+       bar = foo ();
+       assert ((string) bar == "foo");
+}
\ No newline at end of file
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index 87281ad..7c8599e 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -175,8 +175,8 @@ public class Vala.Assignment : Expression {
                                var sig = (Signal) ma.symbol_reference;
                                right.target_type = new DelegateType (sig.get_delegate (ma.inner.value_type, 
this));
                        } else {
-                               right.formal_target_type = ma.formal_value_type;
-                               right.target_type = ma.value_type;
+                               right.formal_target_type = ma.formal_value_type.copy ();
+                               right.target_type = ma.value_type.copy ();
                        }
                } else if (left is ElementAccess) {
                        var ea = (ElementAccess) left;
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 44d674e..077131c 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -745,17 +745,17 @@ public class Vala.MethodCall : Expression {
                                // store parent_node as we need to replace the expression in the old parent 
node later on
                                var old_parent_node = parent_node;
 
-                               var local = new LocalVariable (value_type, get_temp_name (), null, 
source_reference);
+                               var local = new LocalVariable (value_type.copy (), get_temp_name (), null, 
source_reference);
                                var decl = new DeclarationStatement (local, source_reference);
 
                                insert_statement (context.analyzer.insert_block, decl);
 
+                               var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
+
                                // don't set initializer earlier as this changes parent_node and 
parent_statement
                                local.initializer = this;
                                decl.check (context);
 
-                               var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
-                               temp_access.check (context);
 
                                // move temp variable to insert block to ensure the
                                // variable is in the same block as the declaration
@@ -765,6 +765,7 @@ public class Vala.MethodCall : Expression {
                                context.analyzer.insert_block.add_local_variable (local);
 
                                old_parent_node.replace_expression (this, temp_access);
+                               temp_access.check (context);
                        }
                }
 
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 2a2cda1..939b8a6 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -413,17 +413,16 @@ public class Vala.ObjectCreationExpression : Expression {
                                // store parent_node as we need to replace the expression in the old parent 
node later on
                                var old_parent_node = parent_node;
 
-                               var local = new LocalVariable (value_type, get_temp_name (), null, 
source_reference);
+                               var local = new LocalVariable (value_type.copy (), get_temp_name (), null, 
source_reference);
                                var decl = new DeclarationStatement (local, source_reference);
 
                                insert_statement (context.analyzer.insert_block, decl);
 
+                               var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
                                // don't set initializer earlier as this changes parent_node and 
parent_statement
                                local.initializer = this;
                                decl.check (context);
 
-                               var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
-                               temp_access.check (context);
 
                                // move temp variable to insert block to ensure the
                                // variable is in the same block as the declaration
@@ -433,6 +432,7 @@ public class Vala.ObjectCreationExpression : Expression {
                                context.analyzer.insert_block.add_local_variable (local);
 
                                old_parent_node.replace_expression (this, temp_access);
+                               temp_access.check (context);
                        }
                }
 


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