Skip to content

Commit

Permalink
GROOVY-10049
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Apr 22, 2021
1 parent 6d200a4 commit 47fc4ae
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2223,4 +2223,28 @@ public void testTypeChecked10027() {

runConformTest(sources, "42");
}

@Test
public void testTypeChecked10049() {
if (Float.parseFloat(System.getProperty("java.specification.version")) > 8)
vmArguments = new String[] {"--add-opens", "java.base/java.util.stream=ALL-UNNAMED"};

//@formatter:off
String[] sources = {
"Main.groovy",
"def <X /*extends Number*/> Set<X> generateNumbers(Class<X> type) {\n" +
" return Collections.singleton(type.newInstance(42))\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"def <Y extends Number> void printNumbers(Class<Y> numberType) {\n" +
" generateNumbers(numberType).stream()\n" +
" .filter { n -> n.intValue() > 0 }\n" +
" .forEach { n -> print n }\n" +
"}\n" +
"printNumbers(Integer)\n",
};
//@formatter:on

runConformTest(sources, "42");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3316,11 +3316,13 @@ private void inferSAMType(Parameter param, ClassNode receiver, MethodNode method
// First we try to get as much information about the declaration
// class through the receiver
Map<GenericsTypeName, GenericsType> targetMethodDeclarationClassConnections = new HashMap<GenericsTypeName, GenericsType>();
// GRECLIPSE add -- GROOVY-9347
// GRECLIPSE add -- GROOVY-9347, GROOVY-10049
for (ClassNode face : receiver.getAllInterfaces()) {
extractGenericsConnections(targetMethodDeclarationClassConnections, StaticTypeCheckingSupport.getCorrectedClassNode(receiver, face, true), face.redirect());
if (face != receiver) {
ClassNode type = StaticTypeCheckingSupport.getCorrectedClassNode(receiver, face, true);
extractGenericsConnections(targetMethodDeclarationClassConnections, type, face.redirect());
}
}
if (!receiver.isInterface())
// GRECLIPSE end
extractGenericsConnections(targetMethodDeclarationClassConnections, receiver, receiver.redirect());
// then we use the method with the SAM parameter to get more information about the declaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3018,12 +3018,22 @@ protected void inferClosureParameterTypes(final ClassNode receiver, final Expres
private void inferSAMType(final Parameter param, final ClassNode receiver, final MethodNode methodWithSAMParameter, final ArgumentListExpression originalMethodCallArguments, final ClosureExpression openBlock) {
// first we try to get as much information about the declaration class through the receiver
Map<GenericsTypeName, GenericsType> targetMethodConnections = new HashMap<>();
/* GRECLIPSE edit -- GROOVY-10049
for (ClassNode face : receiver.getAllInterfaces()) {
extractGenericsConnections(targetMethodConnections, getCorrectedClassNode(receiver, face, true), face.redirect());
}
if (!receiver.isInterface()) {
extractGenericsConnections(targetMethodConnections, receiver, receiver.redirect());
}
*/
for (ClassNode face : receiver.getAllInterfaces()) {
if (face != receiver) {
ClassNode type = getCorrectedClassNode(receiver, face, true);
extractGenericsConnections(targetMethodConnections, type, face.redirect());
}
}
extractGenericsConnections(targetMethodConnections, receiver, receiver.redirect());
// GRECLIPSE end

// then we use the method with the SAM-type parameter to get more information about the declaration
Parameter[] parametersOfMethodContainingSAM = methodWithSAMParameter.getParameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2923,12 +2923,22 @@ protected void inferClosureParameterTypes(final ClassNode receiver, final Expres
private void inferSAMType(final Parameter param, final ClassNode receiver, final MethodNode methodWithSAMParameter, final ArgumentListExpression originalMethodCallArguments, final ClosureExpression openBlock) {
// first we try to get as much information about the declaration class through the receiver
Map<GenericsTypeName, GenericsType> targetMethodConnections = new HashMap<>();
/* GRECLIPSE edit -- GROOVY-10049
for (ClassNode face : receiver.getAllInterfaces()) {
extractGenericsConnections(targetMethodConnections, getCorrectedClassNode(receiver, face, true), face.redirect());
}
if (!receiver.isInterface()) {
extractGenericsConnections(targetMethodConnections, receiver, receiver.redirect());
}
*/
for (ClassNode face : receiver.getAllInterfaces()) {
if (face != receiver) {
ClassNode type = getCorrectedClassNode(receiver, face, true);
extractGenericsConnections(targetMethodConnections, type, face.redirect());
}
}
extractGenericsConnections(targetMethodConnections, receiver, receiver.redirect());
// GRECLIPSE end

// then we use the method with the SAM-type parameter to get more information about the declaration
Parameter[] parametersOfMethodContainingSAM = methodWithSAMParameter.getParameters();
Expand Down

0 comments on commit 47fc4ae

Please sign in to comment.