From 43bcc5945ef9776f36c73825043934d774b76dc4 Mon Sep 17 00:00:00 2001 From: Jennifer Messerly Date: Fri, 4 Nov 2016 17:37:13 -0700 Subject: [PATCH] fix #27766, allow implicit casts from dynamic to composite types R=leafp@google.com Review URL: https://codereview.chromium.org/2477093002 . --- CHANGELOG.md | 13 +++++++++++++ pkg/analyzer/lib/src/task/strong/checker.dart | 2 +- pkg/analyzer/test/src/task/strong/checker_test.dart | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e4b6f04a3..2f5b2389d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,19 @@ Patch release, resolves one issue: * Dartium: Fixes a bug that caused crashes. No issue filed +### Strong Mode + +* It is no longer a warning when casting from dynamic to a composite type + (SDK issue [27766](https://github.com/dart-lang/sdk/issues/27766)). + + ```dart + main() { + dynamic obj = [1, 2, 3]; + // This is now allowed without a warning. + List list = obj; + } + ``` + ## 1.20.0 - 2016-10-11 ### Dart VM diff --git a/pkg/analyzer/lib/src/task/strong/checker.dart b/pkg/analyzer/lib/src/task/strong/checker.dart index e8c80c0a34f..4e2a092523c 100644 --- a/pkg/analyzer/lib/src/task/strong/checker.dart +++ b/pkg/analyzer/lib/src/task/strong/checker.dart @@ -1107,7 +1107,7 @@ class CodeChecker extends RecursiveAstVisitor { downCastComposite = typeArgs.isEmpty || typeArgs.any((t) => t.isDynamic); } else { - downCastComposite = true; + downCastComposite = !from.isDynamic; } } diff --git a/pkg/analyzer/test/src/task/strong/checker_test.dart b/pkg/analyzer/test/src/task/strong/checker_test.dart index 53d1bea19e0..6c22865f630 100644 --- a/pkg/analyzer/test/src/task/strong/checker_test.dart +++ b/pkg/analyzer/test/src/task/strong/checker_test.dart @@ -988,7 +988,7 @@ Stream bar4() async* { yield /*error:YIELD_OF_INVALID_TYPE*/new Stream baz1() async* { yield* /*info:DYNAMIC_CAST*/x; } Stream baz2() async* { yield* /*info:DYNAMIC_CAST*/x; } -Stream baz3() async* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; } +Stream baz3() async* { yield* /*info:DYNAMIC_CAST*/x; } Stream baz4() async* { yield* new Stream(); } Stream baz5() async* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new Stream(); } '''); @@ -1005,7 +1005,7 @@ Iterable bar4() sync* { yield /*error:YIELD_OF_INVALID_TYPE*/bar3(); } baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; } Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; } -Iterable baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; } +Iterable baz3() sync* { yield* /*info:DYNAMIC_CAST*/x; } Iterable baz4() sync* { yield* bar3(); } Iterable baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new List(); } ''');