Skip to content

Commit

Permalink
GROOVY-10282
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Oct 6, 2021
1 parent c66d390 commit 845f9fc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6406,4 +6406,23 @@ public void testCompileStatic10229() {
checkDisassemblyFor("C$_b_closure1.class",
" // Signature: ()Ljava/util/List<Ljava/util/Map<Ljava/lang/String;+Ljava/lang/Object;>;>;\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, "----------");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -918,13 +918,18 @@ public static Map<GenericsType, GenericsType> makeDeclaringAndActualGenericsType
* @since 2.5.9
*/
public static Map<GenericsType, GenericsType> makeDeclaringAndActualGenericsTypeMapOfExactType(ClassNode declaringClass, ClassNode actualReceiver) {
/* GRECLIPSE edit -- GROOVY-10282
List<ClassNode> parameterizedTypeList = new LinkedList<>();
Map<GenericsType, GenericsType> result = makeDeclaringAndActualGenericsTypeMapOfExactType(declaringClass, actualReceiver, parameterizedTypeList);
return connectGenericsTypes(result);
*/
return doMakeDeclaringAndActualGenericsTypeMap(declaringClass, actualReceiver, true).getFirst();
// GRECLIPSE end
}

/* GRECLIPSE edit
private static Map<GenericsType, GenericsType> makeDeclaringAndActualGenericsTypeMapOfExactType(ClassNode declaringClass, ClassNode actualReceiver, List<ClassNode> parameterizedTypeList) {
Tuple2<Map<GenericsType, GenericsType>, ClassNode> resultAndParameterizedTypeTuple = doMakeDeclaringAndActualGenericsTypeMap(declaringClass, actualReceiver, true);
ClassNode parameterizedType = resultAndParameterizedTypeTuple.getSecond();
Expand All @@ -937,6 +942,7 @@ private static Map<GenericsType, GenericsType> makeDeclaringAndActualGenericsTyp
return connectGenericsTypes(result);
}
*/

private static Tuple2<Map<GenericsType, GenericsType>, ClassNode> doMakeDeclaringAndActualGenericsTypeMap(ClassNode declaringClass, ClassNode actualReceiver, boolean tryToFindExactType) {
ClassNode parameterizedType = findParameterizedTypeFromCache(declaringClass, actualReceiver, tryToFindExactType);
Expand Down Expand Up @@ -970,6 +976,7 @@ private static Tuple2<Map<GenericsType, GenericsType>, ClassNode> doMakeDeclarin
// GRECLIPSE end
}

/* GRECLIPSE edit
private static Map<GenericsType, GenericsType> connectGenericsTypes(Map<GenericsType, GenericsType> genericsTypeMap) {
Map<GenericsType, GenericsType> result = new LinkedHashMap<>();
Expand All @@ -993,6 +1000,7 @@ private static Map<GenericsType, GenericsType> connectGenericsTypes(Map<Generics
return result;
}
*/

public static boolean hasPlaceHolders(final ClassNode parameterizedType) {
return checkPlaceHolders(parameterizedType, GenericsType::isPlaceholder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,14 @@ public static Map<GenericsType, GenericsType> makeDeclaringAndActualGenericsType
* @since 3.0.0
*/
public static Map<GenericsType, GenericsType> 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<GenericsType, GenericsType> makeDeclaringAndActualGenericsTypeMapOfExactType(final ClassNode declaringClass, final ClassNode actualReceiver, final Set<ClassNode> parameterizedTypes) {
Tuple2<Map<GenericsType, GenericsType>, ClassNode> tuple = doMakeDeclaringAndActualGenericsTypeMap(declaringClass, actualReceiver, true);
Map<GenericsType, GenericsType> result = tuple.getV1();
Expand All @@ -863,6 +868,7 @@ private static Map<GenericsType, GenericsType> makeDeclaringAndActualGenericsTyp
return result;
}
*/

private static Tuple2<Map<GenericsType, GenericsType>, ClassNode> doMakeDeclaringAndActualGenericsTypeMap(final ClassNode declaringClass, final ClassNode actualReceiver, final boolean tryToFindExactType) {
ClassNode parameterizedType = findParameterizedTypeFromCache(declaringClass, actualReceiver, tryToFindExactType);
Expand Down Expand Up @@ -916,7 +922,6 @@ private static Map<GenericsType, GenericsType> makePlaceholderAndParameterizedTy
return result;
}
*/
private static Map<GenericsType, GenericsType> connectGenericsTypes(final Map<GenericsType, GenericsType> genericsTypeMap) {
Map<GenericsType, GenericsType> result = new LinkedHashMap<>();
Expand All @@ -941,6 +946,7 @@ private static Map<GenericsType, GenericsType> connectGenericsTypes(final Map<Ge
return result;
}
*/

/**
* Checks if the type has any non-placeholder (aka resolved) generics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,14 @@ public static Map<GenericsType, GenericsType> makeDeclaringAndActualGenericsType
* @since 3.0.0
*/
public static Map<GenericsType, GenericsType> 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<GenericsType, GenericsType> makeDeclaringAndActualGenericsTypeMapOfExactType(final ClassNode declaringClass, final ClassNode actualReceiver, final Set<ClassNode> parameterizedTypes) {
Tuple2<Map<GenericsType, GenericsType>, ClassNode> tuple = doMakeDeclaringAndActualGenericsTypeMap(declaringClass, actualReceiver, true);
Map<GenericsType, GenericsType> result = tuple.getV1();
Expand All @@ -862,6 +867,7 @@ private static Map<GenericsType, GenericsType> makeDeclaringAndActualGenericsTyp
return result;
}
*/

private static Tuple2<Map<GenericsType, GenericsType>, ClassNode> doMakeDeclaringAndActualGenericsTypeMap(final ClassNode declaringClass, final ClassNode actualReceiver, final boolean tryToFindExactType) {
ClassNode parameterizedType = findParameterizedTypeFromCache(declaringClass, actualReceiver, tryToFindExactType);
Expand Down Expand Up @@ -914,7 +920,6 @@ private static Map<GenericsType, GenericsType> makePlaceholderAndParameterizedTy
return result;
}
*/
private static Map<GenericsType, GenericsType> connectGenericsTypes(final Map<GenericsType, GenericsType> genericsTypeMap) {
Map<GenericsType, GenericsType> result = new LinkedHashMap<>();
Expand All @@ -939,6 +944,7 @@ private static Map<GenericsType, GenericsType> connectGenericsTypes(final Map<Ge
return result;
}
*/

/**
* Checks if the type has any non-placeholder (aka resolved) generics.
Expand Down

0 comments on commit 845f9fc

Please sign in to comment.