Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No warning for identity pattern-matching comparison #16099

Closed
SLaks opened this issue Dec 25, 2016 · 5 comments
Closed

No warning for identity pattern-matching comparison #16099

SLaks opened this issue Dec 25, 2016 · 5 comments

Comments

@SLaks
Copy link
Contributor

SLaks commented Dec 25, 2016

Version Used: a2df650

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=

@SLaks
Copy link
Contributor Author

SLaks commented Dec 25, 2016

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

@jcouv
Copy link
Member

jcouv commented Dec 27, 2016

FYI @gafter

@gafter gafter self-assigned this Dec 27, 2016
@gafter
Copy link
Member

gafter commented Dec 27, 2016

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.

@gafter gafter added this to the 2.0 (RTM) milestone Dec 27, 2016
@alrz
Copy link
Contributor

alrz commented Dec 28, 2016

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.

@gafter gafter modified the milestones: 2.0 (RTM), 2.1 Jan 17, 2017
@jaredpar jaredpar added the New Feature - Warning Waves Warning Waves label Mar 9, 2017
@jaredpar jaredpar modified the milestones: Unknown, 15.1 Mar 9, 2017
gafter added a commit to gafter/roslyn that referenced this issue Apr 9, 2018
Both refutable and irrefutable is-pattern matches affect definite assignment:
- an irrefutable match leaves pattern variables definitely assigned
- a refutable match is an error
Fixes dotnet#25890

Also, we check to see if a constant input makes the result refutable or irrefutable:
- If a constant cannot match the pattern, we issue a warning
- If a constant always matches a constant pattern, we issue a warning
The latter two are subject to compat council approval.
Fixes dotnet#16099
@gafter
Copy link
Member

gafter commented Apr 11, 2018

Fixed in #26035

@gafter gafter closed this as completed Apr 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants