Skip to content

Fix tuple assignment and tuple element type inference #1359

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

Open
wants to merge 6 commits into
base: draft-v8
Choose a base branch
from

Conversation

BillWagner
Copy link
Member

@BillWagner BillWagner commented Jun 26, 2025

Fixes #1244: type inference from tuple element expressions

I followed the recommended text from collection expressions because we well need them in the future. I did break apart the first phase and the input type inference because tuple elements now needs subscripts as well. We could put them together, but the small i and j start to look the same.

Fixes dotnet#1155

This PR follows the process outlined in dotnet#1155 (comment)
@BillWagner BillWagner force-pushed the additional-tuple-work branch from 29fba23 to 79be266 Compare June 26, 2025 20:50
Fixes dotnet#1244

I followed the recommended text from [collection expressions](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-12.0/collection-expressions.md#type-inference) because we well need them in the future. I did break apart the first phase and the input type inference because tuple elements now needs subscripts as well. We could put them together, but the small `i` and `j` start to look the same.
@BillWagner BillWagner changed the title Fix tuple assignment Fix tuple assignment and tuple element type inference Jun 26, 2025
@BillWagner BillWagner added the meeting: priority Review before meeting. Merge, merge with issues, or reject at the next TC49-TC2 meeting label Jun 26, 2025
@BillWagner BillWagner marked this pull request as ready for review June 27, 2025 17:06
@BillWagner
Copy link
Member Author

@jskeet This is ready to review for the next meeting.

Copy link
Contributor

@Nigel-Ecma Nigel-Ecma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My possible fix to #1155 doesn’t deal with the case of a tuple_expression not having a type (RIP null type), and one without a type is not representable directly as a ValueTuple<…> as there is no type for one or more of the type params…

A re-think is needed, till then I’ll mark this PR as draft

@@ -1611,7 +1611,7 @@ A tuple expression has a type if and only if each of its element expressions `Ei

A tuple expression is evaluated by evaluating each of its element expressions in order from left to right.

A tuple value can be obtained from a tuple expression by converting it to a tuple type ([§10.2.13](conversions.md#10213-implicit-tuple-conversions)), by reclassifying it as a value ([§12.2.2](expressions.md#1222-values-of-expressions))) or by making it the target of a deconstructing assignment ([§12.21.2](expressions.md#12212-simple-assignment)).
A tuple value is obtained from a tuple expression by evaluating it and storing the result in corresponding `System.ValueTuple<...>` type, and initializing each of its fields in order from left to right by evaluating the corresponding tuple element expression of `E`, converting it to the corresponding element type of `T` using the implicit conversion found, and initializing the field with the result.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this isn’t right, see review comment

@Nigel-Ecma Nigel-Ecma marked this pull request as draft June 30, 2025 23:32
Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's talk about this at the meeting. If we can come to an agreement about the second commit, would we be able to separate that out from the first and get it merged, to reduce the scope of outstanding changes?

@dotnet dotnet deleted a comment from BillWagner Jul 2, 2025
Changes made during the July meeting.

Co-authored-by: Jon Skeet <skeet@pobox.com>
@jskeet
Copy link
Contributor

jskeet commented Jul 2, 2025

@BillWagner will split into two PRs, I'll approve the one that is "2nd commit and onwards" and Bill can merge it.

@BillWagner
Copy link
Member Author

New task: Split into 2 PRs, one with the first commit, one with the 2nd and 3rd commits. Then, that 2nd PR can be merged.

@jskeet
Copy link
Contributor

jskeet commented Jul 2, 2025

And @Nigel-Ecma will think about required changes for the first commit.

@BillWagner BillWagner mentioned this pull request Jul 3, 2025
@BillWagner BillWagner marked this pull request as ready for review July 3, 2025 18:52
@BillWagner
Copy link
Member Author

@Nigel-Ecma @jskeet The first commit in this PR has been reverted. I've updated the description so this PR only fixes the one issue. The other commit has been broken off into #1366, which I assigned to Nigel to noodle on for the next meeting.

We should be able to merge this one before the next meeting.

Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more nit, but otherwise yay.

Co-authored-by: Jon Skeet <skeet@pobox.com>
@BillWagner
Copy link
Member Author

@Nigel-Ecma Are you good with merging this now that the incorrect part is split off? If so, can you approve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meeting: priority Review before meeting. Merge, merge with issues, or reject at the next TC49-TC2 meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type inference from element expressions within tuple literal arguments
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy