]> 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>
Wed, 17 Nov 2021 17:46:22 +0000 (18: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 b7a40d46c5ffa9374727b1632b64e793a8ea0f06..84af6bef1da85baf306592ec40610cf441bf00ed 100644 (file)
@@ -981,6 +981,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.test \
@@ -1073,6 +1074,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 46f9445a44a311c49ecac8ebfba06ba10c56a24f..137361b28ab4919b7a304e45b2da2fa93c45f7c2 100644 (file)
@@ -297,6 +297,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 e6d15cf19811b94dc368d0278d9a3c2d84fe5c68..024b046fe351c06d59582484f17ac95fa2f5f20a 100644 (file)
@@ -209,6 +209,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)) {