[vala/0.40] vala: Ownership transfer of inline-allocated array is not allowed



commit 84d3d2b1dd94abd6b7b0a4a48719331c16b1cb56
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Dec 28 18:09:04 2020 +0100

    vala: Ownership transfer of inline-allocated array is not allowed
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/931

 tests/Makefile.am                           | 1 +
 tests/arrays/inline-ownership-transfer.test | 6 ++++++
 vala/valareferencetransferexpression.vala   | 6 ++++++
 3 files changed, 13 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 669dccecb..eaf147097 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -87,6 +87,7 @@ TESTS = \
        arrays/inline-field.test \
        arrays/inline-local-instantiation.test \
        arrays/inline-local-variable.test \
+       arrays/inline-ownership-transfer.test \
        arrays/inline-parameter.test \
        arrays/inline-struct.vala \
        arrays/inline-struct-field.test \
diff --git a/tests/arrays/inline-ownership-transfer.test b/tests/arrays/inline-ownership-transfer.test
new file mode 100644
index 000000000..f274a4516
--- /dev/null
+++ b/tests/arrays/inline-ownership-transfer.test
@@ -0,0 +1,6 @@
+Invalid Code
+
+void main () {
+       string foo[23];
+       var bar = (owned) foo;
+}
diff --git a/vala/valareferencetransferexpression.vala b/vala/valareferencetransferexpression.vala
index f455446bf..4de0f49d1 100644
--- a/vala/valareferencetransferexpression.vala
+++ b/vala/valareferencetransferexpression.vala
@@ -100,6 +100,12 @@ public class Vala.ReferenceTransferExpression : Expression {
                        return false;
                }
 
+               if (inner.value_type is ArrayType && ((ArrayType) inner.value_type).inline_allocated) {
+                       error = true;
+                       Report.error (source_reference, "Ownership of inline-allocated array cannot be 
transferred");
+                       return false;
+               }
+
                var is_owned_delegate = inner.value_type is DelegateType && inner.value_type.value_owned;
                if (!inner.value_type.is_disposable ()
                    && !(inner.value_type is PointerType)


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