]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't pass CCodeCastExpression to NULL-aware free macro
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 5 Apr 2020 20:24:58 +0000 (22:24 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 5 Apr 2020 20:28:49 +0000 (22:28 +0200)
This resulted in invalid C code:
    error: lvalue required as left operand of assignment

Fixes https://gitlab.gnome.org/GNOME/vala/issues/953

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/objects/member-initializer-property.vala [new file with mode: 0644]

index f58985b9e70f652d0ad7a6bb232fb3012aae571b..a921cd755398088be58d7772be6203c7e545ecdb 100644 (file)
@@ -3678,6 +3678,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                cfile.add_type_declaration (new CCodeMacroReplacement.with_expression ("%s(var)".printf (free0_func), macro));
                        }
 
+                       // FIXME this breaks in our macro, so this should not happen
+                       if (cvar is CCodeCastExpression) {
+                               cvar = ((CCodeCastExpression) cvar).inner;
+                       }
+
                        ccall = new CCodeFunctionCall (new CCodeIdentifier (free0_func));
                        ccall.add_argument (cvar);
                        return ccall;
index 88aaac40a69c9b23771353a691d905f51862f101..1d9aa496ae1a1a583bd2a396fb55b83524f2f86b 100644 (file)
@@ -384,6 +384,7 @@ TESTS = \
        objects/interface-property-override.vala \
        objects/interface-virtual-override.vala \
        objects/member-initializer-base-properties.vala \
+       objects/member-initializer-property.vala \
        objects/member-initializer-property-owned-setter.vala \
        objects/methods.vala \
        objects/paramspec.vala \
diff --git a/tests/objects/member-initializer-property.vala b/tests/objects/member-initializer-property.vala
new file mode 100644 (file)
index 0000000..cd71ed0
--- /dev/null
@@ -0,0 +1,15 @@
+class Baz {
+}
+
+class Bar : Baz {
+}
+
+class Foo {
+       public Baz baz { get; set; }
+}
+
+void main() {
+       var foo = new Foo () {
+               baz = new Bar ()
+       };
+}