[vala/0.40] vala: Use correct value-type for ArrayCreationExpression used as argument



commit c014d783f0e684a5b7a13a6ec407a91a68523994
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Jun 15 20:18:11 2020 +0200

    vala: Use correct value-type for ArrayCreationExpression used as argument
    
    Copy fixed_length and inline_allocated attributes from formal-target-type.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1009

 tests/Makefile.am                                    |  1 +
 tests/methods/parameter-fixed-array-initializer.vala | 20 ++++++++++++++++++++
 vala/valaarraycreationexpression.vala                |  4 ++++
 3 files changed, 25 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 78b746d99..84517abfa 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -114,6 +114,7 @@ TESTS = \
        methods/closures.vala \
        methods/contains.vala \
        methods/iterator.vala \
+       methods/parameter-fixed-array-initializer.vala \
        methods/parameter-ref-array-resize.vala \
        methods/prepostconditions.vala \
        methods/prepostconditions-captured.vala \
diff --git a/tests/methods/parameter-fixed-array-initializer.vala 
b/tests/methods/parameter-fixed-array-initializer.vala
new file mode 100644
index 000000000..516f1f36b
--- /dev/null
+++ b/tests/methods/parameter-fixed-array-initializer.vala
@@ -0,0 +1,20 @@
+struct Bar {
+       int i;
+       double d;
+}
+
+void foo (int a[3]) {
+       assert (a[2] == 4711);
+}
+
+void bar (Bar b[3]) {
+       assert (b[2].i == 23);
+       assert (b[2].d == 47.11);
+}
+
+void main () {
+       foo ({ 23, 42, 4711 });
+
+       Bar b = { 23, 47.11 };
+       bar ({b, b, b});
+}
diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala
index 965286add..d334a7bab 100644
--- a/vala/valaarraycreationexpression.vala
+++ b/vala/valaarraycreationexpression.vala
@@ -282,6 +282,10 @@ public class Vala.ArrayCreationExpression : Expression {
                }
 
                value_type = new ArrayType (element_type, rank, source_reference);
+               if (formal_target_type is ArrayType) {
+                       ((ArrayType) value_type).fixed_length = ((ArrayType) formal_target_type).fixed_length;
+                       ((ArrayType) value_type).inline_allocated = ((ArrayType) 
formal_target_type).inline_allocated;
+               }
                value_type.value_owned = true;
 
                if (!value_type.check (context)) {


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