[vala/staging: 4/4] vala: Issue an error on void initializer for local-variable
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 4/4] vala: Issue an error on void initializer for local-variable
- Date: Tue, 29 Sep 2020 16:43:16 +0000 (UTC)
commit ebdf7c781d7eca34cbd63b59fe586c1cc530349b
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 41d4438fa..beb8d9b24 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -890,6 +890,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 a1c3657f8..96d9f5a69 100644
--- a/vala/valalocalvariable.vala
+++ b/vala/valalocalvariable.vala
@@ -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");
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]