linter:
rules:
- await_only_futures
- unnecessary_parenthesis
import 'dart:async';
main() async {
bool cond = true;
await (cond ? Future<void>.value(true) : Future<void>.value(true));
await cond ? Future<void>.value(true) : Future<void>.value(true);
}
I'm sure one of those await lines should be valid, but the first one warns Unnecessary parenthesis can be removed. and the second one warns Await only futures.. I think one of them may be wrong?
The one that is definitely wrong is the unnecessary parentheses warning.
awaitExpression ::=
awaitunaryExpression
and conditionalExpression is not a unary expression.
While you can remove the parentheses, it's still syntactically valid, it won't mean the same thing any more. It'll be (await cond) ? ... or even awaiting some initial sub-expression of cond, if cond was a more complex expression. In that case you are awaiting a non-future, so that warning is correct.
Ob-nitpick: It should probably say "Unnecessary parentheses can be removed" - removing just one isn't going to work :) Or "Unnecessary parenthesization".
I cannot reproduce a report on the first await line. unnecessary_parenthesis was fixed perhaps?
I also can't repro on SDK v2.1 either. There have been changed to unnecessary_parenthesis since I opened this, so maybe it was one of those.
It was fixed by 51b8fc7
Most helpful comment
The one that is definitely wrong is the unnecessary parentheses warning.
and conditionalExpression is not a unary expression.
While you can remove the parentheses, it's still syntactically valid, it won't mean the same thing any more. It'll be
(await cond) ? ...or even awaiting some initial sub-expression ofcond, ifcondwas a more complex expression. In that case you are awaiting a non-future, so that warning is correct.Ob-nitpick: It should probably say "Unnecessary parentheses can be removed" - removing just one isn't going to work :) Or "Unnecessary parenthesization".