You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Fact]
public void ImplicitConversions_07()
{
var source =
@"class A<T>
{
}
class B<T>
{
public static implicit operator A<T>(B<T> b) => throw null;
}
class C
{
static B<T> F<T>(T t) => throw null;
static void G(A<object?> a) => throw null;
static void Main(object? x)
{
var y = F(x);
G(y); // warning
if (x == null) return;
var z = F(x);
G(z); // ok
}
}";
var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
// PROTOTYPE(NullableReferenceTypes): Several issues with implicit user-defined conversions and
// nested nullability: should report `'A<object?>' doesn't match ... 'A<object>'` rather than
// `'A<object>' doesn't match ... 'A<object?>'`; should report warning for `G(y)` only, not `G(z)`
// (see NullabilityWalker.ApplyConversion).
comp.VerifyDiagnostics(
// (15,11): warning CS8620: Nullability of reference types in argument of type 'A<object>' doesn't match target type 'A<object?>' for parameter 'a' in 'void C.G(A<object?> a)'.
// G(y); // warning
Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "y").WithArguments("A<object>", "A<object?>", "a", "void C.G(A<object?> a)").WithLocation(15, 11),
// (18,11): warning CS8620: Nullability of reference types in argument of type 'A<object>' doesn't match target type 'A<object?>' for parameter 'a' in 'void C.G(A<object?> a)'.
// G(z); // ok
Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "z").WithArguments("A<object>", "A<object?>", "a", "void C.G(A<object?> a)").WithLocation(18, 11));
}
The text was updated successfully, but these errors were encountered:
I am not sure if the expectations stated in the comment are correct. It feels like the warning reported for G(z) is correct and there should be no warning for G(y).
The text was updated successfully, but these errors were encountered: