Sdk: Confusing messages with await_only_futures, unnecessary_parenthesis and futures with ternary operator

Created on 27 Jun 2018  路  4Comments  路  Source: dart-lang/sdk

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?

P2 analyzer-linter area-analyzer type-bug

Most helpful comment

The one that is definitely wrong is the unnecessary parentheses warning.

awaitExpression ::= await unaryExpression

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".

All 4 comments

The one that is definitely wrong is the unnecessary parentheses warning.

awaitExpression ::= await unaryExpression

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

Was this page helpful?
0 / 5 - 0 ratings