You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2023/04/30 00:42:19 UTC

[groovy] branch GROOVY_4_0_X updated: GROOVY-10920: SC: `void` method as boolean condition

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new 73c5865736 GROOVY-10920: SC: `void` method as boolean condition
73c5865736 is described below

commit 73c5865736a4bb3b75d2cab0f5882167482e4b37
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Apr 29 18:53:05 2023 -0500

    GROOVY-10920: SC: `void` method as boolean condition
    
    4_0_X backport
---
 .../transformers/BooleanExpressionTransformer.java |  3 +-
 src/test/groovy/bugs/Groovy10920.groovy            | 41 ++++++++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java b/src/main/java/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java
index 988dfc590e..f1cd0b13a0 100644
--- a/src/main/java/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java
+++ b/src/main/java/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java
@@ -107,9 +107,8 @@ class BooleanExpressionTransformer {
                 int mark = os.getStackLength();
                 getExpression().visit(visitor);
 
-                if (ClassHelper.isPrimitiveType(type)) {
+                if (ClassHelper.isPrimitiveType(type) && !ClassHelper.isPrimitiveVoid(type)) { // GROOVY-10920
                     if (ClassHelper.isPrimitiveBoolean(type)) {
-                        // TODO: maybe: os.castToBool(mark, true);
                         os.doGroovyCast(ClassHelper.boolean_TYPE);
                     } else {
                         BytecodeHelper.convertPrimitiveToBoolean(mv, type);
diff --git a/src/test/groovy/bugs/Groovy10920.groovy b/src/test/groovy/bugs/Groovy10920.groovy
new file mode 100644
index 0000000000..ea0198c351
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy10920.groovy
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy10920 {
+
+    @Test
+    void testWhileWithVoidCondition() {
+        assertScript '''import groovy.transform.*
+            void proc() {}
+            @CompileStatic
+            void test() {
+                while (proc()) {
+                    assert false
+                }
+            }
+
+            test()
+        '''
+    }
+}