Overloads not returning appropriate info. [Field reflunkory]

Adam D. Ruppe destructionator at gmail.com
Fri Apr 5 15:13:36 UTC 2019


On Friday, 5 April 2019 at 14:38:21 UTC, Alex wrote:
> No one has a clue about this?

Your code has a lot of layers to unfold, but instead let me just 
show you a working example and then maybe you can fix your own 
code:

---
class A {
	void foo(int a) {}
	void foo(int b, int c) {}
}

void main() {
	import std.stdio;
	foreach(overload; __traits(getOverloads, A, "foo")) {
		writeln(typeof(overload).stringof);
		static if(is(typeof(overload) Params == __parameters))
			static foreach(idx, _; Params) {{
				alias param = Params[idx .. idx + 1];
				writeln("\t", __traits(identifier, param));
			}}
	}
}
---


I don't know if your bug is in your code or in std.traits or 
what, but this example works and prints out

void(int a)
         a
void(int b, int c)
         b
         c


The one bizarre thing is the `param = Params[idx .. idx + 1]` 
bit. I wrote a little about this for parameter attributes too

http://dpldocs.info/this-week-in-d/Blog.Posted_2019_02_11.html#how-to-get-uda-on-a-function-param

but it also applies to getting the identifier out.


More information about the Digitalmars-d-learn mailing list