]> 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>
Sun, 3 Jan 2021 11:43:57 +0000 (12:43 +0100)
tests/Makefile.am
tests/semantic/localvariable-void-initializer.test [new file with mode: 0644]
vala/valalocalvariable.vala

index eb4abee40dec63695aa0ad35c7d9b5837ce1adde..26a8eaa6ce01206e70c01059bfea908b70ace88b 100644 (file)
@@ -766,6 +766,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 ad0231f8495ae921622f3b5f3eab06b66207ef1e..e75f402dea98019d1dba7bb859d10b1e3e356756 100644 (file)
@@ -102,6 +102,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");
                        }
                }