Skip to content

VSTHRD100 detects async void local functions and lamdas - #1075

Merged
Andrew Arnott (AArnott) merged 4 commits into
microsoft:mainfrom
drewnoakes:fix-1074-async-void
Jul 25, 2022
Merged

VSTHRD100 detects async void local functions and lamdas#1075
Andrew Arnott (AArnott) merged 4 commits into
microsoft:mainfrom
drewnoakes:fix-1074-async-void

Conversation

@drewnoakes

Copy link
Copy Markdown
Member

Fixes #1074

@drewnoakes

Copy link
Copy Markdown
Member Author

I cannot reproduce the CI test failures locally. I suspect the compiler version is at play here.


class Test {
void M() {
F(async void () => await Task.Delay(0));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid syntax, and the cause for the test failure in CI. You mentioned you couldn't repro it locally, but that really surprises me, since it isn't valid in any version of the language or compiler AFAIK. Even Sharplab shows this failing.

If you just remove the void modifier (which lambdas aren't allowed to specify), it works.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In C# 10 it's possible to specify the return type of a lambda in code:

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-expressions#explicit-return-type

That Sharplab code works if you set the compiler to main and the output to something other than ASM:

https://sharplab.io/#v2:EYLgtghglgdgPgAQEwEYCwAoBAGABAlAVgG5NNlcAVAUwGcAXXAb01zfwBZcBZACgEpmrdiIBivBAA5OuAbgC8APnwBOfADYAdABFqAGwgBPXtn79SGYSLYIu4gklwRBTAL5Xc7jF6A=

I think the problem in this case is the version of the compiler being used differs in CI from what I have locally (int.main).

Removing the explicit return type is fine however, as it's optional in that case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very strange, and disappointing that the tests aren't effectively pinning whatever versions vary between our official builds and your local build. We are pinning the compiler. I would have thought the langversion was effectively pinned as well.

@drewnoakes

Copy link
Copy Markdown
Member Author

Andrew Arnott (@AArnott) would you expect this in 17.4.10-alpha? I just tried pulling it down and don't see diagnostics on async void local functions.

image

@AArnott

Copy link
Copy Markdown
Member

Your change only went into 17.4.14-alpha.

@AArnott

Copy link
Copy Markdown
Member

We only push packages to the feed you found 17.4.10-alpha nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VSTHRD100 (avoid async void) doesn't work for local functions

2 participants