Open AlekseyTs opened 6 years ago
[Fact]
public void Conversions_ImplicitTupleLiteral_ExtensionThis()
{
var source =
@"interface I<T> { }
interface IIn<in T> { }
interface IOut<out T> { }
class A<T> : I<T> { }
class B<T> : IIn<T> { }
class C<T> : IOut<T> { }
static class E
{
static void F1(string x, string? y)
{
(x, y).F1A(); // 1
(x, y).F1B();
}
static void F1A(this (object, object) t) { }
static void F1B(this (object?, object?) t) { }
static void F2(A<object> x, A<object?> y)
{
(x, y).F2A(); // 2
(x, y).F2B(); // 3
}
static void F2A(this (I<object>, I<object>) t) { }
static void F2B(this (I<object?>, I<object?>) t) { }
static void F3(B<object> x, B<object?> y)
{
(x, y).F3A();
(x, y).F3B(); // 4
}
static void F3A(this (IIn<object>, IIn<object>) t) { }
static void F3B(this (IIn<object?>, IIn<object?>) t) { }
static void F4(C<object> x, C<object?> y)
{
(x, y).F4A(); // 5
(x, y).F4B();
}
static void F4A(this (IOut<object>, IOut<object>) t) { }
static void F4B(this (IOut<object?>, IOut<object?>) t) { }
}";
var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
// PROTOTYPE(NullableReferenceTypes): Report WRN_NullabilityMismatchInArgument rather than ...Assignment.
comp.VerifyDiagnostics(
// (11,9): warning CS8620: Nullability of reference types in argument of type '(object x, object? y)' doesn't match target type '(object, object)' for parameter 't' in 'void E.F1A((object, object) t)'.
// (x, y).F1A(); // 1
Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "(x, y)").WithArguments("(object x, object? y)", "(object, object)", "t", "void E.F1A((object, object) t)").WithLocation(11, 9),
// (18,13): warning CS8619: Nullability of reference types in value of type 'A<object?>' doesn't match target type 'I<object>'.
// (x, y).F2A(); // 2
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y").WithArguments("A<object?>", "I<object>").WithLocation(18, 13),
// (19,10): warning CS8619: Nullability of reference types in value of type 'A<object>' doesn't match target type 'I<object?>'.
// (x, y).F2B(); // 3
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("A<object>", "I<object?>").WithLocation(19, 10),
// (26,10): warning CS8619: Nullability of reference types in value of type 'B<object>' doesn't match target type 'IIn<object?>'.
// (x, y).F3B(); // 4
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("B<object>", "IIn<object?>").WithLocation(26, 10),
// (32,13): warning CS8619: Nullability of reference types in value of type 'C<object?>' doesn't match target type 'IOut<object>'.
// (x, y).F4A(); // 5
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y").WithArguments("C<object?>", "IOut<object>").WithLocation(32, 13));
}
Examples: