Skip to content

Commit

Permalink
Address more PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Jul 23, 2018
1 parent 661e4f1 commit 0503021
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ private void VisitPattern(BoundExpression expression, TypeSymbolWithAnnotations
break;
}

Debug.Assert(!IsConditionalState);
int slot = -1;
if (isNull != null)
{
Expand All @@ -827,7 +828,6 @@ private void VisitPattern(BoundExpression expression, TypeSymbolWithAnnotations
}
}

Debug.Assert(!IsConditionalState);
base.VisitPattern(expression, pattern);
Debug.Assert(IsConditionalState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11796,7 +11796,7 @@ public void ConditionalBranching_Is_UnconstrainedGenericType()
CSharpCompilation c = CreateCompilation(@"
class C
{
static void F<T>(T t, object? o)
static void F<T>(object? o)
{
if (o is T)
{
Expand All @@ -11823,7 +11823,7 @@ public void ConditionalBranching_Is_StructConstrainedGenericType()
CSharpCompilation c = CreateCompilation(@"
class C
{
static void F<T>(T t, object? o) where T : struct
static void F<T>(object? o) where T : struct
{
if (o is T)
{
Expand All @@ -11850,7 +11850,7 @@ public void ConditionalBranching_Is_ClassConstrainedGenericType()
CSharpCompilation c = CreateCompilation(@"
class C
{
static void F<T>(T t, object? o) where T : class
static void F<T>(object? o) where T : class
{
if (o is T)
{
Expand Down Expand Up @@ -12030,9 +12030,37 @@ void Test(object? x)
);
}

[Fact]
public void ConditionalBranching_IsConstantPattern_NonConstant()
{
CSharpCompilation c = CreateCompilation(@"
class C
{
void Test(object? x)
{
string nonConstant = ""hello"";
if (x is nonConstant)
{
x.ToString(); // warn
}
}
}
", parseOptions: TestOptions.Regular8);

c.VerifyDiagnostics(
// (7,18): error CS0150: A constant value is expected
// if (x is nonConstant)
Diagnostic(ErrorCode.ERR_ConstantExpected, "nonConstant").WithLocation(7, 18),
// (9,13): warning CS8602: Possible dereference of a null reference.
// x.ToString(); // warn
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(9, 13)
);
}

[Fact]
public void ConditionalBranching_IsConstantPattern_Null_AlreadyTestedAsNonNull()
{
// PROTOTYPE(NullableReferenceTypes): confirm that we want such hidden warnings
CSharpCompilation c = CreateCompilation(@"
class C
{
Expand Down

0 comments on commit 0503021

Please sign in to comment.