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

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: 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..678af6163c19001fc6c82e1aaf2f9a94930f895a 100644
--- a/pkg/analyzer/test/src/task/strong/checker_test.dart
+++ b/pkg/analyzer/test/src/task/strong/checker_test.dart
@@ -87,6 +87,49 @@ void main() {
''');
});
+ 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>[]) {}
vsm 2016/03/21 21:25:20 nice!
Bob Nystrom 2016/03/21 22:44:55 \o/
+ }
+ ''');
+ });
+
+ 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 {

Powered by Google App Engine
This is Rietveld 408576698