Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
June 23, 2015 cannot use UDA with same name as one of field's name | ||||
---|---|---|---|---|
| ||||
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;`)? |
June 23, 2015 Re: cannot use UDA with same name as one of field's name | ||||
---|---|---|---|---|
| ||||
Posted in reply to sigod | 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 |
June 23, 2015 Re: cannot use UDA with same name as one of field's name | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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 ')' ``` |
June 23, 2015 Re: cannot use UDA with same name as one of field's name | ||||
---|---|---|---|---|
| ||||
Posted in reply to sigod | On 6/23/15 7:00 PM, sigod wrote:
> 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 ')'
> ```
I'm not completely sure on the syntax, try adding some parens.
-Steve
|
June 23, 2015 Re: cannot use UDA with same name as one of field's name | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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()
|
June 24, 2015 Re: cannot use UDA with same name as one of field's name | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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: >> 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() Yep, something like this works. ``` @(vibe.data.serialization.name("_id")) int id; ``` But in this case `alias` looks better. |
Copyright © 1999-2021 by the D Language Foundation