From 845f9fca620ee428e960f9b2b7ded6d965ebbb9a Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Wed, 6 Oct 2021 16:06:56 -0500 Subject: [PATCH] GROOVY-10282 --- .../tests/xform/StaticCompilationTests.java | 19 +++++++++++++++++++ .../groovy/ast/tools/GenericsUtils.java | 8 ++++++++ .../groovy/ast/tools/GenericsUtils.java | 8 +++++++- .../groovy/ast/tools/GenericsUtils.java | 8 +++++++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java index 64d312a464..a2297567c4 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java @@ -6406,4 +6406,23 @@ public void testCompileStatic10229() { checkDisassemblyFor("C$_b_closure1.class", " // Signature: ()Ljava/util/List;>;\n"); // not L?; } + + @Test // BiFunction and BinaryOperator with same type parameter + public void testCompileStatic10282() { + assumeTrue(isParrotParser()); + + //@formatter:off + String[] sources = { + "Main.groovy", + "@groovy.transform.CompileStatic\n" + + "String f() {\n" + + " def integers = java.util.stream.IntStream.range(0, 10).boxed()\n" + + " integers.reduce('', (s, i) -> s + '-', String::concat)\n" + + "}\n" + + "print f()\n", + }; + //@formatter:on + + runConformTest(sources, "----------"); + } } diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/tools/GenericsUtils.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/tools/GenericsUtils.java index b209627d02..2dde112516 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/tools/GenericsUtils.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/tools/GenericsUtils.java @@ -918,13 +918,18 @@ public static Map makeDeclaringAndActualGenericsType * @since 2.5.9 */ public static Map makeDeclaringAndActualGenericsTypeMapOfExactType(ClassNode declaringClass, ClassNode actualReceiver) { + /* GRECLIPSE edit -- GROOVY-10282 List parameterizedTypeList = new LinkedList<>(); Map result = makeDeclaringAndActualGenericsTypeMapOfExactType(declaringClass, actualReceiver, parameterizedTypeList); return connectGenericsTypes(result); + */ + return doMakeDeclaringAndActualGenericsTypeMap(declaringClass, actualReceiver, true).getFirst(); + // GRECLIPSE end } + /* GRECLIPSE edit private static Map makeDeclaringAndActualGenericsTypeMapOfExactType(ClassNode declaringClass, ClassNode actualReceiver, List parameterizedTypeList) { Tuple2, ClassNode> resultAndParameterizedTypeTuple = doMakeDeclaringAndActualGenericsTypeMap(declaringClass, actualReceiver, true); ClassNode parameterizedType = resultAndParameterizedTypeTuple.getSecond(); @@ -937,6 +942,7 @@ private static Map makeDeclaringAndActualGenericsTyp return connectGenericsTypes(result); } + */ private static Tuple2, ClassNode> doMakeDeclaringAndActualGenericsTypeMap(ClassNode declaringClass, ClassNode actualReceiver, boolean tryToFindExactType) { ClassNode parameterizedType = findParameterizedTypeFromCache(declaringClass, actualReceiver, tryToFindExactType); @@ -970,6 +976,7 @@ private static Tuple2, ClassNode> doMakeDeclarin // GRECLIPSE end } + /* GRECLIPSE edit private static Map connectGenericsTypes(Map genericsTypeMap) { Map result = new LinkedHashMap<>(); @@ -993,6 +1000,7 @@ private static Map connectGenericsTypes(Map makeDeclaringAndActualGenericsType * @since 3.0.0 */ public static Map makeDeclaringAndActualGenericsTypeMapOfExactType(final ClassNode declaringClass, final ClassNode actualReceiver) { + /* GRECLIPSE edit -- GROOVY-10282 return makeDeclaringAndActualGenericsTypeMapOfExactType(declaringClass, actualReceiver, new HashSet<>()); + */ + return doMakeDeclaringAndActualGenericsTypeMap(declaringClass, actualReceiver, true).getV1(); + // GRECLIPSE end } + /* GRECLIPSE edit private static Map makeDeclaringAndActualGenericsTypeMapOfExactType(final ClassNode declaringClass, final ClassNode actualReceiver, final Set parameterizedTypes) { Tuple2, ClassNode> tuple = doMakeDeclaringAndActualGenericsTypeMap(declaringClass, actualReceiver, true); Map result = tuple.getV1(); @@ -863,6 +868,7 @@ private static Map makeDeclaringAndActualGenericsTyp return result; } + */ private static Tuple2, ClassNode> doMakeDeclaringAndActualGenericsTypeMap(final ClassNode declaringClass, final ClassNode actualReceiver, final boolean tryToFindExactType) { ClassNode parameterizedType = findParameterizedTypeFromCache(declaringClass, actualReceiver, tryToFindExactType); @@ -916,7 +922,6 @@ private static Map makePlaceholderAndParameterizedTy return result; } - */ private static Map connectGenericsTypes(final Map genericsTypeMap) { Map result = new LinkedHashMap<>(); @@ -941,6 +946,7 @@ private static Map connectGenericsTypes(final Map makeDeclaringAndActualGenericsType * @since 3.0.0 */ public static Map makeDeclaringAndActualGenericsTypeMapOfExactType(final ClassNode declaringClass, final ClassNode actualReceiver) { + /* GRECLIPSE edit -- GROOVY-10282 return makeDeclaringAndActualGenericsTypeMapOfExactType(declaringClass, actualReceiver, new HashSet<>()); + */ + return doMakeDeclaringAndActualGenericsTypeMap(declaringClass, actualReceiver, true).getV1(); + // GRECLIPSE end } + /* GRECLIPSE edit private static Map makeDeclaringAndActualGenericsTypeMapOfExactType(final ClassNode declaringClass, final ClassNode actualReceiver, final Set parameterizedTypes) { Tuple2, ClassNode> tuple = doMakeDeclaringAndActualGenericsTypeMap(declaringClass, actualReceiver, true); Map result = tuple.getV1(); @@ -862,6 +867,7 @@ private static Map makeDeclaringAndActualGenericsTyp return result; } + */ private static Tuple2, ClassNode> doMakeDeclaringAndActualGenericsTypeMap(final ClassNode declaringClass, final ClassNode actualReceiver, final boolean tryToFindExactType) { ClassNode parameterizedType = findParameterizedTypeFromCache(declaringClass, actualReceiver, tryToFindExactType); @@ -914,7 +920,6 @@ private static Map makePlaceholderAndParameterizedTy return result; } - */ private static Map connectGenericsTypes(final Map genericsTypeMap) { Map result = new LinkedHashMap<>(); @@ -939,6 +944,7 @@ private static Map connectGenericsTypes(final Map