Roslyn: No warning for identity pattern-matching comparison

Created on 25 Dec 2016  路  5Comments  路  Source: dotnet/roslyn

Version Used: a2df65047264ed08fb3a985056085dbcee821253

C# var b = 1 is 1 || 1 is 2;

Expected Behavior:
Warning: "The given expression is always / never equal to the provided value", just like is would when used with types.

Actual Behavior:
No warnings

http://tryroslyn.azurewebsites.net/#b:master/f:r/K4Zwlgdg5gBAygTxAFwKYFsDcAoADsAIwBswBjGUogQxBBgGEYBvbGNmfYsmANwHswAExgBZABQBKZtgCQMnlQBOMAjAC8MAIwwwdbQB99WnXQBMOOao3bdOiMhiHjtwX0JFUOdjAC+2H0A=

Area-Compilers Feature Request New Feature - Warning Waves New Language Feature - Pattern Matching

Most helpful comment

I imagine this is more likely to happen in a "warning wave" in a subsequent release, but I'll see if we can get it in to C# 7.

All 5 comments

Also, 1 is int x should perhaps give a warning (1 is var x should not).

FYI @gafter

I imagine this is more likely to happen in a "warning wave" in a subsequent release, but I'll see if we can get it in to C# 7.

Is this related to unreachable code detection (rel. #15489)?

int M()
{
  if(1 is 1) return 2;
}

Same code with == does not produce any error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glennblock picture glennblock  路  3Comments

NikChao picture NikChao  路  3Comments

johndog picture johndog  路  3Comments

codingonHP picture codingonHP  路  3Comments

MadsTorgersen picture MadsTorgersen  路  3Comments