| Thread overview | |||||
|---|---|---|---|---|---|
|
April 09, 2015 UDAs and no complaints about "need 'this'" | ||||
|---|---|---|---|---|
| ||||
struct BigLongStructName
{
int evenLongerMemberName;
}
struct QN{}
unittest
{
BigLongStructName bigLongStructName;
@(bigLongStructName.evenLongerMemberName)
QN quickName;
__traits(getAttributes, quickName)[0]++;
}
Is it just me or is it weird that this works? Once you pull the UDA out from being a storage class and attempt to alias it, you get the usual "need 'this' for 'evenLongerMemberName' of type 'int'" error messages on use.
Why are UDAs so special? I don't believe there's any other way to achieve this sort of effective renaming.
| ||||
April 09, 2015 Re: UDAs and no complaints about "need 'this'" | ||||
|---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Thursday, 9 April 2015 at 09:53:15 UTC, John Colvin wrote: > struct BigLongStructName > { > int evenLongerMemberName; > } > > struct QN{} > > unittest > { > BigLongStructName bigLongStructName; > > @(bigLongStructName.evenLongerMemberName) > QN quickName; > > __traits(getAttributes, quickName)[0]++; > } > > Is it just me or is it weird that this works? Once you pull the UDA out from being a storage class and attempt to alias it, you get the usual "need 'this' for 'evenLongerMemberName' of type 'int'" error messages on use. > > Why are UDAs so special? I don't believe there's any other way to achieve this sort of effective renaming. I think it's an error. When the attribute is a struct, it looks like the member is processed as a static variable. But the equivalent with a class raises an AV: --- class BigLongStructName { int evenLongerMemberName; } struct QN{} unittest { import std.stdio; BigLongStructName bigLongStructName; @(bigLongStructName.evenLongerMemberName) QN quickName; __traits(getAttributes, quickName)[0]++; } --- which is a totally expected behaviour. | |||
April 09, 2015 Re: UDAs and no complaints about "need 'this'" | ||||
|---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Thursday, 9 April 2015 at 09:53:15 UTC, John Colvin wrote:
> struct BigLongStructName
> {
> int evenLongerMemberName;
> }
>
> struct QN{}
>
> unittest
> {
> BigLongStructName bigLongStructName;
>
> @(bigLongStructName.evenLongerMemberName)
> QN quickName;
>
> __traits(getAttributes, quickName)[0]++;
> }
>
> Is it just me or is it weird that this works? Once you pull the UDA out from being a storage class and attempt to alias it, you get the usual "need 'this' for 'evenLongerMemberName' of type 'int'" error messages on use.
>
> Why are UDAs so special? I don't believe there's any other way to achieve this sort of effective renaming.
For me it seems to fit into D type system (which is not necessarily is a good idea).
struct S
{
int i;
}
alias S.i si;
void main(){ /*si++;*/}
Behavior of D depends sometimes on it internals, not on programmers' expectations. Since D has never been stabilized, the boundary between WAT and bugs is partially undefined.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply