[vala/0.40] vala: Issue an error on void initializer for local-variable



commit ce6a89db03ea1052f1acf15f724b647f1127c43a
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Sep 29 14:47:48 2020 +0200

    vala: Issue an error on void initializer for local-variable

 tests/Makefile.am                                  | 1 +
 tests/semantic/localvariable-void-initializer.test | 5 +++++
 vala/valalocalvariable.vala                        | 3 +++
 3 files changed, 9 insertions(+)
---
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");
                        }
                }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]