Skip to content

Commit

Permalink
GROOVY-10807
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 8, 2023
1 parent b020533 commit 3ac5083
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8033,6 +8033,26 @@ public void testCompileStatic10807() {
//@formatter:on

runConformTest(sources, "[bar, baz, foo]");

assumeTrue(isAtLeastGroovy(50));

//@formatter:off
sources = new String[] {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class C {\n" +
" public static final Comparator<String> BY_DISPLAY_NAME = Comparator.<String,String>comparing(C::getDisplayName)\n" +
" static String getDisplayName(String component) {\n" +
" return component\n" +
" }\n" +
"}\n" +
"def list = ['foo','bar','baz']\n" +
"list.sort(C.BY_DISPLAY_NAME)\n" +
"print list\n",
};
//@formatter:on

runConformTest(sources, "[bar, baz, foo]");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@
import static org.codehaus.groovy.ast.tools.WideningCategories.isLongCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.isNumberCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.lowestUpperBound;
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.init;
import static org.codehaus.groovy.runtime.ArrayGroovyMethods.asBoolean;
import static org.codehaus.groovy.runtime.ArrayGroovyMethods.init;
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.last;
import static org.codehaus.groovy.syntax.Types.ASSIGN;
import static org.codehaus.groovy.syntax.Types.COMPARE_EQUAL;
Expand Down Expand Up @@ -2947,6 +2947,7 @@ protected void visitMethodCallArguments(final ClassNode receiver, final Argument
LambdaExpression lambda = constructLambdaExpressionForMethodReference(
targetType, (MethodReferenceExpression) expression);
inferClosureParameterTypes(receiver, arguments, lambda, target, selectedMethod);
expression.putNodeMetaData(PARAMETER_TYPE, lambda.getNodeMetaData(PARAMETER_TYPE));
expression.putNodeMetaData(CLOSURE_ARGUMENTS, lambda.getNodeMetaData(CLOSURE_ARGUMENTS));
} else {
addError("The argument is a method reference, but the parameter type is not a functional interface", expression);
Expand Down Expand Up @@ -3099,8 +3100,7 @@ protected void inferClosureParameterTypes(final ClassNode receiver, final Expres
Expression emc = typeCheckingContext.getEnclosingMethodCall();
if (emc instanceof MethodCallExpression) {
MethodCallExpression mce = (MethodCallExpression) emc;
if (mce.getArguments() == arguments // GROOVY-10807 ::
|| expression.getCode() == GENERATED_EMPTY_STATEMENT){
if (mce.getArguments() == arguments) {
GenericsType[] typeArguments = mce.getGenericsTypes();
if (typeArguments != null) {
int n = typeParameters.length;
Expand Down Expand Up @@ -4416,7 +4416,7 @@ protected void storeType(final Expression exp, ClassNode cn) {
assignedTypes.add(cn);
}
List<ClassNode> temporaryTypesForExpression = getTemporaryTypesForExpression(var);
if (asBoolean(temporaryTypesForExpression)) {
if (temporaryTypesForExpression != null) {
// a type inference has been made on a variable whose type was defined in an instanceof block
// erase available information with the new type
temporaryTypesForExpression.clear();
Expand Down

0 comments on commit 3ac5083

Please sign in to comment.