Add more tests, adjust existing baseline.

上级 c53fa479
......@@ -2595,9 +2595,6 @@ void M(in object o1, out object o2)
}";
CreateCompilation(source).VerifyDiagnostics(
// (4,10): error CS0177: The out parameter 'o2' must be assigned to before control leaves the current method
// void M(in object o1, out object o2)
Diagnostic(ErrorCode.ERR_ParamUnassigned, "M").WithArguments("o2").WithLocation(4, 10),
// (6,9): error CS8331: Cannot assign to variable 'in object' because it is a readonly variable
// o1 ??= null;
Diagnostic(ErrorCode.ERR_AssignReadonlyNotField, "o1").WithArguments("variable", "in object").WithLocation(6, 9),
......
......@@ -108754,12 +108754,12 @@ void M1(int? i)
[Fact]
[WorkItem(41273, "https://github.com/dotnet/roslyn/issues/41273")]
public void NullCoalescingAssignment_InTryFinally()
public void NullCoalescingAssignment_InTryCatchFinally01()
{
var source = @"
using System;
public class C {
public class C
{
string x;
public C()
......@@ -108779,6 +108779,121 @@ public C()
comp.VerifyDiagnostics();
}
[Fact]
[WorkItem(41273, "https://github.com/dotnet/roslyn/issues/41273")]
public void NullCoalescingAssignment_InTryCatchFinally02()
{
var source = @"
using System;
public class C
{
string x;
public C()
{
try
{
}
catch (Exception)
{
x ??= """";
}
}
}";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (7,12): warning CS8618: Non-nullable field 'x' is uninitialized. Consider declaring the field as nullable.
// public C()
Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "C").WithArguments("field", "x").WithLocation(7, 12)
);
}
[Fact]
[WorkItem(41273, "https://github.com/dotnet/roslyn/issues/41273")]
public void NullCoalescingAssignment_InTryCatchFinally03()
{
var source = @"
public class C {
string x;
public C()
{
try
{
}
finally
{
x ??= """";
}
}
}";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics();
}
[Fact]
[WorkItem(41273, "https://github.com/dotnet/roslyn/issues/41273")]
public void NullCoalescingAssignment_InTryCatchFinally04()
{
var source = @"
public class C
{
string x;
public C()
{
try
{
x = """";
}
finally
{
x ??= null;
}
}
}";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (14,19): warning CS8625: Cannot convert null literal to non-nullable reference type.
// x ??= null;
Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(14, 19)
);
}
[Fact]
[WorkItem(41273, "https://github.com/dotnet/roslyn/issues/41273")]
public void NullCoalescingAssignment_InTryCatchFinally05()
{
var source = @"
using System;
public class C
{
string x;
public C()
{
try
{
x = """";
}
catch (Exception)
{
x ??= null;
}
}
}";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (15,19): warning CS8625: Cannot convert null literal to non-nullable reference type.
// x ??= null;
Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(15, 19)
);
}
[Fact]
public void Deconstruction_01()
{
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册