]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Real struct-type without type_id can't be used for GObject property 4a25381d631a22979d2b3cc4f919f3a6106fae62
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 8 Mar 2020 16:54:39 +0000 (17:54 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 8 Mar 2020 16:54:39 +0000 (17:54 +0100)
It caused an invalid usage of G_TYPE_POINTER with g_param_spec_boxed().

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

tests/Makefile.am
tests/objects/property-struct-no-gtype.vala [new file with mode: 0644]
vala/valasemanticanalyzer.vala

index ec74064d58e6c70df1fc5ff298f90cfaa061f658..6c74a3186b2b8eae47f6093e5a2f338c7069800c 100644 (file)
@@ -387,6 +387,7 @@ TESTS = \
        objects/property-real-struct-no-accessor.test \
        objects/property-simple-type-struct-nullable.vala \
        objects/property-static.vala \
+       objects/property-struct-no-gtype.vala \
        objects/regex.vala \
        objects/sealed-abstract-class.test \
        objects/sealed-class.test \
diff --git a/tests/objects/property-struct-no-gtype.vala b/tests/objects/property-struct-no-gtype.vala
new file mode 100644 (file)
index 0000000..98a2c9f
--- /dev/null
@@ -0,0 +1,14 @@
+[CCode (has_type_id = false)]
+struct Bar {
+       public int i;
+}
+
+class Foo : Object {
+       public Bar bar { get; set; }
+}
+
+void main () {
+       var foo = new Foo ();
+       foo.bar = { 23 };
+       assert (foo.bar.i == 23);
+}
index 89314c2896ba17d0306951b3aa79e84d69898506..f2d2bdd1f71c5f063d950ecda600a6bb8f65eac1 100644 (file)
@@ -491,6 +491,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                // Allow GType-based struct types
                        } else if (property_type.nullable) {
                                return false;
+                       } else if (!st.get_attribute_bool ("CCode", "has_type_id", true)) {
+                               return false;
                        }
                }