Hint for missing return when the function is guaranteed to throw #21741
Labels
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
P2
A bug or feature request we're likely to work on
type-enhancement
A request for a change that isn't a bug
This issue was originally filed by greg...@gmail.com
Ideally the analyzer would not generate a hint for the function below:
//Hint: This function declares the return type of 'int' but does not end with a return statement.
int foo() {
bar() => throw "oi";
bar();
}
Here's the actual function that I was writing when I noticed this.
Duration _parseWithSuffix(String s) {
fail(s) => throw new FormatException('Cannot parse string as duration: "$s".');
parsePrefix(s, [int suffixLen = 1])
=> int.parse(s.substring(0, s.length-suffixLen), onError: fail);
if (s.endsWith('h')) return new Duration(hours: parsePrefix(s));
if (s.endsWith('m')) return new Duration(minutes: parsePrefix(s));
if (s.endsWith('s')) return new Duration(seconds: parsePrefix(s));
if (s.endsWith('ms')) return new Duration(milliseconds: parsePrefix(s, 2));
if (s.endsWith('us')) return new Duration(microseconds: parsePrefix(s, 2));
fail(s);
}
The text was updated successfully, but these errors were encountered: