未验证 提交 acfc61d0 编写于 作者: C Chris Sienkiewicz 提交者: GitHub

Add test for #34921 (#39365)

上级 c40b14c7
......@@ -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>
{
T P { get; }
}
class C<T>
{
internal T F = default!;
}
class Program
{
static void F1<T>(I<(T, T)> i) where T : class?
{
var t = i.P;
t.Item1.ToString(); // 1
}
static void F2<T>(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)
);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册