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



commit 832607b8b5498e43fc280cac57617d6e6ddf79d9
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 b8583d770..9f55a3162 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -111,6 +111,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 a6452df55..e2ae4b3c8 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]