[Issue 20464] New: builtin types could be usable as UDA, without being enclosed in parens

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Dec 22 17:32:13 UTC 2019


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

          Issue ID: 20464
           Summary: builtin types could be usable as UDA, without being
                    enclosed in parens
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: b2.temp at gmx.com

Minor enhancement suggestion

---
template BasicTypeUDA(T)
{
    @T(0) int v1;
    @int(0) int v2; // not accepted by the parser but this is the same as v1
attribute when  `T` is an `int`.
}

alias WithInt = BasicTypeUDA!int;
---

possible by simplifying the current rule for UDA this way:

UserDefinedAttribute:
    @ ( ArgumentList )
-    @ Identifier
-    @ Identifier ( ArgumentListopt )
-    @ TemplateInstance
-    @ TemplateInstance ( ArgumentListopt )
+    @ BasicType
+    @ BasicType ( ArgumentListopt )

since BasicType covers Identifier, TemplateInstance, builtin types and even
more. (https://dlang.org/spec/declaration.html#BasicType)

The @ guarantees that parsing will not become ambiguous.
This would simplify a bit the language by generalizing the use of the
construction syntax, although we all know that `@Type(args)` is just the short
for `@(Type(args))`.

--


More information about the Digitalmars-d-bugs mailing list