This is an automated email from the ASF dual-hosted git repository.
paulk 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 7fa431cd24 GROOVY-11596: Additional DGM lazy iterator methods (add
missing DelegatesTo hint)
7fa431cd24 is described below
commit 7fa431cd24c0379c64755f37ab1ddd95203f1d75
Author: Paul King <[email protected]>
AuthorDate: Thu Apr 3 21:55:44 2025 +1000
GROOVY-11596: Additional DGM lazy iterator methods (add missing DelegatesTo
hint)
---
.../org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 13 +++++++++----
.../groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy | 5 +++--
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git
a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 331ba16153..75674f050a 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -14051,8 +14051,11 @@ public class DefaultGroovyMethods extends
DefaultGroovyMethodsSupport {
* @return an Iterator for the original elements
* @since 5.0.0
*/
- public static <T, U> Iterator<U> tapEvery(Iterator<U> self, int every,
-
@ClosureParams(FirstParam.FirstGenericType.class) Closure<T> closure) {
+ public static <T, U> Iterator<U> tapEvery(
+ @DelegatesTo.Target Iterator<U> self,
+ int every,
+ @DelegatesTo(genericTypeIndex=0)
+ @ClosureParams(FirstParam.FirstGenericType.class) Closure<T> closure) {
return new TapIterator<>(self, closure, every);
}
@@ -14083,8 +14086,10 @@ public class DefaultGroovyMethods extends
DefaultGroovyMethodsSupport {
* @return an Iterator for the original elements
* @since 5.0.0
*/
- public static <T, U> Iterator<U> tapEvery(Iterator<U> self,
-
@ClosureParams(FirstParam.FirstGenericType.class) Closure<T> closure) {
+ public static <T, U> Iterator<U> tapEvery(
+ @DelegatesTo.Target Iterator<U> self,
+ @DelegatesTo(genericTypeIndex=0)
+ @ClosureParams(FirstParam.FirstGenericType.class) Closure<T> closure) {
return new TapIterator<>(self, closure, 1);
}
diff --git a/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy
b/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy
index 1d5c956712..a096003b6c 100644
--- a/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy
@@ -447,8 +447,9 @@ class DefaultGroovyMethodsSTCTest extends
StaticTypeCheckingTestCase {
// GROOVY-11596
void testTapEveryTypeInference() {
assertScript '''
- List<String> pets = ['cat', 'canary', 'cockroach']
- pets.iterator().tapEvery{ assert it.startsWith('c') }.collect()
+ List<String> pets = ['canary', 'cat', 'cockroach']
+ pets.iterator().tapEvery { assert it.startsWith('c') }.collect()
+ pets.iterator().tapEvery(2) { assert contains('r') }.collect()
'''
}