-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.core-nenhancement-breaking-changeAn enhancement which is breaking.An enhancement which is breaking.library-asynctype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Description
This has come up several times, but I don't see a bug for it.
Here's a sample use that highlights the problem:
import 'dart:async';
Stream<int> change(Stream<Iterable> stream) {
return stream.transform(new StreamTransformer<Iterable, int>.fromHandlers(
handleData: (Iterable iter, EventSink<int> sink) {
sink.add(iter.length);
}));
}
void main() {
Stream<Iterable> stream = new Stream<List<String>>.fromIterable([
["hello"],
["world"]
]);
var result = change(stream);
result.listen(print);
}The change method looks just fine from a typing perspective. However, if we invoke it with Stream<T> where T is a proper subtype of Iterable, it will trigger a confusing runtime error:
Type '_StreamHandlerTransformer<Iterable, int>' is not a subtype of type 'StreamTransformer<List<String>, int>'
Intuitively, StreamTransformer should be contravariant on it's first type parameter (Iterable here). But, Dart does not support that.
Metadata
Metadata
Assignees
Labels
area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.core-nenhancement-breaking-changeAn enhancement which is breaking.An enhancement which is breaking.library-asynctype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug