-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Implement extended property patterns #52139
Implement extended property patterns #52139
Conversation
Done. Feel free to create the test plan issue whenever you're ready. In reply to: 808550478 |
…rns' into extended-property-patterns # Conflicts: # src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
@333fred I should probably sort out public APIs just like the other PR, also check lang version. Up until the next round of changes I'd like a review pass if possible. Thanks. |
@alrz Just to let you know, we have a lot of features in flight as the moment that we'd prefer to land first. We love the contribution/enthusiasm and this feature, but this means we won't be able to dedicate much time reviewing this for a while. In reply to: 815249337 |
That's why I wrote "if possible" 😄 I don't expect this feature to be a priority obviously. |
We super appreciate your enthusiasm here and want to get as much of your features into C# 10 as possible. But we are starting to run up against resource constraints (just can't review it all at the same time 😄). I think there are essentially three features in flight now:
Had a brief chat earlier this week with @jcouv and we were pretty interested and trying to get (1) in first. That is a self contained feature, adds a ton of value, and it seems to be on the right path impl + design. After that I'm somewhat ambivilent as to what we push on next but we should discuss. |
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 Thanks (iteration 34) with a minor comment (missing PROTOTYPE marker?)
@333fred @dotnet/roslyn-compiler for a second review. Thanks |
var memberBuilder = ArrayBuilder<Symbol>.GetInstance(); | ||
LookupMembersForPropertyPattern(inputType, expr, memberBuilder, diagnostics, ref hasErrors, out memberType); | ||
members = memberBuilder.ToImmutableAndFree(); | ||
if (!hasErrors && members.Length > 1) |
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.
If we don't care if there's already error on the name we might as well move it to the parser. But in that case it will err in completely invalid scenarios { (c?a:b): p } // invalid name + feature is in preview (?!)
Is that ok?
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 we want to avoid reporting this error if the are syntax errors, could we check !expr.HasErrors
here instead?
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.
hasErrors may be already set by the caller or from an earlier subpattern. And if we don't report a /langversion error now because of another error, won't the user just get the /langversion error after fixing the current error?
Reading this again, that's actually a pretty bad experience. Another scenario is doing a?.b
which produces "invalid name" and only after fixing that we give langversion error (even with expr.HasError) which is unnecessary back and forth.
I'm leaning towards moving this check to the parser and produce all diagnostics upfront - (c?a:b)
example is a hypothetical scenario that I think we shouldn't be worry about.
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.
Another scenario is doing a?.b which produces "invalid name" and only after fixing that we give langversion error (even with expr.HasError) which is unnecessary back and forth.
I'm leaning towards moving this check to the parser and produce all diagnostics upfront
Moving this check to the parser seems reasonable, but it might be a fair amount of code churn (with "/langversion" errors reported in parsing tests, etc.). Also, I suspect there are other codepaths in binding we don't report all binding errors if the expression contains syntax errors. So, to me, it seems sufficient to either remove the !hasErrors
check above or change to !expr.HasErrors
.
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.
Also, I suspect there are other codepaths in binding we don't report all binding errors if the expression contains syntax errors.
Not for subpatterns apparently - probably because we only had an identifier before and it couldn't go wrong. I did a little experiment to see how it looks like (with all green pattern tests; semantic and syntax): d3f1e7f?w=1
We already use preview
version so there wasn't a need to adjust the baseline.
Anywho, if you feel that's gonna be an issue I'll be fine to keep it in the binder.
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.
I did a little experiment to see how it looks like (with all green pattern tests; semantic and syntax)
Anywho, if you feel that's gonna be an issue I'll be fine to keep it in the binder.
My hesitation was just avoiding code churn if there was minimal benefit to moving the check.
It looks like we have a number of pattern feature checks in the parser already so perhaps it makes sense to check this feature in the parser as well since there's no test impact currently.
If you do move the check, please include at least one parsing test with TestOptions.Regular9
and TestOptions.RegularPreview
, and consider including a binding test that demonstrates that errors in an earlier subpattern have no effect on the /langversion
error: perhaps _ = new C() is { Unrecognized: null, Prop1.Prop2: null };
src/Compilers/CSharp/Portable/Parser/LanguageParser_Patterns.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Syntax/BaseExpressionColonSyntax.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Syntax/InternalSyntax/NameColonSyntax.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests5.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests5.cs
Outdated
Show resolved
Hide resolved
static bool Test1(C o) => o is { Prop1.Prop2.Prop3: null }; | ||
static bool Test2(S o) => o is { Prop1.Prop2.Prop3: null }; | ||
static bool Test3(S? o) => o is { Prop1.Prop2.Prop3: null }; | ||
static bool Test4(S0 o) => o is { Prop1.Prop2.Prop3: 420 }; |
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. A couple of remaining comments that are not blocking.
Merged/squashed. Thanks @alrz! |
@jcouv Thanks. I did not receive your email (it's |
Proposal: dotnet/csharplang#4394
Spec: https://github.com/dotnet/csharplang/blob/main/proposals/extended-property-patterns.md
Test plan: #52468