]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't create temp var in transform_value if lvalue isn't allowed
authorLuca Bruno <lucabru@src.gnome.org>
Mon, 17 Oct 2011 19:56:49 +0000 (21:56 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Mon, 17 Oct 2011 20:04:37 +0000 (22:04 +0200)
Fixes bug 657378.

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/structs/bug657378.vala [new file with mode: 0644]

index b4c5efdd4ca48ca47a8b603e1b721d01f9180b40..df7af485e88dfa873174419b57599a0995263147 100644 (file)
@@ -5102,8 +5102,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        public TargetValue transform_value (TargetValue value, DataType? target_type, CodeNode node) {
                var type = value.value_type;
                var result = ((GLibValue) value).copy ();
-               result.value_type = target_type != null ? target_type : type;
-               result.value_type = result.value_type.copy ();
                var requires_temp_value = false;
 
                if (type.value_owned
@@ -5150,11 +5148,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        if (target_type is PointerType) {
                                // manual memory management for pointers
                        } else if (requires_destroy (type)) {
-                               var temp_value = create_temp_value (type, false, node);
-                               temp_ref_values.insert (0, ((GLibValue) temp_value).copy ());
-                               store_value (temp_value, result);
-                               result.cvalue = get_cvalue_ (temp_value);
-                               requires_temp_value = false;
+                               if (!is_lvalue_access_allowed (type)) {
+                                       // cannot assign to a temporary variable
+                                       temp_ref_values.insert (0, result.copy ());
+                               } else {
+                                       var temp_value = create_temp_value (type, false, node);
+                                       temp_ref_values.insert (0, ((GLibValue) temp_value).copy ());
+                                       store_value (temp_value, result);
+                                       result.cvalue = get_cvalue_ (temp_value);
+                                       requires_temp_value = false;
+                               }
                        }
                }
 
@@ -5163,6 +5166,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        return result;
                }
 
+               result.value_type = target_type.copy ();
+
                if (gvalue_boxing) {
                        // implicit conversion to GValue
                        var temp_value = create_temp_value (target_type, true, node, true);
index 2a896bd2e961bde269b226c403a958e196e535dd..682b1281018cbdd87c4a121f2b0a4a75d326dea8 100644 (file)
@@ -74,6 +74,7 @@ TESTS = \
        structs/bug654646.vala \
        structs/bug654753.vala \
        structs/bug656693.vala \
+       structs/bug657378.vala \
        structs/bug658048.vala \
        structs/bug660426.vala \
        structs/bug661945.vala \
diff --git a/tests/structs/bug657378.vala b/tests/structs/bug657378.vala
new file mode 100644 (file)
index 0000000..5ba8263
--- /dev/null
@@ -0,0 +1,7 @@
+string foo (string format, ...) {
+       return format.vprintf (va_list ());
+}
+
+void main () {
+       assert (foo ("%s", "foo") == "foo");
+}