[vala/bug736774: 3/3] Fix regression introduced by ba1fa07
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/bug736774: 3/3] Fix regression introduced by ba1fa07
- Date: Thu, 18 Sep 2014 21:17:05 +0000 (UTC)
commit e8915408926541584c77a1b914327664b80f0372
Author: Luca Bruno <lucabru src gnome org>
Date: Thu Sep 18 23:06:09 2014 +0200
Fix regression introduced by ba1fa07
Hope this is the last time we touch this code.
In the owned->unowned case, we want the variable to be floating:
- If we assign to a local variable we get an error.
- Otherwise the value is destroyed when goes out of scope.
In the owned->owned case, we want to avoid copies and thus
we transfer the ownership and make the variable non-floating.
Fixes bug 736774
tests/Makefile.am | 1 +
tests/control-flow/bug736774.vala | 23 +++++++++++++++++++++++
vala/valabinaryexpression.vala | 4 +++-
vala/valamethodcall.vala | 1 +
vala/valaobjectcreationexpression.vala | 2 +-
vala/valasemanticanalyzer.vala | 1 +
6 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 85ca6b3..b8904c3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -75,6 +75,7 @@ TESTS = \
control-flow/bug661985.vala \
control-flow/bug665904.vala \
control-flow/bug691514.vala \
+ control-flow/bug736774.vala \
enums/enums.vala \
enums/flags.vala \
enums/bug673879.vala \
diff --git a/tests/control-flow/bug736774.vala b/tests/control-flow/bug736774.vala
new file mode 100644
index 0000000..34064bd
--- /dev/null
+++ b/tests/control-flow/bug736774.vala
@@ -0,0 +1,23 @@
+bool destroyed = false;
+
+class Foo : Object {
+ ~Foo() {
+ destroyed = true;
+ }
+}
+
+Foo may_fail () throws Error {
+ return new Foo ();
+}
+
+void func (Foo x) {
+}
+
+void main() {
+ try {
+ func (may_fail ());
+ } catch {
+ }
+
+ assert (destroyed);
+}
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 965d4d9..c254f70 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -233,6 +233,9 @@ public class Vala.BinaryExpression : Expression {
insert_statement (context.analyzer.insert_block, decl);
insert_statement (context.analyzer.insert_block, if_stmt);
+ // create before check as local.floating might become false
+ var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
+
if (!decl.check (context)) {
error = true;
return false;
@@ -243,7 +246,6 @@ public class Vala.BinaryExpression : Expression {
return false;
}
- var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
temp_access.check (context);
parent_node.replace_expression (this, temp_access);
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 1707880..b3f713d 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -638,6 +638,7 @@ public class Vala.MethodCall : Expression {
insert_statement (context.analyzer.insert_block, decl);
+ // create before check as local.floating might become false
var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
// don't set initializer earlier as this changes parent_node and
parent_statement
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index b882cb8..b9f4bed 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -435,12 +435,12 @@ public class Vala.ObjectCreationExpression : Expression {
insert_statement (context.analyzer.insert_block, decl);
+ // create before check as local.floating might become false
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);
-
// move temp variable to insert block to ensure the
// variable is in the same block as the declaration
// otherwise there will be scoping issues in the generated code
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index 91f2769..f1d3672 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -897,6 +897,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
temp_access = new ReferenceTransferExpression (temp_access, local.source_reference);
temp_access.target_type = target_type != null ? target_type.copy () :
local.variable_type.copy ();
temp_access.target_type.value_owned = true;
+ local.floating = false;
} else {
temp_access.target_type = target_type != null ? target_type.copy () : null;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]