dotnet/roslyn

Consider new warning for unobserved async-iterator call

オープン

#33,939 opened on 2019/03/07

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-CompilersBugConcept-Diagnostic ClarityFeature - Async Streamshelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

Version Used: 3.0.19.12206 (ec366687)

Steps to Reproduce: Compile the following code:

using System.Collections.Generic;
using System.Threading.Tasks;

class C
{
  async IAsyncEnumerable<int> ProduceAsync()
  {
    await Task.CompletedTask;
    yield return 42;
  }

  void Consume()
  {
    ProduceAsync(); // currently emits WRN_UnobservedAwaitableExpression
  }
}

Expected Behavior:

Emit new warning with text like "Because result of asynchronous iterator call is not being iterated, execution of the current method continues before the call is completed. Consider using the 'await foreach' over the result of the call." For async-iterators returning IAsyncEnumerator<T> the second sentence may be omitted. Or maybe you'll come up with better wording which will work for both cases :)

Actual Behavior:

The warning "CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call" is emitted. But it's somewhat misleading.

コントリビューターガイド