Name-based + new position-based destructuring #438
Replies: 10 comments 36 replies
-
|
One of the open design questions is what properties should be available through this syntax. There are three possible levels: 🚀 Only primary constructor properties 1️⃣, To direct discussion, I would love to gather feedback on this specific point in this thread. Please use emojis 🚀/🎉/❤️ (edit: GitHub does not allow generic emoji responses) if you just want to state "I prefer this option" without any additional reasoning. |
Beta Was this translation helpful? Give feedback.
-
|
About further extensions:
I think allowing assignments without mixing with declarations is already useful and covers a common case: [a, b] = b to aMixing can be added if the use-cases are found. |
Beta Was this translation helpful? Give feedback.
-
|
I see a problem in the current design. From the declaration below it is not fully comprehensible, which of the names is a property of a class and which is a variable. (val name1 = name2, ...) = ...One may say that the one near f(a = b)The first one is proposed by the declaration owner and the SECOND one is OUR argument. In the proposed feature the FIRST one is OUR name. Do you consider something like: (val name1 = .name2, ...) = ...(val name1 = declaration.name2, ...) = ...(val name1 = decl.name2, ...) = ...The following was also suggested in the comments: (val name1 = _.name2, ...) = ...Another problem is that if you have a variable with the declaration name above, it is not obvios that you reference not it: val name2 = "#"
(val name1 = name2, ...) = ... // name2 here is not from aboveSo, the |
Beta Was this translation helpful? Give feedback.
-
|
See:
It would be nice to stop using |
Beta Was this translation helpful? Give feedback.
-
|
Am I correct that with the long-term syntax (post-migration), you would not be required to specify any |
Beta Was this translation helpful? Give feedback.
-
|
For the migration plan, it would be very nice to have the ability to start with Phase 3 for new projects and projects that have been manually migrated. E.g. with an experimental compiler arg. |
Beta Was this translation helpful? Give feedback.
-
|
I want to push back a tiny bit on the |
Beta Was this translation helpful? Give feedback.
-
|
A question about what happens as the number of deconstructed properties goes down to 1, especially after phase 3: would you be able to write On the one hand, it seems silly to allow this when On the other hand, disallowing it would be an arbitrary restriction:
|
Beta Was this translation helpful? Give feedback.
-
|
Quick update for transparency: we’ve been working on the implementation of name-based destructuring in both the compiler and the IDE. The frontend part is nearly complete (KT-79274), but we still need some time to polish the IDE experience. The feature is not yet publicly available, not even an experimental version. |
Beta Was this translation helpful? Give feedback.
-
|
I feel like the current KEEP is not taking into consideration future extensions and feature interactions. I read the rationale and it all makes sense in isolation but how exactly would nested destructuring work? How would this integrate with Stuff like And would something similar to this ever work? when (f()) {
is Data.Foo(val x) -> funcRequiresInt(x)
is Data.Baz(val z0 @ true = bazField1, val z1 = bazField2) -> funcRequiresInt(z1)
}Would it not make sense to plan to unify the syntax for both irrefutable (destructuring assignment) and refutable patterns (pattern matching)? EDIT:I realized that the document mentions pattern matching at the very end, but that still doesn't address my concern for pattern matching beyond single level. EDIT 2:Purely hypothetically: { bazField1 = var z0; bazField2 = { var z1 } } = f() // assuming this is irrefutable
Baz { bazField1 = var z0; bazField2 = Wozzle { var z1 } } = f() // assuming this is irrefutable
when (f()) {
is Baz { bazField1 = true; bazField2 = Wozzle { var z1 } } -> ...
// or
is Baz(bazField1 = true, bazField2 = Wozzle(var z1) } -> ...
}this supports Comparatively, the current proposal: (var z0 = bazField1, (var z1) = bazField2) = f() // ???
// Hypothetically
Baz(var z0 = bazField1, Wozzle(var z1) = bazField2) = f()
when (f()) {
is Baz(true = bazField1, Wozzle(var z1) = bazField2 } -> ... // ???
}EDIT 3:I suppose the conclusion one can draw from this is that nested destructuring or even matching on constant values (without a guard) is not a priority and will not be a priority in the future? 🥲 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is an issue to discuss name-based destructuring and new syntax for position-based destructuring. The current full text of the proposal can be found here.
We propose a new form of destructuring based on names instead of positions. In addition, we propose new syntax for position-based destructuring.
Beta Was this translation helpful? Give feedback.
All reactions