]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Check for unavailable value-type of variable initializer
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 17 Nov 2021 17:46:22 +0000 (18:46 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 18 Nov 2021 19:46:19 +0000 (20:46 +0100)
Regression of 6690ea0e3c6f0d81d849e13548efc8c0809149cc

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

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

index f33c60674dcaa2ac9914135be9e1b8925be33741..789e34de8337d2314df4476842a0a766e96a0c95 100644 (file)
@@ -919,6 +919,7 @@ TESTS = \
        semantic/assignment-same-variable.vala \
        semantic/assignment-signal-incompatible-method.test \
        semantic/assignment-signal-incompatible-type.test \
+       semantic/assignment-invalid-type.test \
        semantic/cast-gvalue-unsupported.test \
        semantic/cast-gvariant-unsupported.test \
        semantic/cast-void-not-allowed.vala \
@@ -1005,6 +1006,7 @@ TESTS = \
        semantic/foreach-next-value-void.test \
        semantic/foreach-next-void.test \
        semantic/foreach-wrong-types.test \
+       semantic/initializer-invalid-type.test \
        semantic/initializer-unknown-type.test \
        semantic/interface-prerequisite-invalid.test \
        semantic/interface-prerequisite-less-accessible.test \
diff --git a/tests/semantic/assignment-invalid-type.test b/tests/semantic/assignment-invalid-type.test
new file mode 100644 (file)
index 0000000..261c52e
--- /dev/null
@@ -0,0 +1,7 @@
+Invalid Code
+
+string bar;
+
+void main () {
+       bar = string;
+}
diff --git a/tests/semantic/initializer-invalid-type.test b/tests/semantic/initializer-invalid-type.test
new file mode 100644 (file)
index 0000000..2f8e91e
--- /dev/null
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+       string foo = string;
+}
index 621e96aac04a5e5c04204b8e72d606791c55b7f0..241ba956816b76c4a8c244b541df31a7f7d02281 100644 (file)
@@ -291,6 +291,10 @@ public class Vala.Assignment : Expression {
                                        Report.error (source_reference, "Assignment: Invalid assignment attempt");
                                        return false;
                                }
+                       } else if (ma.symbol_reference is Variable && right.value_type == null) {
+                               error = true;
+                               Report.error (source_reference, "Assignment: Invalid assignment attempt");
+                               return false;
                        } else if (ma.symbol_reference is Variable) {
                                unowned Variable variable = (Variable) ma.symbol_reference;
                                unowned ArrayType? variable_array_type = variable.variable_type as ArrayType;
index c31e980566e3ae7e3c2cbe1794d93bde881f2978..b08f6f7ee4da0495f1990b7e103e32c522a7a197 100644 (file)
@@ -205,6 +205,10 @@ public class Vala.LocalVariable : Variable {
                                        Report.error (source_reference, "expression type not allowed as initializer");
                                        return false;
                                }
+                       } else if (initializer.value_type == null) {
+                               error = true;
+                               Report.error (source_reference, "expression type not allowed as initializer");
+                               return false;
                        }
 
                        if (!initializer.value_type.compatible (variable_type)) {