]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't apply address-of operator on literals when casting to array
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 20 Jan 2019 18:23:43 +0000 (19:23 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 28 Feb 2019 17:25:40 +0000 (18:25 +0100)
Regression of 5f316333d6a803e4240b5cccc95a6abd2294137b

https://bugzilla.gnome.org/show_bug.cgi?id=777194

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

index 9ea2e2c1b897c421e2226ac4f71b158afe991ad9..1041ed89da56d1ed3bef6514385940792a96caf4 100644 (file)
@@ -5307,7 +5307,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                expr.inner.value_type is ValueType && expr.inner.value_type.nullable) {
                                // nullable integer or float or boolean or struct or enum cast to non-nullable
                                innercexpr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, innercexpr);
-                       } else if (expr.type_reference is ArrayType
+                       } else if (expr.type_reference is ArrayType && !(expr.inner is Literal)
                            && expr.inner.value_type is ValueType && !expr.inner.value_type.nullable) {
                                // integer or float or boolean or struct or enum to array cast
                                innercexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, innercexpr);
index 7172b31fcad8a78388ea818a31394d87aaa8370e..8558fbcd449717019bb24f42fad6377d78189fa2 100644 (file)
@@ -189,6 +189,7 @@ TESTS = \
        structs/bug764041.test \
        structs/bug775761.vala \
        structs/bug777194.vala \
+       structs/bug777194-2.vala \
        delegates/casting.vala \
        delegates/compatible.vala \
        delegates/delegates.vala \
diff --git a/tests/structs/bug777194-2.vala b/tests/structs/bug777194-2.vala
new file mode 100644 (file)
index 0000000..5caa9e8
--- /dev/null
@@ -0,0 +1,7 @@
+[CCode (array_length = false)]
+unowned int[] foo;
+
+void main () {
+       foo = (int[]) 0;
+       assert (foo == null);
+}