You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2022/05/23 23:04:57 UTC

[groovy] branch master updated: GROOVY-10635: Method references not working for record components in dynamic code

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 4cb6a0efc8 GROOVY-10635: Method references not working for record components in dynamic code
4cb6a0efc8 is described below

commit 4cb6a0efc8e15535cca06eb3a72fe6a5c9f02e3f
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon May 23 22:43:17 2022 +1000

    GROOVY-10635: Method references not working for record components in dynamic code
---
 src/main/java/groovy/lang/MetaClassImpl.java             |  2 +-
 src/test/groovy/transform/stc/MethodReferenceTest.groovy | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index c57b0331c0..947007fe02 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -1022,7 +1022,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
         try {
             return ownerMetaClass.invokeMethod(ownerClass, owner, methodName, arguments, false, false);
 
-        } catch (MissingMethodExceptionNoStack | InvokerInvocationException e) {
+        } catch (MissingMethodExceptionNoStack | InvokerInvocationException | IllegalArgumentException e) {
             if (ownerIsClass) {
                 if (MethodClosure.NEW.equals(methodName)) { // CONSTRUCTOR REFERENCE
                     if (!ownerClass.isArray()) {
diff --git a/src/test/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
index 0935f6f110..a3f401a1f4 100644
--- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy
+++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
@@ -709,4 +709,14 @@ final class MethodReferenceTest {
         '''
         assert err =~ /The argument is a method reference, but the parameter type is not a functional interface/
     }
+
+    @Test // GROOVY-10635
+    void testRecordComponentMethodReference() {
+        assertScript shell, '''
+            record Bar(String name) { }
+
+            def bars = [new Bar(name: 'A'), new Bar(name: 'B')]
+            assert bars.stream().map(Bar::name).map(String::toLowerCase).toList() == ['a', 'b']
+        '''
+    }
 }