Skip to content

Commit 9f82850

Browse files
Ignore new unreachable_switch_default warning. (#2318)
The Dart analyzer will soon be changed so that if the `default` clause of a `switch` statement is determined to be unreachable by the exhaustiveness checker, a new warning of type `unreachable_switch_default` will be issued. This parallels the behavior of the existing `unreachable_switch_case` warning, which is issued whenever a `case` clause of a `switch` statement is determined to be unreachable. In the vast majority of cases, the most reasonable way to address the warning is to remove the unreachable `default` clause. However, in a few rare cases, the `default` clause must be kept, due to the fact that flow analysis is not as sophisticated as exhaustiveness checking (see dart-lang/language#2977 for details). Two of these rare cases crop up in dart-sass. This change adds `ignore` comments to avoid a spurious warning, and adds a comment explaining why the `default` clause needs to be kept.
1 parent 798cd7c commit 9f82850

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/src/functions/map.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ final _set = BuiltInCallable.overloadedFunction("set", {
6161
throw SassScriptException("Expected \$args to contain a value.");
6262
case [...var keys, var value]:
6363
return _modify(map, keys, (_) => value);
64-
default:
64+
default: // ignore: unreachable_switch_default
65+
// This code is unreachable, and the compiler knows it (hence the
66+
// `unreachable_switch_default` warning being ignored above). However,
67+
// due to architectural limitations in the Dart front end, the compiler
68+
// doesn't understand that the code is unreachable until late in the
69+
// compilation process (after flow analysis). So this `default` clause
70+
// must be kept around to avoid flow analysis incorrectly concluding
71+
// that the function fails to return. See
72+
// https://github.com/dart-lang/language/issues/2977 for details.
6573
throw '[BUG] Unreachable code';
6674
}
6775
},
@@ -87,7 +95,15 @@ final _merge = BuiltInCallable.overloadedFunction("merge", {
8795
if (nestedMap == null) return map2;
8896
return SassMap({...nestedMap.contents, ...map2.contents});
8997
});
90-
default:
98+
default: // ignore: unreachable_switch_default
99+
// This code is unreachable, and the compiler knows it (hence the
100+
// `unreachable_switch_default` warning being ignored above). However,
101+
// due to architectural limitations in the Dart front end, the compiler
102+
// doesn't understand that the code is unreachable until late in the
103+
// compilation process (after flow analysis). So this `default` clause
104+
// must be kept around to avoid flow analysis incorrectly concluding
105+
// that the function fails to return. See
106+
// https://github.com/dart-lang/language/issues/2977 for details.
91107
throw '[BUG] Unreachable code';
92108
}
93109
},

0 commit comments

Comments
 (0)