[Issue 19127] UDAs seem to be raw AST nodes rather than expressions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 3 12:20:13 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=19127

Nick Treleaven <nick at geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick at geany.org

--- Comment #4 from Nick Treleaven <nick at geany.org> ---
> "User-Defined Attributes (UDA) are compile-time expressions that can be attached to a declaration."

Fixed this wording in https://github.com/dlang/dlang.org/pull/3598.

> This should be invalid:

>  struct jsonize { string name; }
>  @jsonize int i;

> `jsonize` is a type, but it is used as an expression. We see how this misbehaves when we inspect it:

>  foreach (uda; __traits(getAttributes, i)) writeln(uda);
>  // Error: cannot pass type jsonize as a function argument

It is actually correct, a UDA can be defined by a type name. And naturally you
can't pass a type as a function argument. You can use it in declarations,
scroll down to the getAttributes example:
https://dlang.org/spec/attribute.html#uda

The other behaviour is very weird for @print. Also non-compile-time expressions
should definitely be disallowed.

--


More information about the Digitalmars-d-bugs mailing list