]> 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>
Mon, 20 Apr 2020 19:30:29 +0000 (21:30 +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 5e13088589b0c5cf81768a9582267fa269826351..3a07377f39fc23bf7712e8574bb17c46a21ac48e 100644 (file)
@@ -3620,6 +3620,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 bf88efc4113ac0225ec893c0ea0f9259ed61c8a1..f96352d757960592808e850478cd6e342904df26 100644 (file)
@@ -368,6 +368,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 ()
+       };
+}