[vala/0.50] 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/0.50] vala: Issue an error on void initializer for local-variable
- Date: Mon, 19 Oct 2020 20:16:41 +0000 (UTC)
commit 765a5912a3f6b45a7168828a660493a3f9788fa3
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 de02d1607..c6865db09 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
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]