]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Use correct value-type for ArrayCreationExpression used as argument
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 15 Jun 2020 18:18:11 +0000 (20:18 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 15 Jun 2020 18:18:35 +0000 (20:18 +0200)
Copy fixed_length and inline_allocated attributes from formal-target-type.

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

tests/Makefile.am
tests/methods/parameter-fixed-array-initializer.vala [new file with mode: 0644]
vala/valaarraycreationexpression.vala

index c871a48667d6785d2fa415a613a07d358babfd48..cb930e132e41f8d4fcdff64b393d96b82240712c 100644 (file)
@@ -129,6 +129,7 @@ TESTS = \
        methods/contains.vala \
        methods/extern.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 (file)
index 0000000..516f1f3
--- /dev/null
@@ -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});
+}
index 63037528173deb21aacd65c9dd1194e91a52c166..58a2135ad4b3c585caab4f72d866e6d375a9f10d 100644 (file)
@@ -325,6 +325,10 @@ public class Vala.ArrayCreationExpression : Expression {
 
                value_type = new ArrayType (element_type, rank, source_reference);
                ((ArrayType) value_type).length_type = length_type.copy ();
+               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)) {