diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index e99ef7e8f0f7e41bcbae3a961034820f55e8bd09..3a7eb672648a65c22ba7b219c35773dfdec0774b 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -117673,5 +117673,47 @@ await foreach (var o in Create(y)) // object y = null; // 1 Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "null").WithLocation(24, 20)); } + + [Fact] + [WorkItem(34921, "https://github.com/dotnet/roslyn/issues/34921")] + public void NullableStructMembersOfClassesAndInterfaces() + { + var source = +@"#nullable enable + +interface I +{ + T P { get; } +} + +class C +{ + internal T F = default!; +} + +class Program +{ + static void F1(I<(T, T)> i) where T : class? + { + var t = i.P; + t.Item1.ToString(); // 1 + } + + static void F2(C<(T, T)> c) where T : class? + { + var t = c.F; + t.Item1.ToString();// 2 + } +}"; + var comp = CreateCompilation(source); + comp.VerifyDiagnostics( + // (18,9): warning CS8602: Dereference of a possibly null reference. + // t.Item1.ToString(); // 1 + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item1").WithLocation(18, 9), + // (24,9): warning CS8602: Dereference of a possibly null reference. + // t.Item1.ToString();// 2 + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item1").WithLocation(24, 9) + ); + } } }