// Note: pattern-based async disposal is not allowed (cannot use ref structs in async methods), so the arguments are known to be empty even for async case
// (7,9): error CS4032: The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task<IAsyncEnumerator<int>>'.
// (4,74): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
// public static async System.Collections.Generic.IAsyncEnumerable<int> M()
// (4,62): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token)
public Enumerator GetAsyncEnumerator()
=> throw null;
public sealed class Enumerator
{
...
...
@@ -317,9 +317,9 @@ public int Current
}";
varcomp=CreateCompilationWithMscorlib46(source);
comp.VerifyDiagnostics(
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator(CancellationToken)' must have a suitable public 'MoveNextAsync' method and public 'Current' property
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator()' must have a suitable public 'MoveNextAsync' method and public 'Current' property
@@ -335,7 +335,7 @@ await foreach (var i in new C())
{
}
}
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token) => throw null;
public Enumerator GetAsyncEnumerator() => throw null;
public sealed class Enumerator
{
public System.Threading.Tasks.Task<object> MoveNextAsync() => throw null; // returns Task<object>
...
...
@@ -344,9 +344,9 @@ public sealed class Enumerator
}";
varcomp=CreateCompilationWithMscorlib46(source);
comp.VerifyDiagnostics(
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator(CancellationToken)' must have a suitable public 'MoveNextAsync' method and public 'Current' property
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator()' must have a suitable public 'MoveNextAsync' method and public 'Current' property
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token)
public Enumerator GetAsyncEnumerator()
=> throw null;
public sealed class Enumerator
{
...
...
@@ -410,9 +410,9 @@ public static int Current
}";
varcomp=CreateCompilationWithMscorlib46(source);
comp.VerifyDiagnostics(
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator(CancellationToken)' must have a suitable public 'MoveNextAsync' method and public 'Current' property
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator()' must have a suitable public 'MoveNextAsync' method and public 'Current' property
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token)
public Enumerator GetAsyncEnumerator()
=> throw null;
public sealed class Enumerator
{
...
...
@@ -438,9 +438,9 @@ public int Current
}";
varcomp=CreateCompilationWithMscorlib46(source);
comp.VerifyDiagnostics(
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator(CancellationToken)' must have a suitable public 'MoveNextAsync' method and public 'Current' property
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator()' must have a suitable public 'MoveNextAsync' method and public 'Current' property
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token)
public Enumerator GetAsyncEnumerator()
=> throw null;
public sealed class Enumerator
{
...
...
@@ -502,9 +502,9 @@ public int Current
}";
varcomp=CreateCompilationWithMscorlib46(source);
comp.VerifyDiagnostics(
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator(CancellationToken)' must have a suitable public 'MoveNextAsync' method and public 'Current' property
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator()' must have a suitable public 'MoveNextAsync' method and public 'Current' property
public static async System.Threading.Tasks.Task Main()
{
await foreach (var i in new C())
{
}
}
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token)
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token = default)
{
throw null;
return new Enumerator();
}
public sealed class Enumerator
{
public System.Threading.Tasks.Task<bool> MoveNextAsync(int bad = 0)
public async System.Threading.Tasks.Task<bool> MoveNextAsync(int ok = 0)
{
throw null;
System.Console.Write(""MoveNextAsync"");
await System.Threading.Tasks.Task.Yield();
return false;
}
public int Current
{
...
...
@@ -638,12 +640,44 @@ public int Current
}
}
}";
varcomp=CreateCompilationWithMscorlib46(source);
comp.VerifyDiagnostics(
// (6,33): error CS8412: Asynchronous foreach requires that the return type 'C.Enumerator' of 'C.GetAsyncEnumerator(CancellationToken)' must have a suitable public 'MoveNextAsync' method and public 'Current' property
@@ -1203,6 +1238,7 @@ public static C.Enumerator GetAsyncEnumerator(this C c)
throw null;
}
}";
// Pattern-based lookup does not bind extension methods at the moment
varcomp=CreateCompilationWithMscorlib46(source);
comp.VerifyDiagnostics(
// (6,33): error CS8411: Async foreach statement cannot operate on variables of type 'C' because 'C' does not contain a public definition for 'GetAsyncEnumerator'
...
...
@@ -1222,6 +1258,7 @@ void M()
foreach (var i in new C())
{
}
_ = (new C()).GetEnumerator();
}
public sealed class Enumerator
{
...
...
@@ -1233,6 +1270,7 @@ public static class Extensions
{
public static C.Enumerator GetEnumerator(this C self) => throw null;
}";
// Pattern-based lookup does not bind extension methods at the moment
varcomp=CreateCompilationWithMscorlib46(source);
comp.VerifyDiagnostics(
// (6,27): error CS1579: foreach statement cannot operate on variables of type 'C' because 'C' does not contain a public definition for 'GetEnumerator'
...
...
@@ -1253,7 +1291,7 @@ await foreach (var i in new C())
{
}
}
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token)
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token = default)
{
throw null;
}
...
...
@@ -1364,7 +1402,7 @@ void M()
{
}
}
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token) => throw null;
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token = default) => throw null;
public sealed class Enumerator
{
public System.Threading.Tasks.Task<bool> MoveNextAsync() => throw null;
...
...
@@ -1438,7 +1476,7 @@ void M()
{
}
}
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token)
public Enumerator GetAsyncEnumerator(System.Threading.CancellationToken token = default)
=> throw null;
public sealed class Enumerator
{
...
...
@@ -1456,32 +1494,33 @@ public System.Threading.Tasks.Task<bool> MoveNextAsync()
// (6,33): error CS8411: Asynchronous foreach statement cannot operate on variables of type 'C' because 'C' does not contain a suitable public instance definition for 'GetAsyncEnumerator'
// (6,33): error CS8412: Async foreach requires that the return type 'D.Enumerator' of 'D.GetAsyncEnumerator(System.Threading.CancellationToken)' must have a suitable public MoveNextAsync method and public Current property
// (6,33): error CS8412: Async foreach requires that the return type 'D.Enumerator' of 'D.GetAsyncEnumerator()' must have a suitable public MoveNextAsync method and public Current property
// (8,33): error CS8411: Asynchronous foreach statement cannot operate on variables of type 'C' because 'C' does not contain a suitable public instance definition for 'GetAsyncEnumerator'