]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't free temp-var for element-access to array with boxed structs
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 11 Apr 2021 16:05:08 +0000 (18:05 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 11 Apr 2021 16:05:38 +0000 (18:05 +0200)
Check the symbol_reference of inner element-access as needed.

Regression of 63551acaf0d83fac8b50904c2759c1098fbfaa71

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

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/arrays/cast-struct-boxed-element-access.vala [new file with mode: 0644]

index fc25b327f5f4639013ecda002eea8839afd25614..4ea6794c47427fb42e3520de7baeff69d8e5ad4d 100644 (file)
@@ -5477,6 +5477,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        while (inner_expr is CastExpression) {
                                inner_expr = ((CastExpression) inner_expr).inner;
                        }
+                       if (inner_expr is ElementAccess) {
+                               inner_expr = ((ElementAccess) inner_expr).container;
+                       }
                        if (!(inner_expr.symbol_reference is Variable)) {
                                // heap allocated struct leaked, destroy it
                                var value = new GLibValue (new PointerType (new VoidType ()), innercexpr);
index a802bc8fba0ee335963c18500c4bfe851783a549..346c67e2d268565134ad633855e719efad475bda 100644 (file)
@@ -100,6 +100,7 @@ TESTS = \
        constants/strings.vala \
        namespace/unique.vala \
        arrays/cast-silent-invalid.test \
+       arrays/cast-struct-boxed-element-access.vala \
        arrays/class-field-initializer.vala \
        arrays/class-field-length-cname.vala \
        arrays/constant-element-access.vala \
diff --git a/tests/arrays/cast-struct-boxed-element-access.vala b/tests/arrays/cast-struct-boxed-element-access.vala
new file mode 100644 (file)
index 0000000..356ecbd
--- /dev/null
@@ -0,0 +1,22 @@
+struct Foo {
+       public int i;
+}
+
+void main () {
+       var foo = new Foo?[] { { 23 },  { 42 },  { 4711 } };
+       {
+               Foo f = foo[0];
+               assert (f.i == 23);
+               assert (foo[0].i == 23);
+       }
+       {
+               Foo f = (Foo) foo[1];
+               assert (f.i == 42);
+               assert (foo[1].i == 42);
+       }
+       {
+               Foo f = (!) foo[2];
+               assert (f.i == 4711);
+               assert (foo[2].i == 4711);
+       }
+}