This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new d6514725fe GROOVY-11238: Refine static compilation for `==>`
d6514725fe is described below
commit d6514725feef361266d884f9b6ccaaed0f4e8e03
Author: Daniel Sun <[email protected]>
AuthorDate: Sat Dec 23 00:51:14 2023 +0800
GROOVY-11238: Refine static compilation for `==>`
---
.../transform/stc/StaticTypeCheckingSupport.java | 2 ++
.../groovy/operator/ImplicationOperatorTest.groovy | 7 ++++++
.../src/test/groovy/JQwikTest.groovy | 28 ++++++++++++++++++++--
3 files changed, 35 insertions(+), 2 deletions(-)
diff --git
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index da3f79e2f3..b15cd5c4f5 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -147,6 +147,7 @@ import static
org.codehaus.groovy.syntax.Types.COMPARE_NOT_INSTANCEOF;
import static org.codehaus.groovy.syntax.Types.COMPARE_TO;
import static org.codehaus.groovy.syntax.Types.DIVIDE;
import static org.codehaus.groovy.syntax.Types.DIVIDE_EQUAL;
+import static org.codehaus.groovy.syntax.Types.IMPLIES;
import static org.codehaus.groovy.syntax.Types.INTDIV;
import static org.codehaus.groovy.syntax.Types.INTDIV_EQUAL;
import static org.codehaus.groovy.syntax.Types.KEYWORD_IN;
@@ -523,6 +524,7 @@ public abstract class StaticTypeCheckingSupport {
case MATCH_REGEX:
case KEYWORD_INSTANCEOF:
case COMPARE_NOT_INSTANCEOF:
+ case IMPLIES:
return true;
default:
return false;
diff --git a/src/test/groovy/operator/ImplicationOperatorTest.groovy
b/src/test/groovy/operator/ImplicationOperatorTest.groovy
index b3b95d11d4..901682a63c 100644
--- a/src/test/groovy/operator/ImplicationOperatorTest.groovy
+++ b/src/test/groovy/operator/ImplicationOperatorTest.groovy
@@ -19,6 +19,7 @@
package operator
import groovy.test.GroovyTestCase
+import groovy.transform.CompileStatic
/**
* Test Logical Implication Operation
@@ -37,4 +38,10 @@ class ImplicationOperatorTest extends GroovyTestCase {
assert false ==> (false ==> false)
assert !((false ==> false) ==> false)
}
+
+ @CompileStatic
+ void testImplicationOperationCS() {
+ boolean result = false ==> false && false ==> true && !(true ==>
false) && true ==> true
+ assert result
+ }
}
diff --git a/subprojects/groovy-test-junit5/src/test/groovy/JQwikTest.groovy
b/subprojects/groovy-test-junit5/src/test/groovy/JQwikTest.groovy
index aba7529cb1..557f8e8c55 100644
--- a/subprojects/groovy-test-junit5/src/test/groovy/JQwikTest.groovy
+++ b/subprojects/groovy-test-junit5/src/test/groovy/JQwikTest.groovy
@@ -16,8 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-import net.jqwik.api.*
-import net.jqwik.api.constraints.*
+
+
+import groovy.transform.CompileStatic
+import net.jqwik.api.ForAll
+import net.jqwik.api.Property
+import net.jqwik.api.constraints.IntRange
+import net.jqwik.api.constraints.Size
+import net.jqwik.api.constraints.UniqueElements
class JQwikTest {
@Property
@@ -31,16 +37,34 @@ class JQwikTest {
i == 0 ==> i == -i
}
+ @CompileStatic
+ @Property(tries=10)
+ boolean 'only zero is the same as the negative of itself - CS'(@ForAll int
i) {
+ i == 0 ==> i == -i
+ }
+
@Property(tries=100)
boolean 'an odd number squared is still odd'(@ForAll int n) {
n % 2 == 1 ==> (n ** 2) % 2 == 1
}
+ @CompileStatic
+ @Property(tries=100)
+ boolean 'an odd number squared is still odd - CS'(@ForAll int n) {
+ n % 2 == 1 ==> (n ** 2) % 2 == 1
+ }
+
@Property(tries=100)
boolean 'abs of a positive integer is itself'(@ForAll int i) {
i >= 0 ==> i.abs() == i
}
+ @CompileStatic
+ @Property(tries=100)
+ boolean 'abs of a positive integer is itself - CS'(@ForAll int i) {
+ i >= 0 ==> i.abs() == i
+ }
+
@Property(tries=100)
boolean 'abs of a positive integer is itself alternative'(@ForAll
@IntRange(min = 0, max = 10000) int i) {
i.abs() == i