]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Assign to temp varable when passing a nullable struct argument
authorLuca Bruno <lucabru@src.gnome.org>
Tue, 16 Aug 2011 20:37:58 +0000 (22:37 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Tue, 16 Aug 2011 21:16:29 +0000 (23:16 +0200)
Assign possible (*expr) to a temp variable to ensure copying the struct.

Fixes bug 656693.

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

index 2a2ee263910a3406d02dc650a06613e09524aeb4..b6e2ce14d0039213a741126459ae574c93dfa072 100644 (file)
@@ -4388,10 +4388,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        // we already use a reference for arguments of ref, out, and nullable parameters
                        if (!(unary != null && (unary.operator == UnaryOperator.OUT || unary.operator == UnaryOperator.REF)) && !type.nullable) {
                                var cunary = cexpr as CCodeUnaryExpression;
-                               if (cunary != null && cunary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
-                                       // *expr => expr
-                                       return cunary.inner;
-                               } else if (cexpr is CCodeIdentifier || cexpr is CCodeMemberAccess) {
+                               if (cexpr is CCodeIdentifier || cexpr is CCodeMemberAccess) {
                                        return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cexpr);
                                } else {
                                        // if cexpr is e.g. a function call, we can't take the address of the expression
index 0beb76f063b8ca0a8fa6ae4ffb0c8f1f81fcf816..d1b1491f9bf6f45976717042c8d2fe842e59f1c7 100644 (file)
@@ -72,6 +72,7 @@ TESTS = \
        structs/bug651441.vala \
        structs/bug654646.vala \
        structs/bug654753.vala \
+       structs/bug656693.vala \
        delegates/delegates.vala \
        delegates/bug539166.vala \
        delegates/bug595610.vala \
diff --git a/tests/structs/bug656693.vala b/tests/structs/bug656693.vala
new file mode 100644 (file)
index 0000000..86d90e5
--- /dev/null
@@ -0,0 +1,13 @@
+struct Foo {
+       int bar;
+}
+
+void baz (Foo foo) {
+       foo.bar = 3;
+}
+
+void main () {
+       Foo? foo = Foo ();
+       baz (foo);
+       assert (foo.bar == 0);
+}