Skip to content

Commit 8579ff0

Browse files
committed
Type Inference issue in spring-boot project
1 parent 90dce92 commit 8579ff0

4 files changed

Lines changed: 76 additions & 29 deletions

File tree

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ protected TypeBinding getP(int i) {
722722
if (InferenceContext18.DEBUG) {
723723
if (!capturesToRemove.isEmpty()) {
724724
for (ParameterizedTypeBinding toRemove : capturesToRemove) {
725+
if (this.captures.get(toRemove) != null)
725726
System.out.println("Removing capture bound " + //$NON-NLS-1$
726727
String.valueOf(toRemove.shortReadableName()) +
727728
"=capture("+String.valueOf(this.captures.get(toRemove).shortReadableName())+")"); //$NON-NLS-1$ //$NON-NLS-2$

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ public BoundSet inferInvocationType(TypeBinding expectedType, InvocationSite inv
462462
return null;
463463
// * reduce and incorporate
464464
if (!this.currentBounds.reduceOneConstraint(this, constraint))
465-
return null;
465+
continue;
466466
}
467467
for (ConstraintFormula constraint : bottomSet) {
468468
// https://bugs.openjdk.org/browse/JDK-8052325

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,28 +2024,17 @@ public void testBug427479b() {
20242024
" }\n" +
20252025
"}\n"
20262026
},
2027-
"----------\n" +
2028-
"1. ERROR in Bug419048.java (at line 9)\n" +
2029-
" roster\n" +
2030-
" .stream()\n" +
2031-
" .collect(\n" +
2032-
" Collectors.toMap(\n" +
2033-
" p -> p.getLast(),\n" +
2034-
" p -> p.getLast()\n" +
2035-
" ));\n" +
2036-
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
2037-
"Type mismatch: cannot convert from Map<Object,Object> to Map<String,Object>\n" +
2038-
"----------\n" +
2039-
"2. ERROR in Bug419048.java (at line 13)\n" +
2040-
" p -> p.getLast(),\n" +
2041-
" ^^^^^^^\n" +
2042-
"The method getLast() is undefined for the type Object\n" +
2043-
"----------\n" +
2044-
"3. ERROR in Bug419048.java (at line 14)\n" +
2045-
" p -> p.getLast()\n" +
2046-
" ^^^^^^^\n" +
2047-
"The method getLast() is undefined for the type Object\n" +
2048-
"----------\n");
2027+
"----------\n"
2028+
+ "1. ERROR in Bug419048.java (at line 13)\n"
2029+
+ " p -> p.getLast(),\n"
2030+
+ " ^^^^^^^\n"
2031+
+ "The method getLast() is undefined for the type Object\n"
2032+
+ "----------\n"
2033+
+ "2. ERROR in Bug419048.java (at line 14)\n"
2034+
+ " p -> p.getLast()\n"
2035+
+ " ^^^^^^^\n"
2036+
+ "The method getLast() is undefined for the type Object\n"
2037+
+ "----------\n");
20492038
}
20502039
public void testBug427626() {
20512040
runNegativeTest(
@@ -10964,4 +10953,56 @@ <X, Y extends One<X>> void foo2(Y y1) {
1096410953
"The method bar(One<Inner<?>>) in the type Bug is not applicable for the arguments (One<Inner<X>>)\n" +
1096510954
"----------\n");
1096610955
}
10956+
public void testSpringBoot() {
10957+
if (this.complianceLevel < ClassFileConstants.JDK9) {
10958+
return;
10959+
}
10960+
runConformTest(
10961+
new String[] {
10962+
"Pairs.java",
10963+
"""
10964+
import java.util.Map;
10965+
import java.util.function.Function;
10966+
10967+
public class Pairs<T> {
10968+
10969+
public <V> void addMapEntries(Function<T, Map<String, V>> extractor) {
10970+
add(extractor.andThen(Map::entrySet), Map.Entry::getKey, Map.Entry::getValue);
10971+
}
10972+
10973+
public <E> void add(Function<T, Iterable<E>> elementsExtractor, PairExtractor<E> pairExtractor) {
10974+
add(elementsExtractor, pairExtractor::getName, pairExtractor::getValue);
10975+
}
10976+
10977+
public <E, V> void add(Function<T, Iterable<E>> elementsExtractor, Function<E, String> nameExtractor,
10978+
Function<E, V> valueExtractor) {
10979+
}
10980+
10981+
interface PairExtractor<E> {
10982+
<N> N getName(E element);
10983+
<V> V getValue(E element);
10984+
static <T> PairExtractor<T> of(Function<T, ?> nameExtractor, Function<T, ?> valueExtractor) {
10985+
return new PairExtractor<>() {
10986+
10987+
@Override
10988+
@SuppressWarnings("unchecked")
10989+
public <N> N getName(T instance) {
10990+
return (N) nameExtractor.apply(instance);
10991+
}
10992+
10993+
@Override
10994+
@SuppressWarnings("unchecked")
10995+
public <V> V getValue(T instance) {
10996+
return (V) valueExtractor.apply(instance);
10997+
}
10998+
10999+
};
11000+
}
11001+
}
11002+
11003+
}
11004+
"""
11005+
});
11006+
}
11007+
1096711008
}

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7175,12 +7175,17 @@ public void test443467() throws Exception {
71757175
"}\n" +
71767176
"}\n",
71777177
},
7178-
"----------\n" +
7179-
"1. ERROR in BuildIdeMain.java (at line 9)\n" +
7180-
" filter2.map(p -> new SimpleEntry<>(updateToFile.get(p), p->ideFiles.get(p)));\n" +
7181-
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
7182-
"Cannot infer type arguments for SimpleEntry<>\n" +
7183-
"----------\n",
7178+
"----------\n"
7179+
+ "1. ERROR in BuildIdeMain.java (at line 9)\n"
7180+
+ " filter2.map(p -> new SimpleEntry<>(updateToFile.get(p), p->ideFiles.get(p)));\n"
7181+
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"
7182+
+ "The constructor AbstractMap.SimpleEntry<Path,Object>(Path, (<no type> p) -> {}) is undefined\n"
7183+
+ "----------\n"
7184+
+ "2. ERROR in BuildIdeMain.java (at line 9)\n"
7185+
+ " filter2.map(p -> new SimpleEntry<>(updateToFile.get(p), p->ideFiles.get(p)));\n"
7186+
+ " ^^^^^^^^^^^^^^^^^^\n"
7187+
+ "The target type of this expression must be a functional interface\n"
7188+
+ "----------\n",
71847189
this.LIBS,
71857190
true/*flush*/);
71867191
}

0 commit comments

Comments
 (0)