Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 05, 2016 [Issue 16123] alias member of member | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=16123 Ketmar Dark <ketmar@ketmar.no-ip.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ketmar@ketmar.no-ip.org -- |
June 06, 2016 [Issue 16123] alias member of member | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=16123 --- Comment #1 from Sobirari Muhomori <dfj1esp02@sneakemail.com> --- I guess, you can alias a symbol, but then the compiler doesn't know what S's symbol in T struct means. struct S { int x; alias y = x; } actually means struct S { int x; alias y = S.x; } struct T { S s; alias y = S.x; // what this means? } -- |
June 06, 2016 [Issue 16123] alias member of member | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=16123 --- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> --- (In reply to Sobirari Muhomori from comment #1) > struct T > { > S s; > alias y = S.x; // what this means? > } Right, but I said s.x, not S.x. It means alias to the member x of the instance of S called s, which resides in this instance of T. Maybe it's more helpful if I say: alias y = T.s.x; In any case, I see no technical limitation of why this shouldn't work. If there's already a way to do it, please close and let me know how to! Note, I've worked around in my code by doing essentially: private ref y() { return s.x; } But I much prefer the alias mechanism. -- |
June 06, 2016 [Issue 16123] alias member of member | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=16123 Max Samukha <maxsamukha@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxsamukha@gmail.com --- Comment #3 from Max Samukha <maxsamukha@gmail.com> --- (In reply to Steven Schveighoffer from comment #2) > (In reply to Sobirari Muhomori from comment #1) > > > struct T > > { > > S s; > > alias y = S.x; // what this means? > > } > > Right, but I said s.x, not S.x. It means alias to the member x of the instance of S called s, which resides in this instance of T. In 'alias', they are just two equivalent ways of referencing 'x', that is: __traits(isSame, S.x, T.s.x) == true And it kind of makes sense if you think of 'alias' as little more than a means of creating synonyms for a symbol. With 's.x' in the 'alias' declaration, you are simply importing 'x' to the namespace of 'T'. Not that I care much now, but some code I wrote actually relied on this semantics. -- |
June 06, 2016 [Issue 16123] alias member of member | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=16123 --- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> --- I'm having trouble seeing how this logically is different. Access to t.s.x is done by adding some offset to &t, just like access to s.x is done by adding some offset to &s. I get that the "symbol" I'm trying to alias is really a compound symbol, but I can alias it just fine in other places. This reminds me of the whole inability to alias keywords. It's an implementation detail that I shouldn't have to care about! -- |
June 06, 2016 [Issue 16123] alias member of member | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=16123 --- Comment #5 from Max Samukha <maxsamukha@gmail.com> --- (In reply to Steven Schveighoffer from comment #4) > I'm having trouble seeing how this logically is different. Access to t.s.x is done by adding some offset to &t, just like access to s.x is done by adding some offset to &s. > > I get that the "symbol" I'm trying to alias is really a compound symbol, but I can alias it just fine in other places. I just say that what you are trying is not how 'alias' works, and the current semantics does make sense. Whether it is good is a different issue. > > This reminds me of the whole inability to alias keywords. It's an implementation detail that I shouldn't have to care about! Inability to alias keywords is a different issue. -- |
June 06, 2016 [Issue 16123] alias member of member | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=16123 --- Comment #6 from Steven Schveighoffer <schveiguy@yahoo.com> --- (In reply to Max Samukha from comment #5) > (In reply to Steven Schveighoffer from comment #4) > > I'm having trouble seeing how this logically is different. Access to t.s.x is done by adding some offset to &t, just like access to s.x is done by adding some offset to &s. > > > > I get that the "symbol" I'm trying to alias is really a compound symbol, but I can alias it just fine in other places. > > I just say that what you are trying is not how 'alias' works, and the current semantics does make sense. Whether it is good is a different issue. I would understand if s was a property and not a field, because you need to execute code to compute the actual access. I get that alias is not as powerful as a mixin, but this doesn't seem like a reasonable limitation. Note: it's kind of weird that the compiler would allow this kind of alias to compile when it's fully unusable. > > This reminds me of the whole inability to alias keywords. It's an implementation detail that I shouldn't have to care about! > > Inability to alias keywords is a different issue. To the user, it's not much different. Granted, two different implementation issues, but it looks the same -- compiler cannot do what should be obviously doable. -- |
June 06, 2016 [Issue 16123] alias member of member | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=16123 Steven Schveighoffer <schveiguy@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement --- Comment #7 from Steven Schveighoffer <schveiguy@yahoo.com> --- (In reply to Max Samukha from comment #5) > I just say that what you are trying is not how 'alias' works, and the current semantics does make sense. Whether it is good is a different issue. However, I get your point that this is intended behavior and working as designed. I'm changing to enhancement. -- |
September 17, 2020 [Issue 16123] alias member of member | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=16123 Andrei Alexandrescu <andrei@erdani.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrei@erdani.com --- Comment #8 from Andrei Alexandrescu <andrei@erdani.com> --- subscribe -- |
December 17, 2022 [Issue 16123] alias member of member | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=16123 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P1 |P4 -- |
Copyright © 1999-2021 by the D Language Foundation