- Notifications
You must be signed in to change notification settings - Fork92
Fix tuple assignment#1366
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:draft-v8
Are you sure you want to change the base?
Fix tuple assignment#1366
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Fixesdotnet#1155This PR follows the process outlined indotnet#1155 (comment)
Nigel-Ecma commentedJul 3, 2025
Carried over from#1159:
This PR is for that rethink… |
jnm2 commentedJul 3, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@Nigel-Ecma If a tuple expression doesn't have a type, then I think we don't get to the part where
Thus a tuple expression is only evaluated when it has a type, and thus a tuple expression can be evaluated by constructing the corresponding |
| A tuple expression is evaluated by evaluating each of its element expressions in order from left to right. | ||
| A tuple valuecan beobtained from a tuple expression byconverting itto 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))) orbymakingit thetargetofa deconstructing assignment ([§12.21.2](expressions.md#12212-simple-assignment)). | ||
| A tuple valueisobtained from a tuple expression byevaluating itand storing the result in corresponding`System.ValueTuple<...>` type, and initializing each of its fields in order from left to rightbyevaluating the corresponding tuple element expression of`E`, convertingittothecorresponding element typeof`T` using the implicit conversion found, and initializing the field with the result. |
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.
System.ValueTuple isn't mentioned anywhere else in this file. Shouldn't we be a bit more specific? There are wrinkles in how tuples map to the ValueTuple types. For instance, a tuple type(T1, T2, T3, T4, T5, T6, T7, T8) must be represented as nested ValueTuples, because the TRest type argument of a tuple must always itself be a nested tuple:ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8>>
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 see that conversions.md does mentionValueTuple<...> a few times, but it doesn't explain the required recursive encoding.
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 vaguely remember that we discussed how far we needed to go with that encoding aspect.
If we can avoid referring toValueTuple<...> in this section, it's likely to make our lives easier... even if it means doing a bit more work in 8.3.11 to effectively make that theonly place that needs to go into that detail. If we can say "logically there's a type with N fields" then we can make this line (in expressions.md) simpler.
| ###12.2.2 Values of expressions | ||
| Most of the constructs that involve an expression ultimately require the expression to denote a***value***. In such cases, if the actual expression denotes a namespace, a type, a method group, or nothing, a compile-time error occurs. However, if the expression denotes a property access, an indexer access, or a variable, the value of the property, indexer, or variable is implicitly substituted: | ||
| Most of the constructs that involve an expression ultimately require the expression to denote a***value***. In such cases, if the actual expression denotes a namespace, a type, a method group, or nothing, a compile-time error occurs. However, if the expression denotes a property access, an indexer access,a tuple,or a variable, the value of the property, indexer, tuple, or variable is implicitly substituted: |
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 do we mention tuple expressions here, but we don't mention other kinds of expressions such as object creation expressions, array creation expressions, lambda expressions, and so on?
| ### 10.2.13 Implicit tuple conversions | ||
| Animplicitconversionexistsfromatupleexpression `E`toatupletype `T`if `E`hasthesamearityas `T`andanimplicitconversionexistsfromeachelementin `E`tothecorrespondingelementtypein `T`.Theconversionisperformedbycreatinganinstanceof `T`’scorresponding `System.ValueTuple<...>`type,andinitializingeachofitsfieldsinorderfromlefttorightbyevaluatingthecorrespondingtupleelementexpressionof `E`,convertingittothecorrespondingelementtypeof `T`usingtheimplicitconversionfound,andinitializingthefieldwiththeresult. | ||
| Animplicitconversionexistsfromanexpression `E`withatupletype `S`toatupletype `T`if `S`hasthesamearityas `T`andanimplicitconversionexistsfromeachelementtypein `S`tothecorrespondingelementtypein `T`. |
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 think I'm following, but just checking.Is there a tuple typeS for every tuple expression? For instance, does(default, default) have a tuple typeS in:
(object,object)x=(default,default);
jskeet commentedNov 19, 2025
@Nigel-Ecma is working on a new PR - he will close this when opening the new one. |
Fixes#1155
This PR follows the process outlined in#1155 (comment)
This replaces the first commit in#1159.
See#1359 (review) for the status of this PR.