-
Notifications
You must be signed in to change notification settings - Fork 4k
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
recursive-patterns(19) Distinguish irrefutable and refutable patterns in the is
expression
#26035
recursive-patterns(19) Distinguish irrefutable and refutable patterns in the is
expression
#26035
Conversation
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
is
expressionis
expression
} | ||
|
||
operand = BadExpression(node, operand).MakeCompilerGenerated(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we doing this unconditionally now? #ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is unconditionally illegal to have a lambda or method group here. This line just gives the expression an error type so later code doesn't see a typeless expression.
In reply to: 180249518 [](ancestors = 180249518)
if (!reachableLabels.Contains(node.WhenTrueLabel)) | ||
{ | ||
SetState(this.StateWhenFalse); | ||
SetConditionalState(UnreachableState(), this.State); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If SetConditionalState zeroes out the current state, what's the point of calling SetState before this? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to UnreachableState()
requires as a precondition that the current state is not a split state.
In reply to: 180252872 [](ancestors = 180252872)
else if (!reachableLabels.Contains(node.WhenFalseLabel)) | ||
{ | ||
SetState(this.StateWhenTrue); | ||
SetConditionalState(this.State, UnreachableState()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. #Resolved
@@ -212,9 +212,6 @@ public static void Main() | |||
// (10,13): error CS8117: Invalid operand for pattern match; value required, but found '<null>'. | |||
// if (null is dynamic t) { } // null not allowed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this text is out of date. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
{ | ||
diagnostics.Add(ErrorCode.WRN_GivenExpressionNeverMatchesPattern, node.Location); | ||
} | ||
else if (!decisionDag.ReachableLabels.Contains(whenFalseLabel) && pattern.Kind == BoundKind.ConstantPattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&& pattern.Kind == BoundKind.ConstantPattern [](start = 83, length = 44)
When is the pattern not a ConstantPattern
? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const string s = null;
System.Console.WriteLine(s is string { Length: 3 });
#Resolved
Both refutable and irrefutable is-pattern matches affect definite assignment:
Fixes Add tests for irrefutable patterns #25890
Also, we check to see if a constant input makes the result refutable or irrefutable:
The latter two are subject to compat council approval.
Fixes No warning for identity pattern-matching comparison #16099