GeezerVison is showing github.com — Crash when a diamond is in a lambda · Issue #8047 · typetools/checker-framework
Crash when a diamond is in a lambda #8047
Description
The following was reduced from a crash in Beam.
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* A diamond {@code new Adapter<>(...)} appearing in a lambda body, where {@code Adapter} is the
* enclosing class and so its type variable {@code T} is in scope, crashed inference in {@code
* StructuralEqualityComparer} with "unexpected combination". Reduced from Apache Beam's {@code
* UnboundedReadFromBoundedSource.BoundedToUnboundedSourceAdapter.split}.
*/
public class DiamondInLambdaCrash {
static class Adapter<T> {
Adapter(T t) {}
List<Adapter<T>> viaStream(Stream<T> s) {
return s.map(input -> new Adapter<>(input)).collect(Collectors.toList());
}
List<Adapter<T>> viaList(List<T> l) {
return l.stream().map(input -> new Adapter<>(input)).collect(Collectors.toList());
}
// Spelling out the type argument instead of using a diamond did not crash.
List<Adapter<T>> explicitTypeArgument(Stream<T> s) {
return s.map(input -> new Adapter<T>(input)).collect(Collectors.toList());
}
}
// The same shape without any JDK stream classes.
interface Str<E> {
<R> Str<R> map(Function<? super E, ? extends R> f);
<X> X collect(Coll<? super E, X> c);
}
interface Coll<E, X> {}
static <Y> Coll<Y, List<Y>> toList() {
throw new RuntimeException();
}
static class Wrapper<T> {
Wrapper(T t) {}
List<Wrapper<T>> f(Str<T> s) {
return s.map(input -> new Wrapper<>(input)).collect(toList());
}
}
// The diamond class differing from the enclosing class did not crash.
static class Other<T> {}
static class Holder<T> {
List<Other<T>> f(Stream<T> s) {
return s.map(input -> new Other<T>()).collect(Collectors.toList());
}
}
}
Metadata
Metadata
Development
No branches or pull requestsIssue actions