From: Rico Tzschichholz Date: Tue, 29 Sep 2020 12:47:48 +0000 (+0200) Subject: vala: Issue an error on void initializer for local-variable X-Git-Tag: 0.40.25~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce6a89db03ea1052f1acf15f724b647f1127c43a;p=thirdparty%2Fvala.git vala: Issue an error on void initializer for local-variable --- diff --git a/tests/Makefile.am b/tests/Makefile.am index eb4abee40..26a8eaa6c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..fbfbbff95 --- /dev/null +++ b/tests/semantic/localvariable-void-initializer.test @@ -0,0 +1,5 @@ +Invalid Code + +void main () { + var foo = (void) "foo"; +} diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala index ad0231f84..e75f402de 100644 --- a/vala/valalocalvariable.vala +++ b/vala/valalocalvariable.vala @@ -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"); } }