Closed
Description
Why run-time type of the variable from the below is Future
?
import "dart:async";
FutureOr<Stream<int>?> f1() async* {
yield 1;
yield 2;
yield 3;
}
main() async {
Stream<int>? res1 = await f1();
List<int>? it1 = await res1?.toList();
print(it1 is List<int>?); // Analyzer: Unnecessary type check; the result is always 'true'.
// Prints `false`
print(it1.runtimeType); // Future<List<dynamic>>
}
Ok, the fact that type of it1
is List<dynamic>
instead of List<int>
is a known issue described here. But why it is Future
?
Note that if to remove nullability issue connected with the Future
disappers
import "dart:async";
FutureOr<Stream<int>> f1() async* {
yield 1;
yield 2;
yield 3;
}
main() async {
Stream<int> res1 = await f1();
List<int> it1 = await res1.toList();
print(it1 is List<int>); // Analyzer: Unnecessary type check; the result is always 'true'.
// Prints `false`
print(it1.runtimeType); // List<dynamic>
}
Tested on Dart SDK version: 3.1.0-333.0.dev (dev) (Thu Jul 20 13:04:10 2023 -0700) on "windows_x64"