From 661e4f1ac28f2878440f544a765e5d1af61462f0 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Fri, 20 Jul 2018 08:52:40 -0700 Subject: [PATCH] Address PR feedback (2) --- .../Portable/FlowAnalysis/NullableWalker.cs | 2 +- .../Semantics/NullableReferenceTypesTests.cs | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index 03157e5675258..d7636df83da34 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -781,7 +781,7 @@ public override BoundNode VisitIsPatternExpression(BoundIsPatternExpression node /// `switch (x) ... case Point p:` // PROTOTYPE(NullableReferenceTypes): not yet handled /// /// If the expression is trackable, we'll return with different null-states for that expression in the two conditional states. - /// If the patterns is a `var` pattern, we'll also have re-inferred the `var` type with nullability and + /// If the pattern is a `var` pattern, we'll also have re-inferred the `var` type with nullability and /// updated the state for that declared local. /// private void VisitPattern(BoundExpression expression, TypeSymbolWithAnnotations expressionResultType, BoundPattern pattern) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index bd50cc3e60151..69231be44d1bf 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -12131,12 +12131,21 @@ void Test(object? x) { if (x is var c) { - x.ToString(); // warn - c /*T:object?*/ .ToString(); // warn + x.ToString(); // warn 1 + c /*T:object?*/ .ToString(); // warn 2 } else { - x.ToString(); // warn + x.ToString(); // warn 3 + } + + if (x is var _) + { + x.ToString(); // warn 4 + } + else + { + x.ToString(); // warn 5 } } } @@ -12145,14 +12154,20 @@ void Test(object? x) c.VerifyTypes(); c.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. - // x.ToString(); // warn + // x.ToString(); // warn 1 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(8, 13), // (9,13): warning CS8602: Possible dereference of a null reference. - // c /*T:object?*/ .ToString(); // warn + // c /*T:object?*/ .ToString(); // warn 2 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "c").WithLocation(9, 13), // (13,13): warning CS8602: Possible dereference of a null reference. - // x.ToString(); // warn - Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(13, 13) + // x.ToString(); // warn 3 + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(13, 13), + // (18,13): warning CS8602: Possible dereference of a null reference. + // x.ToString(); // warn 4 + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(18, 13), + // (22,13): warning CS8602: Possible dereference of a null reference. + // x.ToString(); // warn 5 + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(22, 13) ); }