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

Analyzer failure when checking parenthesized expression #849

Closed
wazzamatazz opened this issue May 20, 2021 · 0 comments · Fixed by #865
Closed

Analyzer failure when checking parenthesized expression #849

wazzamatazz opened this issue May 20, 2021 · 0 comments · Fixed by #865

Comments

@wazzamatazz
Copy link

Bug description

I observed an analyzer failure in my build log following some changes that a colleague had committed to a codebase. In the committed code, there were some esoteric but syntactically valid await statements such as:

await (queryClient.GetTagRecord(name, cancellationToken).ConfigureAwait(false));

When trying to analyze the above statement the following analyzer failure was observed, caused by the parentheses around the expression that is being awaited:

warning AD0001: Analyzer 'Microsoft.VisualStudio.Threading.Analyzers.VSTHRD003UseJtfRunAsyncAnalyzer' threw an exception of type 'System.Exception' with message 'Analyzer failure while processing syntax at C:\Redacted\SomeFile.cs(XXX,YY): 
System.InvalidCastException Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.ParenthesizedExpressionSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax'.. 
Syntax: await (queryClient.GetTagRecord(name, cancellationToken).ConfigureAwait(false))'.

Repro steps

Add an await statement to a program that encloses the asynchronous operation in parentheses, as shown above.

Expected behavior

Since the syntax is valid, the analyzer should accommodate this without throwing an error.

Actual behavior

The analyzer failed because of an assumption about the type of expression it had encountered.

  • Version used: 16.9.60
  • Application (if applicable): VS 2019 16.9.6

Additional context

The syntax used is unusual, and is very easy to fix in the offending code, so this is very much on the "very minor annoyance" end of the severity scale!

bluetarpmedia added a commit to bluetarpmedia/vs-threading that referenced this issue Jun 15, 2021
…f the invocation is wrapped inside parentheses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants