[vala/0.48] vala: Don't allow nullable enum value as real GObject property



commit 1d37bad7f2047e855591a81b853eba66b3f1869f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Mar 29 16:33:55 2022 +0200

    vala: Don't allow nullable enum value as real GObject property
    
    It is basically a boxed integer value.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1074

 tests/Makefile.am                         |  1 +
 tests/objects/property-enum-nullable.vala | 10 ++++++++++
 vala/valasemanticanalyzer.vala            |  4 ++++
 3 files changed, 15 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b282f1e2d..97c3883ea 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -523,6 +523,7 @@ TESTS = \
        objects/property-construct-only-write-foreign.test \
        objects/property-delegate.vala \
        objects/property-delegate-owned.vala \
+       objects/property-enum-nullable.vala \
        objects/property-gboxed-nullable.vala \
        objects/property-real-struct-assignment.vala \
        objects/property-real-struct-no-accessor.test \
diff --git a/tests/objects/property-enum-nullable.vala b/tests/objects/property-enum-nullable.vala
new file mode 100644
index 000000000..e7206e060
--- /dev/null
+++ b/tests/objects/property-enum-nullable.vala
@@ -0,0 +1,10 @@
+enum Bar {
+       Manam;
+}
+
+class Foo : Object {
+       public Bar? bar { owned get; set; }
+}
+
+void main () {
+}
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index 8b701da7f..23f6329dd 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -499,6 +499,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        }
                }
 
+               if (property_type is EnumValueType) {
+                       return !property_type.nullable;
+               }
+
                if (property_type is ArrayType && ((ArrayType) property_type).element_type.type_symbol != 
string_type.type_symbol) {
                        return false;
                }


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