using System;
using System.Threading.Tasks;
using System.Threading;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#nullable enable
public class A
{
[return: MaybeNull]
public IEnumerator<int> GetEnumerator() => throw null!;
}
public class B
{
[return: NotNull]
public IEnumerator<int>? GetEnumerator() => throw null!;
}
public static class C {
public static void M() {
foreach (var a in new A())
{
}
foreach (var b in new B())
{
}
}
}
Expected Behavior: warning "Dereference of a possible null reference" on foreach (var a in new A()) and not on foreach (var b in new B())
Actual Behavior: warning "Dereference of a possible null reference" on foreach (var b in new B()) and not on foreach (var a in new A())
Version Used: VS 16.6 preview 1
Steps to Reproduce:
Expected Behavior: warning "Dereference of a possible null reference" on
foreach (var a in new A())
and not onforeach (var b in new B())
Actual Behavior: warning "Dereference of a possible null reference" on
foreach (var b in new B())
and not onforeach (var a in new A())