]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Issue an error on void initializer for local-variable
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 29 Sep 2020 12:47:48 +0000 (14:47 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 30 Sep 2020 11:29:17 +0000 (13:29 +0200)
tests/Makefile.am
tests/semantic/localvariable-void-initializer.test [new file with mode: 0644]
vala/valalocalvariable.vala

index de02d16076b9f77aab2bd78955b77909b2b0382c..c6865db09e61af8297ab9913f18679838f759593 100644 (file)
@@ -889,6 +889,7 @@ TESTS = \
        semantic/localvariable-var-static-access-instance-property.test \
        semantic/localvariable-var-without-initializer.test \
        semantic/localvariable-void.test \
+       semantic/localvariable-void-initializer.test \
        semantic/member-access-async-callback-invalid.test \
        semantic/member-access-capture-out.test \
        semantic/member-access-protected-invalid.test \
diff --git a/tests/semantic/localvariable-void-initializer.test b/tests/semantic/localvariable-void-initializer.test
new file mode 100644 (file)
index 0000000..fbfbbff
--- /dev/null
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+       var foo = (void) "foo";
+}
index a1c3657f8e6baf54ba64c8bca15bef472449342e..96d9f5a6970e3c8222d960e6018142c54728dcb9 100644 (file)
@@ -122,6 +122,9 @@ public class Vala.LocalVariable : Variable {
 
                        if (!initializer.check (context)) {
                                error = true;
+                       } else if (initializer.value_type is VoidType) {
+                               error = true;
+                               Report.error (initializer.source_reference, "'void' not supported as initializer type");
                        }
                }