Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UseValueTasksCorrectlyAnalyzer throws ArgumentNullException #3642

Closed
DavidZidar opened this issue May 19, 2020 · 2 comments · Fixed by #3643
Closed

UseValueTasksCorrectlyAnalyzer throws ArgumentNullException #3642

DavidZidar opened this issue May 19, 2020 · 2 comments · Fixed by #3643
Assignees
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design

Comments

@DavidZidar
Copy link

Analyzer package

Microsoft.CodeAnalysis.FxCopAnalyzers

Package Version

v3.0.0 (Latest)

Diagnostic ID

CA2012 UseValueTasksCorrectlyAnalyzer

Repro steps

using System;
using System.Threading.Tasks;

class C
{
    public void GuardThenAssignVariable()
    {
        if (false) throw new Exception();
        var vt = Helpers.ReturnsValueTask();
    }
}

Expected behavior

UseValueTasksCorrectly should not throw.

Actual behavior

An async method with a guard clause that throws an exception in combination with storing ValueTask in a variable causes UseValueTasksCorrectlyAnalyzer to throw ArgumentNullException.

It seems that block.FallThroughSuccessor.Destination is null when handling the fall through successor since it is a throw expression which results in the call to seen.TryGetValue throw
ArgumentNullException because the key is a null value.

@mavasani mavasani added Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design labels May 19, 2020
@stephentoub
Copy link
Member

Thanks for reporting this.

@DavidZidar
Copy link
Author

No problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants