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



commit f847a8b008b94138cf6a560ca34159ba2ddc10c1
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 89ed181a8..2e77ea30d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5414,7 +5414,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 93cbe1611..144a095da 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -223,6 +223,7 @@ TESTS = \
        structs/bug764041.test \
        structs/bug775761.vala \
        structs/bug777194.vala \
+       structs/bug777194-2.vala \
        delegates/casting.vala \
        delegates/compatible.vala \
        delegates/delegate_only.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]