digitalmars.D.learn - Check attribute against value
- frame (25/25) Apr 02 2021 I have an attribute scope:
- rikki cattermole (5/5) Apr 02 2021 "Whether the attributes are values or types is up to the user, and
- frame (4/6) Apr 02 2021 omg - that's dumb - I was thinking the compiler whould be aware
I have an attribute scope: ``` PublicApi { // ... } ``` Querying with hasUDA! works as expected. Later, I added a property to PublicApi: ``` struct PublicApi { bool exposeDetails; } ``` And want to ask the compiler via getUDAs! about the boolean but this fails with: ```Error: type PublicApi has no value``` because I need to rewrite it to ``` PublicApi() { // ... } ``` ... which works again. But how do I check against such cases? And why does a struct not have a value here?
Apr 02 2021
"Whether the attributes are values or types is up to the user, and whether later attributes accumulate or override earlier ones is also up to how the user interprets them." This doesn't explain it well, but you were adding types as attributes on to those symbols. Not struct instances.
Apr 02 2021
On Saturday, 3 April 2021 at 04:03:14 UTC, rikki cattermole wrote:This doesn't explain it well, but you were adding types as attributes on to those symbols. Not struct instances.omg - that's dumb - I was thinking the compiler whould be aware of that. So, I need to check for isType! first, thanks.
Apr 02 2021