@@ -3761,34 +3761,36 @@ private void inferMethodReferenceType(final ClassNode receiver, final ArgumentLi
3761
3761
}
3762
3762
3763
3763
Parameter [] parameters = selectedMethod .getParameters ();
3764
+ final int nthParameter = parameters .length - 1 ;
3764
3765
3765
- List <Integer > methodReferenceParamIndexList = new LinkedList <>();
3766
- List <Expression > newArgumentExpressionList = new LinkedList <>();
3766
+ List <Integer > methodReferencePositions = new LinkedList <>();
3767
+ List <Expression > newArgumentExpressions = new LinkedList <>();
3767
3768
for (int i = 0 , n = argumentExpressions .size (); i < n ; i += 1 ) {
3768
3769
Expression argumentExpression = argumentExpressions .get (i );
3769
3770
if (!(argumentExpression instanceof MethodReferenceExpression )) {
3770
- newArgumentExpressionList .add (argumentExpression );
3771
- continue ;
3772
- }
3773
-
3774
- Parameter param = parameters [i ];
3775
- ClassNode paramType = param .getType ();
3776
-
3777
- if (!isFunctionalInterface (paramType .redirect ())) {
3778
- addError ("The argument is a method reference, but the parameter type is not a functional interface" , argumentExpression );
3779
- newArgumentExpressionList .add (argumentExpression );
3771
+ newArgumentExpressions .add (argumentExpression );
3780
3772
} else {
3781
- newArgumentExpressionList .add (constructLambdaExpressionForMethodReference (paramType ));
3782
- methodReferenceParamIndexList .add (i );
3773
+ Parameter param = parameters [Math .min (i , nthParameter )]; // GROOVY-10336
3774
+ ClassNode paramType = param .getType ();
3775
+ if (i >= nthParameter && paramType .isArray ())
3776
+ paramType = paramType .getComponentType ();
3777
+
3778
+ if (!isFunctionalInterface (paramType .redirect ())) {
3779
+ addError ("The argument is a method reference, but the parameter type is not a functional interface" , argumentExpression );
3780
+ newArgumentExpressions .add (argumentExpression );
3781
+ } else {
3782
+ methodReferencePositions .add (i );
3783
+ newArgumentExpressions .add (constructLambdaExpressionForMethodReference (paramType ));
3784
+ }
3783
3785
}
3784
3786
}
3785
- // GRECLIPSE add -- GROOVY-10269
3786
- if (methodReferenceParamIndexList .isEmpty ()) return ;
3787
- // GRECLIPSE end
3788
- visitMethodCallArguments (receiver , args (newArgumentExpressionList ), true , selectedMethod );
3789
3787
3790
- for (int index : methodReferenceParamIndexList ) {
3791
- Expression lambdaExpression = newArgumentExpressionList .get (index );
3788
+ if (methodReferencePositions .isEmpty ()) return ; // GROOVY-10269
3789
+
3790
+ visitMethodCallArguments (receiver , args (newArgumentExpressions ), true , selectedMethod );
3791
+
3792
+ for (int index : methodReferencePositions ) {
3793
+ Expression lambdaExpression = newArgumentExpressions .get (index );
3792
3794
Expression methodReferenceExpression = argumentExpressions .get (index );
3793
3795
methodReferenceExpression .putNodeMetaData (CLOSURE_ARGUMENTS , lambdaExpression .getNodeMetaData (CLOSURE_ARGUMENTS ));
3794
3796
}
0 commit comments