D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20464 - builtin types could be usable as UDA, without being enclosed in parens
Summary: builtin types could be usable as UDA, without being enclosed in parens
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
: 22338 (view as issue list)
Depends on:
Blocks:
 
Reported: 2019-12-22 17:32 UTC by basile-z
Modified: 2024-12-13 19:06 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description basile-z 2019-12-22 17:32:13 UTC
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))`.
Comment 1 basile-z 2021-09-28 04:54:09 UTC
*** Issue 22338 has been marked as a duplicate of this issue. ***
Comment 2 dlangBugzillaToGithub 2024-12-13 19:06:35 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19651

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB