From 30fbb28714b2dff8d5eb70e7d2b4d66a46d515d8 Mon Sep 17 00:00:00 2001 From: FMorschel Date: Tue, 19 Aug 2025 07:47:37 -0700 Subject: [PATCH] [DAS] Fixes `switch_on_type` for `dynamic` Fixes: https://github.com/dart-lang/sdk/issues/61355 Change-Id: I306e825a20a93910a72c3208596f6d21d82d1ef3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445921 Auto-Submit: Felipe Morschel Reviewed-by: Samuel Rawlins Commit-Queue: Brian Wilkerson Reviewed-by: Brian Wilkerson Commit-Queue: Samuel Rawlins --- pkg/linter/lib/src/rules/switch_on_type.dart | 2 +- pkg/linter/test/rules/switch_on_type_test.dart | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/linter/lib/src/rules/switch_on_type.dart b/pkg/linter/lib/src/rules/switch_on_type.dart index 259593051c2..17f36deaae7 100644 --- a/pkg/linter/lib/src/rules/switch_on_type.dart +++ b/pkg/linter/lib/src/rules/switch_on_type.dart @@ -69,7 +69,7 @@ class _Visitor extends SimpleAstVisitor { /// Returns `true` if the [type] is assignable to [Type]. bool _isAssignableToType(DartType? type) { - if (type == null) return false; + if (type == null || type is DynamicType) return false; return context.typeSystem.isAssignableTo(type, _typeType); } diff --git a/pkg/linter/test/rules/switch_on_type_test.dart b/pkg/linter/test/rules/switch_on_type_test.dart index 6791a061d34..98b372d7fb6 100644 --- a/pkg/linter/test/rules/switch_on_type_test.dart +++ b/pkg/linter/test/rules/switch_on_type_test.dart @@ -60,6 +60,14 @@ void f(Type t) { ); } + Future test_dynamic() async { + await assertNoDiagnostics(''' +void foo(dynamic a) { + switch (a) {} +} +'''); + } + Future test_functionToString() async { await assertNoDiagnostics(''' void f() {