You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow additional meta information (attributes) to be attached with enums and functions parameters, including built-in attributes such as `deprecated`.
14
+
15
+
### Links
16
+
17
+
[Does it require a DIP?](http://forum.dlang.org/thread/cltyrthdxkkfvuxqasqw@forum.dlang.org)
18
+
19
+
## Rationale
20
+
21
+
It is currently not possible to attach attributes to both enums and function parameters. This excludes a few features that can be used with almost any other symbol in D. Attributes and User Defined Attributes serve as a means to provide extra meta data for a symbol. What can be said for why attributes were included as a feature in D can also be said for why they should be extended to enums and function parameters. It is benefitial to provide extra meta data about a symbol that can be used at compile-time.
22
+
23
+
## Description
24
+
25
+
TBD
26
+
27
+
## Existing Solutions
28
+
29
+
Existing solutions exist only for UDAs, for an attribute such a `deprecated`, there is no existing solution to receive the desired effect.
30
+
31
+
Apply UDA through parent symbol with additional information for which child it should be applied to:
32
+
33
+
```D
34
+
@MyUda("feature0", "...")
35
+
enum SomeEnum
36
+
{
37
+
feature0,
38
+
feature1,
39
+
feature2,
40
+
}
41
+
42
+
@MyUda("param0", "...")
43
+
void foo(int param0)
44
+
{
45
+
}
46
+
47
+
```
48
+
49
+
This allows the desired UDA to be used and associated with the desired symbol. It introduces some duplication and the information stored in the UDA is separated from the rest of the information of the symbol.
50
+
51
+
52
+
### Examples
53
+
54
+
Allowing to deprecate enums which should not be used anymore:
55
+
56
+
```D
57
+
enum SomeEnum
58
+
{
59
+
feature0,
60
+
feature1,
61
+
62
+
deprecated("use feature0 or feature1 instead")
63
+
feature2,
64
+
}
65
+
```
66
+
67
+
Provide information on function parameters for use with scripting languages or other type evaluation:
68
+
69
+
```D
70
+
enum ScriptType
71
+
{
72
+
vehicle,
73
+
character,
74
+
scenery,
75
+
}
76
+
77
+
// scripting language can now know that the index is of a specific type
78
+
// the scripting language not being aware that it is just an index
79
+
void someFunction(string name, @ScriptType.vehicle int vehicleIndex)
80
+
{
81
+
// ...
82
+
}
83
+
```
84
+
85
+
Providing extra attributes that can be used to take advantage of knowledge known about the function parameters:
86
+
87
+
```D
88
+
89
+
extern(C) void fetch(@NonNull int* ptr)
90
+
{
91
+
// ...
92
+
}
93
+
```
94
+
95
+
## Copyright & License
96
+
97
+
Licensed under [Creative Commons Zero 1.0](https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt)
0 commit comments