Skip to content

Commit

Permalink
fix bug in import types check
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed Apr 13, 2024
1 parent 4781fc4 commit b230987
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ private static List<CtTypeReference<?>> findQualifiedTypes(CtTypeReference<?> ct
}

List<CtTypeReference<?>> result = new ArrayList<>();
// the right condition is a workaround for https://github.com/INRIA/spoon/issues/5428
if (!isSimplyQualified(type) && (type.getPosition().isValidPosition() || type.getParent(CtArrayTypeReference.class) != null)) {
// The not simplified type check does not always work, especially when spoon is buggy.
// See forEach test, where the type is not implicit, but its parent is.
//
// I can not think of a case where the parent is implicit and the child is not, so I added
// this as a workaround to avoid making a spoon PR.
if (!isSimplyQualified(type) && !type.getParent().isImplicit()) {
result.add(type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,23 @@ public static String[] makeCopy(String[] array) {

problems.assertExhausted();
}

@Test
void testForEach() throws IOException, LinterException {
ProblemIterator problems = this.checkIterator(StringSourceInfo.fromSourceString(
JavaVersion.JAVA_17,
"Test",
"""
import java.util.Map;
class Test {
public static void takesMap(Map<Integer, String[][]> input, Map<Integer, Boolean> output) {
input.forEach((key, strings) -> output.put(key, false));
}
}
"""
), PROBLEM_TYPES);

problems.assertExhausted();
}
}

0 comments on commit b230987

Please sign in to comment.