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 d1e3ce4e79 GROOVY-11596: Additional DGM lazy iterator methods (add 
missing closure param hint)
d1e3ce4e79 is described below

commit d1e3ce4e797263a3dbdb0e4e358b695c6ab7bb80
Author: Paul King <[email protected]>
AuthorDate: Thu Apr 3 21:35:55 2025 +1000

    GROOVY-11596: Additional DGM lazy iterator methods (add missing closure 
param hint)
---
 .../java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java    | 7 +++++--
 src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy  | 8 ++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git 
a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java 
b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index b4f1be2380..331ba16153 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -14051,7 +14051,8 @@ public class DefaultGroovyMethods extends 
DefaultGroovyMethodsSupport {
      * @return an Iterator for the original elements
      * @since 5.0.0
      */
-    public static <T, U> Iterator<T> tapEvery(Iterator<T> self, int every, 
Closure<U> closure) {
+    public static <T, U> Iterator<U> tapEvery(Iterator<U> self, int every,
+                                              
@ClosureParams(FirstParam.FirstGenericType.class) Closure<T> closure) {
         return new TapIterator<>(self, closure, every);
     }
 
@@ -14082,7 +14083,8 @@ public class DefaultGroovyMethods extends 
DefaultGroovyMethodsSupport {
      * @return an Iterator for the original elements
      * @since 5.0.0
      */
-    public static <T, U> Iterator<T> tapEvery(Iterator<T> self, Closure<U> 
closure) {
+    public static <T, U> Iterator<U> tapEvery(Iterator<U> self,
+                                              
@ClosureParams(FirstParam.FirstGenericType.class) Closure<T> closure) {
         return new TapIterator<>(self, closure, 1);
     }
 
@@ -14110,6 +14112,7 @@ public class DefaultGroovyMethods extends 
DefaultGroovyMethodsSupport {
             T next = delegate.next();
             if (++index % every == 0) {
                 closure.setDelegate(next);
+                closure.setResolveStrategy(Closure.DELEGATE_FIRST);
                 closure.call(next);
             }
             return next;
diff --git a/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy 
b/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy
index f079efaefb..1d5c956712 100644
--- a/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy
@@ -444,6 +444,14 @@ class DefaultGroovyMethodsSTCTest extends 
StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-11596
+    void testTapEveryTypeInference() {
+        assertScript '''
+            List<String> pets = ['cat', 'canary', 'cockroach']
+            pets.iterator().tapEvery{ assert it.startsWith('c') }.collect()
+        '''
+    }
+
     // GROOVY-6668, GROOVY-8212
     void testMapGetAtVsObjectGetAt2() {
         assertScript '''

Reply via email to