diff options
author | Colin Kiama <colinkiama@gmail.com> | 2021-09-12 19:11:00 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-11-08 12:50:17 +0100 |
commit | 88801eb4266a8c2d33176739c7f24b6b6cedd774 (patch) | |
tree | 297d5a99978778001388b9a68efa4d7b1ba7e3c5 | |
parent | 32366df9e1cfc73a9d521675a017a7db25f03a7c (diff) | |
download | vala-88801eb4266a8c2d33176739c7f24b6b6cedd774.tar.gz |
vala: Don't allow casting to void
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1070
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/semantic/cast-void-not-allowed.test (renamed from tests/semantic/cast-void-not-allowed.vala) | 4 | ||||
-rw-r--r-- | vala/valacastexpression.vala | 7 |
3 files changed, 5 insertions, 8 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 9b917dea2..9a6c4b3f2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -980,7 +980,7 @@ TESTS = \ semantic/assignment-signal-incompatible-type.test \ semantic/cast-gvalue-unsupported.test \ semantic/cast-gvariant-unsupported.test \ - semantic/cast-void-not-allowed.vala \ + 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.vala b/tests/semantic/cast-void-not-allowed.test index dee3801de..965ef235c 100644 --- a/tests/semantic/cast-void-not-allowed.vala +++ b/tests/semantic/cast-void-not-allowed.test @@ -1,11 +1,9 @@ -bool success = false; +Invalid Code bool foo () { - success = true; return true; } void main () { (void) foo (); - assert (success); } diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala index 1d1dbb0f2..732b99a71 100644 --- a/vala/valacastexpression.vala +++ b/vala/valacastexpression.vala @@ -165,10 +165,9 @@ public class Vala.CastExpression : Expression { // FIXME: check whether cast is allowed if (type_reference is VoidType) { - Report.warning (source_reference, "Casting to `void' is not supported"); - context.analyzer.replaced_nodes.add (this); - parent_node.replace_expression (this, inner); - return inner.check (context); + Report.error (source_reference, "Casting to `void' is not allowed"); + error = true; + return false; } if (type_reference is DelegateType && inner.value_type is MethodType) { |