]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't transfer ownership of local-variable if target-type is unknown
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 17 Aug 2017 06:12:57 +0000 (08:12 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 27 Aug 2017 08:33:37 +0000 (10:33 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=736774

tests/Makefile.am
tests/control-flow/bug736774-1.vala [new file with mode: 0644]
tests/control-flow/bug736774-2.vala [new file with mode: 0644]
vala/valasemanticanalyzer.vala

index 5518b2d120df32a5ee75098f0ae03509495c42ed..6e1b5bff93b6964da025c1f63f33c55b808d1f14 100644 (file)
@@ -87,6 +87,8 @@ TESTS = \
        control-flow/bug661985.vala \
        control-flow/bug665904.vala \
        control-flow/bug691514.vala     \
+       control-flow/bug736774-1.vala \
+       control-flow/bug736774-2.vala \
        enums/enum_only.vala \
        enums/enums.vala \
        enums/flags.vala \
diff --git a/tests/control-flow/bug736774-1.vala b/tests/control-flow/bug736774-1.vala
new file mode 100644 (file)
index 0000000..1fd70a4
--- /dev/null
@@ -0,0 +1,23 @@
+bool success = false;
+
+class Foo : Object {
+       ~Foo() {
+               success = true;
+       }
+}
+
+Foo may_fail () throws Error {
+       return new Foo ();
+}
+
+void func (Foo foo) {
+}
+
+void main() {
+       try {
+               func (may_fail ());
+       } catch {
+       }
+
+       assert (success);
+}
diff --git a/tests/control-flow/bug736774-2.vala b/tests/control-flow/bug736774-2.vala
new file mode 100644 (file)
index 0000000..f54ce5c
--- /dev/null
@@ -0,0 +1,16 @@
+string* keep;
+
+string may_fail () throws GLib.Error {
+       string result = "test";
+       keep = result;
+       return (owned) result;
+}
+
+void main () {
+       try {
+               print (_("%s\n"), may_fail ());
+       } catch {
+       }
+
+       assert (keep != "test");
+}
index 5a83c9b993ec3dc07b04e8b256f623e6f867fbd8..563ce0e459b3aa35b0844d6d4a99b185ce46b38f 100644 (file)
@@ -890,7 +890,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public static Expression create_temp_access (LocalVariable local, DataType? target_type) {
                Expression temp_access = new MemberAccess.simple (local.name, local.source_reference);
 
-               var target_owned = target_type == null || target_type.value_owned;
+               var target_owned = target_type != null && target_type.value_owned;
                if (target_owned && local.variable_type.is_disposable ()) {
                        temp_access = new ReferenceTransferExpression (temp_access, local.source_reference);
                        temp_access.target_type = target_type != null ? target_type.copy () : local.variable_type.copy ();