Replies: 4 comments
-
i.e: x.(S).f = 4; Should act similarly to: v := &x.(S);
v.f = 4; // modifies 'x' |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
(&x.(S)).f = 4; This will work, and is much clearer what is going on too. Even if it's "ugly". |
Beta Was this translation helpful? Give feedback.
-
This reminds me of being able to assign to array elements as in:
Could the same mechanism/design not apply? |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
The current syntax of trying to alter a field which is a member of a discriminated union is quite frustrating and extremely unintuitive. When attempting to access a member of a discriminated union, you'd expect alterations to it to stay since you're accessing a field from a struct. However, it actually copies it instead of referencing it.
Example from my code:
call.variant.(Call).args = temp_node_storage[:];
You'd expect that altering
call.variant
would alter the variant incall
. However, the changes to not stay. This is extremely unintuitive.Example of how to modify the field (from Tetralux):
I would have never thought of this at all.
Describe the solution you'd like
I would like to be able to modify fields that are a member of a discriminated union just like I would any other field. There shouldn't be any distinction between modifying
foo.bar
andfoo.baz.(WhateverGoesAfterBaz).WhateverGoesAfterBaz2ElectricBoogaloo
(please excuse my poor sense of humor).Additional context
Here's the full chunk of code and its output:
Code:
Example (wrong) output:
Beta Was this translation helpful? Give feedback.
All reactions