Skip to content

Commit 30fbb28

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes switch_on_type for dynamic
Fixes: #61355 Change-Id: I306e825a20a93910a72c3208596f6d21d82d1ef3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445921 Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 87b2f50 commit 30fbb28

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pkg/linter/lib/src/rules/switch_on_type.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class _Visitor extends SimpleAstVisitor<void> {
6969

7070
/// Returns `true` if the [type] is assignable to [Type].
7171
bool _isAssignableToType(DartType? type) {
72-
if (type == null) return false;
72+
if (type == null || type is DynamicType) return false;
7373
return context.typeSystem.isAssignableTo(type, _typeType);
7474
}
7575

pkg/linter/test/rules/switch_on_type_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ void f(Type t) {
6060
);
6161
}
6262

63+
Future<void> test_dynamic() async {
64+
await assertNoDiagnostics('''
65+
void foo(dynamic a) {
66+
switch (a) {}
67+
}
68+
''');
69+
}
70+
6371
Future<void> test_functionToString() async {
6472
await assertNoDiagnostics('''
6573
void f() {

0 commit comments

Comments
 (0)