[vala/0.36] codegen: Don't apply address-of operator on literals when casting to array



commit 2d0ff92679200f04ca99e1edfd8e6634595b8c42
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Jan 20 19:23:43 2019 +0100

    codegen: Don't apply address-of operator on literals when casting to array
    
    Regression of 5f316333d6a803e4240b5cccc95a6abd2294137b
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777194

 codegen/valaccodebasemodule.vala | 2 +-
 tests/Makefile.am                | 1 +
 tests/structs/bug777194-2.vala   | 7 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9ea2e2c1b..1041ed89d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7172b31fc..8558fbcd4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 000000000..5caa9e8dd
--- /dev/null
+++ b/tests/structs/bug777194-2.vala
@@ -0,0 +1,7 @@
+[CCode (array_length = false)]
+unowned int[] foo;
+
+void main () {
+       foo = (int[]) 0;
+       assert (foo == null);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]