]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Report invalid type in property assignment attempt
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 15 Apr 2024 06:40:05 +0000 (08:40 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 15 Apr 2024 08:29:10 +0000 (10:29 +0200)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1541

tests/Makefile.am
tests/semantic/assignment-invalid-type-2.test [new file with mode: 0644]
vala/valaassignment.vala

index 605a5bed2ca88fdf947ad957ee5896d26e0b6a8f..5bde146b3a4a706734eaf7830663d24a34c09db9 100644 (file)
@@ -1088,6 +1088,7 @@ TESTS = \
        semantic/assignment-signal-incompatible-method.test \
        semantic/assignment-signal-incompatible-type.test \
        semantic/assignment-invalid-type.test \
+       semantic/assignment-invalid-type-2.test \
        semantic/cast-gvalue-unsupported.test \
        semantic/cast-gvariant-unsupported.test \
        semantic/cast-void-not-allowed.test \
diff --git a/tests/semantic/assignment-invalid-type-2.test b/tests/semantic/assignment-invalid-type-2.test
new file mode 100644 (file)
index 0000000..ff9d0a8
--- /dev/null
@@ -0,0 +1,14 @@
+Invalid Code
+
+enum Foo {
+       MANAM;
+}
+
+class Bar : Object {
+       public Foo foo { get; set; }
+}
+
+void main () {
+       var bar = new Bar ();
+       bar.foo = Foo;
+}
index 1213e24d09b691890e6028738869a7a9df2255df..ff552deb81877b244ea419f08008ca7d74648233 100644 (file)
@@ -293,6 +293,11 @@ public class Vala.Assignment : Expression {
                if (ma != null) {
                        if (ma.symbol_reference is Property) {
                                unowned Property prop = (Property) ma.symbol_reference;
+                               if (right.value_type == null) {
+                                       error = true;
+                                       Report.error (source_reference, "Assignment: Invalid assignment attempt");
+                                       return false;
+                               }
 
                                unowned DynamicProperty? dynamic_prop = prop as DynamicProperty;
                                if (dynamic_prop != null) {