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

Fix ForwardCancellationTokenAnalyzer bug on default parameter values #6616

Merged
merged 3 commits into from
Dec 2, 2022

Conversation

DavidBoike
Copy link
Member

@DavidBoike DavidBoike commented Nov 30, 2022

This fixes a bug discovered in the ForwardCancellationTokenAnalyzer and adds several more test cases.

The analyzer is supposed to ignore when you pass CancellationToken.None, but throwing an exception when doing the same thing but by using a default operator or literal which were introduced between C# 7 and 8:

// OK
await Task.Delay(100, CancellationToken.None);

// Throwing exceptions in 8.0.0
await Task.Delay(100, default(CancellationToken));
await Task.Delay(100, default);

This requires better analysis to make sure the presence of default doesn't throw it off:

public async Task SomeMethod(int a, string b, CancellationToken token = default) { }

// Would pass the 0 and null but not provide a token:
await SomeMethod(default, default);

This PR also introduces several test cases around the use of await foreach… when using async enumerables.


Backported to release-8.0 in #6617

timbussmann added a commit that referenced this pull request Dec 2, 2022
@DavidBoike DavidBoike merged commit b9b31a7 into master Dec 2, 2022
@DavidBoike DavidBoike deleted the analyzer-cases branch December 2, 2022 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants