[vala/0.50] vala: Don't allow disposable SimpleType structs



commit 4e20e99e7e74eadbc450e1e41ef64a4e53ebd111
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Jan 27 21:08:09 2021 +0100

    vala: Don't allow disposable SimpleType structs

 tests/Makefile.am                         | 1 +
 tests/structs/simple-type-disposable.test | 9 +++++++++
 vala/valastruct.vala                      | 4 ++++
 3 files changed, 14 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8d50f0120..8fd18f150 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -332,6 +332,7 @@ TESTS = \
        structs/gmutex.vala \
        structs/gvalue.vala \
        structs/gvalue-implicit-comparison.vala \
+       structs/simple-type-disposable.test \
        structs/bug530605.vala \
        structs/bug572091.vala \
        structs/bug583603.vala \
diff --git a/tests/structs/simple-type-disposable.test b/tests/structs/simple-type-disposable.test
new file mode 100644
index 000000000..68f64a98e
--- /dev/null
+++ b/tests/structs/simple-type-disposable.test
@@ -0,0 +1,9 @@
+Invalid Code
+
+[SimpleType]
+struct Foo {
+       public string s;
+}
+
+void main () {
+}
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index 53a952753..e297e48bd 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -457,6 +457,10 @@ public class Vala.Struct : TypeSymbol {
                        if (f.binding == MemberBinding.INSTANCE
                            && f.get_attribute_bool ("CCode", "delegate_target", true)
                            && f.variable_type.is_disposable ()) {
+                               if (is_simple_type ()) {
+                                       error = true;
+                                       Report.error (f.source_reference, "[SimpleType] struct `%s' cannot 
have owned heap-allocated fields".printf (get_full_name ()));
+                               }
                                return true;
                        }
                }


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