cannot use UDA with same name as one of field's name

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 23 15:10:45 PDT 2015


On 6/23/15 4:53 PM, sigod wrote:
> Hi. I have few questions about this piece of code.
>
> ```
> import vibe.data.serialization;
>
> struct User
> {
>      @name("_id") int id; // Error: function expected before (), not
> name of type string
>      string name;
> }
> ```
>
> Is it even proper compiler behavior?

Yes, name lookup looks in local scope first, then outside. D does not 
have a requirement to order declarations that aren't inside a function body.

> Is there any way to bypass it
> without using alias (e.g. `alias named = name;`)?

You can use @full.path.name

You may be able to use @.name, but I'm not sure that parses.

-Steve


More information about the Digitalmars-d-learn mailing list