-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report obsolete DisposeAsync method in await foreach
- Loading branch information
Showing
6 changed files
with
243 additions
and
12 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
docs/compilers/CSharp/Compiler Breaking Changes - DotNet 10.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This document lists known breaking changes in Roslyn after .NET 9 all the way to .NET 10. | ||
|
||
## Diagnostic now reported for improper use of pattern-based disposal method in `foreach` | ||
|
||
***Introduced in Visual Studio 2022 version 17.13*** | ||
|
||
For instance, an obsolete `DisposeAsync` method is now reported in `await foreach`. | ||
```csharp | ||
await foreach (var i in new C()) { } // 'C.AsyncEnumerator.DisposeAsync()' is obsolete | ||
class C | ||
{ | ||
public AsyncEnumerator GetAsyncEnumerator(System.Threading.CancellationToken token = default) | ||
{ | ||
throw null; | ||
} | ||
|
||
public sealed class AsyncEnumerator : System.IAsyncDisposable | ||
{ | ||
public int Current { get => throw null; } | ||
public Task<bool> MoveNextAsync() => throw null; | ||
|
||
[System.Obsolete] | ||
public ValueTask DisposeAsync() => throw null; | ||
} | ||
} | ||
``` | ||
|
||
Similarly, an `[UnmanagedCallersOnly]` `Dispose` method is now reported in `foreach` with a `ref struct` enumerator. | ||
```csharp | ||
public struct S | ||
{ | ||
public static void M2(S s) | ||
{ | ||
foreach (var i in s) { } // 'SEnumerator.Dispose()' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. | ||
} | ||
public static SEnumerator GetEnumerator() => throw null; | ||
} | ||
public ref struct SEnumerator | ||
{ | ||
public bool MoveNext() => throw null; | ||
public int Current => throw null; | ||
[UnmanagedCallersOnly] | ||
public void Dispose() => throw null; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters