Extracting user defined attributes on function parameters

Adam D. Ruppe destructionator at gmail.com
Fri Apr 17 16:54:42 UTC 2020

On Friday, 17 April 2020 at 16:40:15 UTC, Jean-Louis Leroy wrote:
> Alas the presence of parameter UDAs breaks 
> std.traits.ParameterDefaults:
> import std.traits;
> struct attr;
> void f(@attr int);

This part seems fine...

> pragma(msg, ParameterDefaults!f.stringof);

It is this, specifically, that causes the problem. Replace it 

void main() {
         import std.stdio;

and it is fine.

So pragma(msg) is doing something really weird, the bug doesn't 
appear to be in Phobos per se, I think it is the compiler doing 
the wrong thing, it seems to me it works inside a function scope 
but not at module scope......

> I'd like to understand why taking a slice of __parameters vs 
> fetching the first element matters. What is the (meta?) type of 
> __parameters[0..1]?

The first element alone becomes a type. The slice maintains the 
magic data inside the compiler; it contains stuff the rest of the 
language cannot express by itself except in parameter lists.

It is weird.

> collapses into a string. Makes me think of wave functions in 
> quantum mechanics ;-)

well it is dependent on when the compiler observes it sooooo lol

More information about the Digitalmars-d-learn mailing list