digitalmars.D.learn - cannot use UDA with same name as one of field's name
- sigod (12/12) Jun 23 2015 Hi. I have few questions about this piece of code.
- Steven Schveighoffer (6/19) Jun 23 2015 Yes, name lookup looks in local scope first, then outside. D does not
- sigod (21/23) Jun 23 2015 ```
- Steven Schveighoffer (3/13) Jun 23 2015 I'm not completely sure on the syntax, try adding some parens.
- Adam D. Ruppe (4/5) Jun 23 2015 Yeah, I'm pretty sure it needs to be
- sigod (6/11) Jun 23 2015 Yep, something like this works.
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? Is there any way to bypass it without using alias (e.g. `alias named = name;`)?
Jun 23 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
Jun 23 2015
On Tuesday, 23 June 2015 at 22:10:43 UTC, Steven Schveighoffer wrote:You can use full.path.name``` Error: unexpected ( in declarator Error: basic type expected, not "_id" Error: found '"_id"' when expecting ')' Error: no identifier for declarator .data.serialization.name(int) Error: semicolon expected following function declaration Error: declaration expected, not ')' ```You may be able to use .name, but I'm not sure that parses.``` Error: identifier or (ArgumentList) expected, not . Error: valid attributes are property, safe, trusted, system, disable Error: unexpected ( in declarator Error: basic type expected, not "_id" Error: found '"_id"' when expecting ')' Error: no identifier for declarator .name(int) Error: semicolon expected following function declaration Error: declaration expected, not ')' ```
Jun 23 2015
On 6/23/15 7:00 PM, sigod wrote:On Tuesday, 23 June 2015 at 22:10:43 UTC, Steven Schveighoffer wrote:I'm not completely sure on the syntax, try adding some parens. -SteveYou can use full.path.name``` Error: unexpected ( in declarator Error: basic type expected, not "_id" Error: found '"_id"' when expecting ')' Error: no identifier for declarator .data.serialization.name(int) Error: semicolon expected following function declaration Error: declaration expected, not ')' ```
Jun 23 2015
On Tuesday, 23 June 2015 at 23:14:13 UTC, Steven Schveighoffer wrote:I'm not completely sure on the syntax, try adding some parens.Yeah, I'm pretty sure it needs to be (full.name.here) void foo()
Jun 23 2015
On Tuesday, 23 June 2015 at 23:52:52 UTC, Adam D. Ruppe wrote:On Tuesday, 23 June 2015 at 23:14:13 UTC, Steven Schveighoffer wrote:Yep, something like this works. ``` (vibe.data.serialization.name("_id")) int id; ``` But in this case `alias` looks better.I'm not completely sure on the syntax, try adding some parens.Yeah, I'm pretty sure it needs to be (full.name.here) void foo()
Jun 23 2015