summaryrefslogtreecommitdiff
path: root/vala
diff options
context:
space:
mode:
authorLuca Bruno <lucabru@src.gnome.org>2014-01-26 15:49:18 +0100
committerLuca Bruno <lucabru@src.gnome.org>2014-01-26 15:49:48 +0100
commit19184595677fdd08acf35c32ff78a3d97faf3ab2 (patch)
tree2eeb581e13bfe5da4db12593419495147351ee70 /vala
parentcee269cd25fb753d63586d718468f237160621c5 (diff)
downloadvala-19184595677fdd08acf35c32ff78a3d97faf3ab2.tar.gz
Avoid unnecessary copies when using the coalescing operator
Fixes bug 661985
Diffstat (limited to 'vala')
-rw-r--r--vala/valabinaryexpression.vala22
1 files changed, 9 insertions, 13 deletions
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 19766e12f..9c1ef4c98 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -194,7 +194,12 @@ public class Vala.BinaryExpression : Expression {
}
if (operator == BinaryOperator.COALESCE) {
- var local = new LocalVariable (null, get_temp_name (), left, source_reference);
+ if (!left.check (context)) {
+ error = true;
+ return false;
+ }
+
+ var local = new LocalVariable (left.value_type != null ? left.value_type.copy () : null, get_temp_name (), left, source_reference);
var decl = new DeclarationStatement (local, source_reference);
var right_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple (local.name, right.source_reference), right, AssignmentOperator.SIMPLE, right.source_reference), right.source_reference);
@@ -220,19 +225,10 @@ public class Vala.BinaryExpression : Expression {
return false;
}
- var ma = new MemberAccess.simple (local.name, source_reference);
- Expression replace = ma;
-
- if (target_type == null) {
- replace = new ReferenceTransferExpression (replace, source_reference);
- replace.target_type = local.variable_type.copy ();
- replace.target_type.value_owned = true;
- } else {
- replace.target_type = target_type.copy ();
- }
- replace.check (context);
+ var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
+ temp_access.check (context);
- parent_node.replace_expression (this, replace);
+ parent_node.replace_expression (this, temp_access);
return true;
}