roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

False-positive for IDE0059 when using a variable in an async local function

Open meziantou opened this issue 3 years ago • 1 comments

Version Used: Compiler version: '4.5.0-3.23075.2 (5ca760eb)'. Language version: 11.0

Steps to Reproduce:

Create a new console app with the following code:

string? token = null; // IDE0059: Unnecessary assignment of a value.
                      // If you remove "= null", you get CS0165 on Console.WriteLine
await GetValue();
Console.WriteLine(token);

async Task GetValue() => token = "test";

Note that the sync version of this code is ok:

string? token; // no need for "= null" here
GetValue();
Console.WriteLine(token);

void GetValue() => token = "test";

Diagnostic Id: IDE0059

Expected Behavior: No diagnostic is reported

Actual Behavior: IDE0059 is reported

meziantou avatar Feb 01 '23 21:02 meziantou

Marked with Area-IDE since the reported problem relates to diagnostic IDE0059. Let us know if this turns out to be a problem with underlying compiler APIs. Thanks

jcouv avatar Feb 03 '23 20:02 jcouv