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



commit 55756eab202130792651738a39d409ce9a699aa5
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 52b1b6669..2456be118 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -333,6 +333,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 5909bf7e8..30355efe4 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", get_full_name ());
+                               }
                                return true;
                        }
                }


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