Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Unified Diff: pkg/analyzer/test/src/task/strong/checker_test.dart

Issue 1823793002: Better casting of for-in loops. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Handle supertypes of Iterable and Stream. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/src/task/strong/checker_test.dart
diff --git a/pkg/analyzer/test/src/task/strong/checker_test.dart b/pkg/analyzer/test/src/task/strong/checker_test.dart
index 09738bd19cc465d46b5df8ec364984d366c1ef7a..8c4eb3c82dd9fcab823fb72710377df12ffece80 100644
--- a/pkg/analyzer/test/src/task/strong/checker_test.dart
+++ b/pkg/analyzer/test/src/task/strong/checker_test.dart
@@ -87,6 +87,73 @@ void main() {
''');
});
+ test('for-in casts supertype sequence to iterable', () {
+ checkFile('''
+ main() {
+ dynamic d;
+ for (var i in /*info:DYNAMIC_CAST*/d) {}
+
+ Object o;
+ for (var i in /*info:DOWN_CAST_IMPLICIT*/o) {}
+ }
+ ''');
+ });
+
+ test('await for-in casts supertype sequence to stream', () {
+ checkFile('''
+ main() async {
+ dynamic d;
+ await for (var i in /*info:DYNAMIC_CAST*/d) {}
+
+ Object o;
+ await for (var i in /*info:DOWN_CAST_IMPLICIT*/o) {}
+ }
+ ''');
+ });
+
+ test('for-in casts iterable element to variable', () {
+ checkFile('''
+ main() {
+ // Don't choke if sequence is not iterable.
+ for (var i in /*warning:FOR_IN_OF_INVALID_TYPE*/1234) {}
+
+ // Dynamic cast.
+ for (String /*info:DYNAMIC_CAST*/s in <dynamic>[]) {}
+
+ // Identity cast.
+ for (String s in <String>[]) {}
+
+ // Untyped.
+ for (var s in <String>[]) {}
+
+ // Downcast.
+ for (int /*info:DOWN_CAST_IMPLICIT*/i in <num>[]) {}
+ }
+ ''');
+ });
+
+ test('await for-in casts stream element to variable', () {
+ checkFile('''
+ import 'dart:async';
+ main() async {
+ // Don't choke if sequence is not stream.
+ await for (var i in /*warning:FOR_IN_OF_INVALID_TYPE*/1234) {}
+
+ // Dynamic cast.
+ await for (String /*info:DYNAMIC_CAST*/s in new Stream<dynamic>()) {}
+
+ // Identity cast.
+ await for (String s in new Stream<String>()) {}
+
+ // Untyped.
+ await for (var s in new Stream<String>()) {}
+
+ // Downcast.
+ await for (int /*info:DOWN_CAST_IMPLICIT*/i in new Stream<num>()) {}
+ }
+ ''');
+ });
+
test('dynamic invocation', () {
checkFile('''
class A {
« no previous file with comments | « pkg/analyzer/test/src/context/mock_sdk.dart ('k') | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698