[vala/staging] vala: Don't allow casting to void
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Don't allow casting to void
- Date: Tue, 14 Sep 2021 06:45:55 +0000 (UTC)
commit 051b8a13abb371ed21513ac16acd0f7dfa069dfd
Author: Colin Kiama <colinkiama gmail com>
Date: Sun Sep 12 19:11:00 2021 +0100
vala: Don't allow casting to void
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1070
tests/Makefile.am | 1 +
tests/semantic/cast-void-not-allowed.test | 9 +++++++++
vala/valacastexpression.vala | 6 ++++++
3 files changed, 16 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ec9c97b13..5d3a6ee9b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -948,6 +948,7 @@ TESTS = \
semantic/assignment-signal-incompatible-type.test \
semantic/cast-gvalue-unsupported.test \
semantic/cast-gvariant-unsupported.test \
+ semantic/cast-void-not-allowed.test \
semantic/chainup-gobject-incompatible-type-property.test \
semantic/chainup-gobject-unknown-property.test \
semantic/chainup-gobject-unsupported-type-property.test \
diff --git a/tests/semantic/cast-void-not-allowed.test b/tests/semantic/cast-void-not-allowed.test
new file mode 100644
index 000000000..965ef235c
--- /dev/null
+++ b/tests/semantic/cast-void-not-allowed.test
@@ -0,0 +1,9 @@
+Invalid Code
+
+bool foo () {
+ return true;
+}
+
+void main () {
+ (void) foo ();
+}
diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala
index 9aff511fa..732b99a71 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -164,6 +164,12 @@ public class Vala.CastExpression : Expression {
// FIXME: check whether cast is allowed
+ if (type_reference is VoidType) {
+ Report.error (source_reference, "Casting to `void' is not allowed");
+ error = true;
+ return false;
+ }
+
if (type_reference is DelegateType && inner.value_type is MethodType) {
if (target_type != null) {
inner.value_type.value_owned = target_type.value_owned;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]