-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
NNBDIssues related to NNBD ReleaseIssues related to NNBD ReleaseP2A bug or feature request we're likely to work onA bug or feature request we're likely to work ondevexp-warningIssues with the analyzer's Warning codesIssues with the analyzer's Warning codeslegacy-area-analyzerUse area-devexp instead.Use area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)
Description
From @Hixie on August 20, 2018 23:11
If you assert that a variable of enum type is non-null before a switch, and then you have a switch where every enum value is handled and terminates (returns, throws, or exits), then it should not flag that function as not ending with a return. (The usual pattern today is to return null
after the switch to silence the analyzer, but that's what would happen anyway if the statement wasn't there, in the case of the variable being null in a release build.)
For example:
enum Foo { a, b, c }
String hello(Foo value) {
assert(value != null);
switch (value) {
case Foo.a: return 'A';
case Foo.b: return 'B';
case Foo.c: return 'C';
}
// This should not be flagged by missing_return
}
cc @a14n
Copied from original issue: dart-lang/linter#1139
kika, jamesderlin, numen31337, mdebbar, tvolkert and 8 more
Metadata
Metadata
Assignees
Labels
NNBDIssues related to NNBD ReleaseIssues related to NNBD ReleaseP2A bug or feature request we're likely to work onA bug or feature request we're likely to work ondevexp-warningIssues with the analyzer's Warning codesIssues with the analyzer's Warning codeslegacy-area-analyzerUse area-devexp instead.Use area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)