diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index e739df84e60d7..f30ef320c8e54 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -68858,7 +68858,6 @@ void M0(object? x0, T z0) ref T M2(T x) => throw null!; } "; - // https://github.com/dotnet/roslyn/issues/30952 - Expect WRN_NullReferenceAssignment for [M2(y0) = z0;] CreateCompilation(source, options: WithNonNullTypesTrue()).VerifyDiagnostics(); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesVsPatterns.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesVsPatterns.cs index 322e899ec1776..c646673548301 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesVsPatterns.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesVsPatterns.cs @@ -547,19 +547,18 @@ static void G(object? x) [Fact] public void IsDeclarationPattern_01() { - // https://github.com/dotnet/roslyn/issues/30952: `is` declaration does not set not nullable for declared local. var source = @"class Program { - //static void F1(object x1) - //{ - // if (x1 is string y1) - // { - // x1/*T:object!*/.ToString(); - // y1/*T:string!*/.ToString(); - // } - // x1/*T:object!*/.ToString(); - //} + static void F1(object x1) + { + if (x1 is string y1) + { + x1/*T:object!*/.ToString(); + y1/*T:string!*/.ToString(); + } + x1/*T:object!*/.ToString(); + } static void F2(object? x2) { if (x2 is string y2) @@ -743,6 +742,7 @@ static void F2(object? x2) } [Fact] + [WorkItem(30952, "https://github.com/dotnet/roslyn/issues/30952")] public void IsDeclarationPattern_NeverNull_02() { var source = @@ -754,10 +754,10 @@ static void F1(T t1) { if (t1 is U u1) { - t1?.ToString(); // 1 - u1?.ToString(); // 2 + t1.ToString(); + u1.ToString(); } - t1?.ToString(); // 3 + t1.ToString(); } static void F2(T t2) where T : class? @@ -765,16 +765,17 @@ static void F2(T t2) { if (t2 is U u2) { - t2?.ToString(); // 4 - u2?.ToString(); // 5 + t2.ToString(); + u2.ToString(); } - t2?.ToString(); + t2.ToString(); // 1 } }"; - // https://github.com/dotnet/roslyn/issues/30952: `is` declaration does not set not nullable for declared local. var comp = CreateCompilation(source, options: WithNonNullTypesTrue()); comp.VerifyDiagnostics( - ); + // (23,9): warning CS8602: Possible dereference of a null reference. + // t2.ToString(); // 2 + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t2").WithLocation(23, 9)); } [Fact]