-
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
Allow mixed declaration and assignment in deconstruction #44476
Allow mixed declaration and assignment in deconstruction #44476
Conversation
are there any tests for nested deconstruction? i.e. |
…e/mixed-declaration-and-assignment
do we need to retarget this to a "compiler-next" branch? @jaredpar |
Thanks, added a test #Resolved |
That's what we expected :-) Just as a heads up, we likely won't have much time to review this PR before 6/10 (we're trying to get a big chunk of records in next preview). |
Is there any consideration to permit tuple element names in deconstruction? The expected behavior is already established by recursive patterns for both Deconstruct and tuples. See dotnet/csharplang#3304 |
I don't see why that's related? This just removes a (somewhat arbitrary) error. |
I believe this is also a syntactical relaxation for deconstruction and removes an error. The parser already accept such code. |
LDM approved yesterday for language version following C# 9 (9/15/2020). #Resolved |
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs
Outdated
Show resolved
Hide 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.
Done with review pass (iteration 5)
The feature is approved as preview feature for C# 10 (VS 16.9 under LangVersion.Preview). If this PR is to be merged in the next couple of weeks, then it will be necessary to update the base branch to If on the other hand it will be a while before the PR is merged, we can just wait until master represents VS 16.9. /cc @jaredpar #Resolved |
Would it not be possible to merge it now as a preview feature for C# 10? All the current C# 9 features are no longer in preview. There's zero risk of breaking C# 9.0 since all this does is replace a warning with a preview gate - no code gen changes at all. Otherwise might as well wait a couple of weeks. Either way I imagine that there's further tests that need to be done before this can be merged: Off the top of my head I'm guessing Symbols and Control flow tests? Anything else? GoToDefinition tests? |
Yes, we discussed with Rikki offline and I think we can use the
Yes. I opened a mini test-plan issue for tracking. I think we can just do the whole feature in a single PR. For IDE side, I'll start a thread and get back to you. From the compiler side:
|
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs
Outdated
Show resolved
Hide 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.
LGTM (commit 13). I'm not exactly sure when we'll be able to get this merged, hopefully sometime in the next week or 2. We're heads down on remaining C# 9 fixes for the next 2 weeks.
@333fred any chance we can get this merged this week? |
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 14)
Next week. |
Sorry for the delay. I'm going to run an IDE test pass today and find an IDE buddy. |
Ran this change through a quick IDE test pass on Friday, focusing on completion and QuickInfo (since those seems most likely to be affected). Things look good (behavior is same as for regular deconstruction). Pinged Jinu to get an buddy to get the IDE sign-off. |
It looks like there are several test gaps in IDE code. They aren't new for this PR, but we should take the opportunity to close them.
[jcouv update:] Sam also suggested to verify |
Looks like |
As is: (var x, _) = (0, 0);
Console.WriteLine(x); So it looks like mixed declaration and discard has always been allowed. |
Currently the logic to check is a local is in scope simply checks that's it's declared before the current syntax, so this is suggested, as is x in I don't want to change that logic in the PR as it seems like a relatively complex change, and we do this already, so we're no worse off by merging this. |
How does the language define this code after your feature? class T {
int x;
void M() {
(var x, x) = (1, 2);
Console.WriteLine(x);
Console.WriteLine(this.x);
}
} |
@sharwell that's an error |
And |
Yes, and I have tests for both |
@sharwell We have the necessary sign-offs from the compiler side. Yair has added the IDE (thanks!) and they match what I'd verified manually (behave as expected). |
* upstream/master: For the purpose of runtime capability check require RuntimeFeature type to be a static class. (dotnet#50829) Allow mixed declaration and assignment in deconstruction (dotnet#44476) Disable sdl Fix crash around handling delegating of constructors cross-project Clarify in a comment when some stuff loads Don't reference the implementation type directly if we don't need it Remove the CreateWorkspace() method that implies it's created there Delete AbstractPackage`2.IsInIdeMode() Remove some very outdated comments
Merged/squashed. Thanks @YairHalberstadt! :-) |
Implements dotnet/csharplang#125
Test plan: #47746
I simply removed the error, and added tests. So far everything seems to work without any actual code changes, which worries me a little :-)
Please suggest scenarios for further testing.