-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersBugFeature - Nullable Reference TypesNullable Reference TypesNullable Reference TypesLanguage-C#
Milestone
Description
[Fact]
public void TupleTypeInference_06()
{
var source =
@"class C
{
static void F(object? x, object? y)
{
if (y != null)
{
((object? x, object? y), object? z) t = ((x, y), y);
t.Item1.Item1.ToString();
t.Item1.Item2.ToString();
t.Item2.ToString();
t.Item1.x.ToString();
t.Item1.y.ToString();
t.z.ToString();
}
}
}";
var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
// PROTOTYPE(NullableReferenceTypes): Should not report warning for
// `t.Item1.Item2`, `t.Item2`, `t.Item1.y`, or `t.z`.
comp.VerifyDiagnostics(
// (8,13): warning CS8602: Possible dereference of a null reference.
// t.Item1.Item1.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item1.Item1").WithLocation(8, 13),
// (9,13): warning CS8602: Possible dereference of a null reference.
// t.Item1.Item2.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item1.Item2").WithLocation(9, 13),
// (10,13): warning CS8602: Possible dereference of a null reference.
// t.Item2.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item2").WithLocation(10, 13),
// (11,13): warning CS8602: Possible dereference of a null reference.
// t.Item1.x.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item1.x").WithLocation(11, 13),
// (12,13): warning CS8602: Possible dereference of a null reference.
// t.Item1.y.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item1.y").WithLocation(12, 13),
// (13,13): warning CS8602: Possible dereference of a null reference.
// t.z.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.z").WithLocation(13, 13));
}
Related to #29699 (should conversion warnings be reported on elements or the whole tuple?)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-CompilersBugFeature - Nullable Reference TypesNullable Reference TypesNullable Reference TypesLanguage-C#