From 4a25381d631a22979d2b3cc4f919f3a6106fae62 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Sun, 8 Mar 2020 17:54:39 +0100 Subject: [PATCH] vala: Real struct-type without type_id can't be used for GObject property 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 | 1 + tests/objects/property-struct-no-gtype.vala | 14 ++++++++++++++ vala/valasemanticanalyzer.vala | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 tests/objects/property-struct-no-gtype.vala diff --git a/tests/Makefile.am b/tests/Makefile.am index ec74064d5..6c74a3186 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..98a2c9f7d --- /dev/null +++ b/tests/objects/property-struct-no-gtype.vala @@ -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); +} diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 89314c289..f2d2bdd1f 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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; } } -- 2.47.2