[vala/staging] vala: Don't allow casting to void



commit 88801eb4266a8c2d33176739c7f24b6b6cedd774
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                                                  | 2 +-
 .../{cast-void-not-allowed.vala => cast-void-not-allowed.test}     | 4 +---
 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
similarity index 52%
rename from tests/semantic/cast-void-not-allowed.vala
rename to 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) {


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