Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1529,12 +1529,6 @@ static List<InferenceVariable> pickIvarsByRank(Set<InferenceVariable> variableSe
Map<InferenceVariable,Set<InferenceVariable>> collectDependencies(BoundSet bounds) {
// Implements the definition of dependencies from JLS §18.4:
Map<InferenceVariable,Set<InferenceVariable>> dependsOn = new LinkedHashMap<>();
// "An inference variable α depends on the resolution of itself."
for (InferenceVariable iv : this.inferenceVariables) {
Set<InferenceVariable> selfSet = new LinkedHashSet<>();
selfSet.add(iv);
dependsOn.put(iv, selfSet);
}
for (TypeBound typeBound : bounds.flatten()) {
// "Given a bound of one of the following forms:" (ecj may represent some using :> rather than <:)
// α = T
Expand Down Expand Up @@ -1616,6 +1610,15 @@ Map<InferenceVariable,Set<InferenceVariable>> collectDependencies(BoundSet bound
}
}
} while (hasChange);
// "An inference variable α depends on the resolution of itself."
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4846
for (InferenceVariable iv : this.inferenceVariables) {
if (!dependsOn.containsKey(iv)) {
Set<InferenceVariable> selfSet = new LinkedHashSet<>();
selfSet.add(iv);
dependsOn.put(iv, selfSet);
}
}
return dependsOn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11074,4 +11074,58 @@ public static <T> T any() {
"""
});
}

// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4846
public void testGH4846() {
if (this.complianceLevel < ClassFileConstants.JDK9) {
return;
}
runConformTest(
new String[] {
"Pairs.java",
"""
import java.util.Map;
import java.util.function.Function;

public class Pairs<T> {

public <V> void addMapEntries(Function<T, Map<String, V>> extractor) {
add(extractor.andThen(Map::entrySet), Map.Entry::getKey, Map.Entry::getValue);
}

public <E> void add(Function<T, Iterable<E>> elementsExtractor, PairExtractor<E> pairExtractor) {
add(elementsExtractor, pairExtractor::getName, pairExtractor::getValue);
}

public <E, V> void add(Function<T, Iterable<E>> elementsExtractor, Function<E, String> nameExtractor,
Function<E, V> valueExtractor) {
}

interface PairExtractor<E> {
<N> N getName(E element);
<V> V getValue(E element);
static <T> PairExtractor<T> of(Function<T, ?> nameExtractor, Function<T, ?> valueExtractor) {
return new PairExtractor<>() {

@Override
@SuppressWarnings("unchecked")
public <N> N getName(T instance) {
return (N) nameExtractor.apply(instance);
}

@Override
@SuppressWarnings("unchecked")
public <V> V getValue(T instance) {
return (V) valueExtractor.apply(instance);
}

};
}
}

}
"""
});
}

}
Loading