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() {