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 22:58:05 UTC
[groovy] branch GROOVY_4_0_X 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 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 2988612eb3 GROOVY-10635: Method references not working for record components in dynamic code
2988612eb3 is described below
commit 2988612eb30f3b6d704515938525ee87b90af8be
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 19c4aebc8f..5a30b58c58 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -1021,7 +1021,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']
+ '''
+ }
}