Jump to page: 1 24  
Page
Thread overview
Overloads not returning appropriate info. [Field reflunkory]
Apr 04, 2019
Alex
Apr 05, 2019
Alex
Apr 05, 2019
Adam D. Ruppe
Apr 05, 2019
Adam D. Ruppe
Apr 06, 2019
Alex
Apr 06, 2019
Adam D. Ruppe
Apr 07, 2019
Alex
Apr 07, 2019
Paul Backus
Apr 07, 2019
Adam D. Ruppe
Apr 07, 2019
Alex
Apr 08, 2019
Adam D. Ruppe
Apr 08, 2019
Alex
Apr 08, 2019
Walter Bright
Apr 07, 2019
FeepingCreature
Apr 08, 2019
Adam D. Ruppe
Apr 09, 2019
Alex
Apr 09, 2019
Adam D. Ruppe
Apr 09, 2019
Alex
Apr 09, 2019
Seb
Apr 09, 2019
H. S. Teoh
Apr 09, 2019
Alex
Apr 09, 2019
H. S. Teoh
Apr 10, 2019
Adam D. Ruppe
Apr 10, 2019
H. S. Teoh
Apr 10, 2019
Adam D. Ruppe
Apr 10, 2019
Alex
Apr 10, 2019
Adam D. Ruppe
Apr 10, 2019
H. S. Teoh
Apr 10, 2019
Alex
Apr 09, 2019
Alex
Apr 10, 2019
Adam D. Ruppe
Apr 10, 2019
Adam D. Ruppe
Apr 10, 2019
Alex
April 04, 2019
Trying to get parameter info of an overloaded method, it doesn't return the names. The same code works fine for a free function.


	Id = foo
	TypeName =
	FullName = main.foo
	ModuleName = main
	MangledName = _D4main3fooFiKdfZv
	Protection = public
	Body =
	Uses = []
	Attributes = [
		sAttributeReflection("attr!string(\"test\", 432)", "attr!string"),
		sAttributeReflection("4", "int")
	]
	DType = function
	Signature = void(int x, ref double y, float z = 43234.3F)
	NumArgs = 3
	Linkage = D
	ReturnType = void
	Parameters = [
		sParameterReflection("x", "int", "void", "void", sStorageClass(false, false, false, false, false, false)),
		sParameterReflection("y", "double", "void", "void", sStorageClass(false, false, false, true, false, false)),
		sParameterReflection("z", "float", "43234.3F", "float", sStorageClass(false, false, false, false, false, false))
	]



vs





	Methods = [
		Id = foo
		TypeName = int()
		FullName = mModel.cDerived!(int).foo
		ModuleName = mModel
		MangledName = 6mModel__T8cDerivedTiZQm3foo
		Protection = public
		Body =
		Uses = []
		Attributes = [sAttributeReflection("A", "string")]
		Signature = int()
		NumArgs = 0
		Linkage = D
		ReturnType = int
		Parameters = []
		DType = delegate
		Overloads = []
		,
		Id = foo
		TypeName = pure nothrow @nogc @safe int(int, inout(float))
		FullName = mModel.cDerived!(int).foo
		ModuleName = mModel
		MangledName = 6mModel__T8cDerivedTiZQm3foo
		Protection = public
		Body =
		Uses = []
		Attributes = [sAttributeReflection("A", "string")]
		Signature = pure nothrow @nogc @safe int(int, inout(float))
		NumArgs = 2
		Linkage = D
		ReturnType = int
		Parameters = [
			sParameterReflection("", "int", "void", "void", sStorageClass(false, false, false, false, false, false)),
			sParameterReflection("", "inout(float)", "void", "void", sStorageClass(false, false, false, false, false, false))
		]
		DType = delegate
		Overloads = []
		,




sParameterReflection("z", "float", "43234.3F", "float", sStorageClass(false, false, false, false, false, false))

vs

sParameterReflection("", "int", "void", "void", sStorageClass(false, false, false, false, false, false)),

notice that some info is field out but not all.

The code is here:
https://github.com/IncipientDesigns/Dlang_Reflect/blob/master/mReflect.d

The Base, Aggregate, Function, and Method classes are the appropriate ones to look at. cFunctionReflection does all the work though

[Field reflunkory]

Also, with

cFieldReflection I cannot pass the field as a type on to the base class to reduce code duplication. Ideally I should be able to pass a field around as a type so that reflection can occur on it. This seems like a language design issue but maybe there is a trick?




April 05, 2019
No one has a clue about this?
April 05, 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.
April 05, 2019
BTW `T.stringof` is usually a bug waiting to happen. You are using mixin in a lot of places where you shouldn't be and this is going to lead to name conflicts, import problems, and more. Just use `T`.

If you need a member, use __traits(getMember, T, "name").
April 06, 2019
On Friday, 5 April 2019 at 15:38:18 UTC, Adam D. Ruppe wrote:
> BTW `T.stringof` is usually a bug waiting to happen. You are using mixin in a lot of places where you shouldn't be and this is going to lead to name conflicts, import problems, and more. Just use `T`.
>
> If you need a member, use __traits(getMember, T, "name").

I fixed the parameter info issue and rewrote a large portion of the code to work better, the main problem was that I was doing

static foreach (f; typeof(__traits(getOverloads, T, m)))

but now I get

 Error: variable `std.traits.ParameterDefaults!(foo).Get!1u.Get` only parameters or stack based variables can be `inout`

sParameterReflection("y", "inout(float)", "void", "void", sStorageClass(false, false, false, false, false, false)),

for

pure nothrow @nogc @safe int(int x, inout(float) y = 4.00000F, double x7 = 434.3)

inout clearly has a default value but an error is given. All other default values are returning correctly.


	static if (__traits(compiles, typeof(ParameterDefaults!T[k])))
		{
			enum pd = ParameterDefaults!T[k];
			alias dt = typeof(pd);

		}
		else
		{
			alias dt = void;
			alias pd = void;
		}

t.Parameters ~= sParameterReflection(ParameterIdentifierTuple!T[k], a.stringof, pd.stringof, dt.stringof);		

Without the __traits compiles the error occurs in the enum by simply taking ParameterDefaults.


---------------------------------------------------
The mixin code with T are to build compound names. I never use a mixin for just accessing T alone as far as I know, you are going to have to be more clear on what you are talking about here.

probably 90% of the mixins are of the form

mixin(`Protection = __traits(getProtection, (`~T.stringof~`).`~name~`);`);

Where I have to build the type info, such things as

Protection = __traits(getProtection, T.name);

will definitely not work.



-------------------------

This is now the output of the code and everything seems to basically work now except the above issue.



	Id = cDerived
	TypeName = cDerived!int
	FullName = mModel.cDerived!(int)
	ModuleName = mModel
	MangledName = C6mModel__T8cDerivedTiZQm
	Protection = public
	Body =
	Uses = []
	Attributes = [
		sAttributeReflection("fdsa", "string"),
		sAttributeReflection("8", "int")
	]
	IsNested = false
	IsInnerClass = false
	HasUnsharedAliasing = true
	HasNested = false
	HasIndirections = true
	HasElaborateDestructor = false
	HasElaborateCopyConstructor = false
	HasElaborateAssign = false
	HasAliasing = true
	TypeParameters = []
	AliasThis = [sTypeReflection("type", "cType")]
	NestedAggregates = []
	DerivedClasses = []
	Fields = [
		Id = type
		TypeName = cDerived!int.type
		FullName = mModel.cDerived!(int).type
		ModuleName = mModel
		MangledName = C6mModel__T8cDerivedTiZQm
		Protection = public
		Body =
		Uses = []
		Attributes = []
		DType = field
		,
		Id = testField1
		TypeName = cDerived!int.testField1
		FullName = mModel.cDerived!(int).testField1
		ModuleName = mModel
		MangledName = C6mModel__T8cDerivedTiZQm
		Protection = public
		Body =
		Uses = []
		Attributes = [sAttributeReflection("XXXRRERES", "string")]
		DType = field
		,
		Id = testField2
		TypeName = cDerived!int.testField2
		FullName = mModel.cDerived!(int).testField2
		ModuleName = mModel
		MangledName = C6mModel__T8cDerivedTiZQm
		Protection = private
		Body =
		Uses = []
		Attributes = [sAttributeReflection("XXXRRERES4", "string")]
		DType = field
	]
	Methods = [
		Id = foo
		TypeName =
		FullName = mModel.cDerived!(int).foo
		ModuleName = mModel
		MangledName = _D6mModel__T8cDerivedTiZQm3fooMFZi
		Protection = public
		Body =
		Uses = []
		Attributes = [sAttributeReflection("A", "string")]
		Signature = int()
		NumArgs = 0
		Linkage = D
		ReturnType = int
		Parameters = []
		Overloads = [
			Id = foo
			TypeName =
			FullName = mModel.cDerived!(int).foo
			ModuleName = mModel
			MangledName = _D6mModel__T8cDerivedTiZQm3fooMFNaNbNiNfiNgfdZi
			Protection = private
			Body =
			Uses = []
			Attributes = [sAttributeReflection("B", "string")]
			DType = function
			Signature = pure nothrow @nogc @safe int(int x, inout(float) y = 4.00000F, double x7 = 434.3)
			NumArgs = 3
			Linkage = D
			ReturnType = int
			Parameters = [
				sParameterReflection("x", "int", "void", "void", sStorageClass(false, false, false, false, false, false)),
				sParameterReflection("y", "inout(float)", "void", "void", sStorageClass(false, false, false, false, false, false)),
				sParameterReflection("x7", "double", "void", "void", sStorageClass(false, false, false, false, false, false))
			]
			,
			Id = foo
			TypeName =
			FullName = mModel.cDerived!(int).foo
			ModuleName = mModel
			MangledName = _D6mModel__T8cDerivedTiZQm3fooMFiKdlfZi
			Protection = public
			Body =
			Uses = []
			Attributes = [
				sAttributeReflection("attr!string(\"test\", 432)", "attr!string"),
				sAttributeReflection("4", "int")
			]
			DType = function
			Signature = int(int x, ref double y, long q = 3L, float z = 43234.3F)
			NumArgs = 4
			Linkage = D
			ReturnType = int
			Parameters = [
				sParameterReflection("x", "int", "void", "void", sStorageClass(false, false, false, false, false, false)),
				sParameterReflection("y", "double", "void", "void", sStorageClass(false, false, false, true, false, false)),
				sParameterReflection("q", "long", "3L", "long", sStorageClass(false, false, false, false, false, false)),
				sParameterReflection("z", "float", "43234.3F", "float", sStorageClass(false, false, false, false, false, false))
			]
		]
		DType = delegate
		,
		Id = foo
		TypeName =
		FullName = mModel.cDerived!(int).foo
		ModuleName = mModel
		MangledName = _D6mModel__T8cDerivedTiZQm3fooMFZi
		Protection = public
		Body =
		Uses = []
		Attributes = [sAttributeReflection("A", "string")]
		Signature = int()
		NumArgs = 0
		Linkage = D
		ReturnType = int
		Parameters = []
		Overloads = [
			Id = foo
			TypeName =
			FullName = mModel.cDerived!(int).foo
			ModuleName = mModel
			MangledName = _D6mModel__T8cDerivedTiZQm3fooMFNaNbNiNfiNgfdZi
			Protection = private
			Body =
			Uses = []
			Attributes = [sAttributeReflection("B", "string")]
			DType = function
			Signature = pure nothrow @nogc @safe int(int x, inout(float) y = 4.00000F, double x7 = 434.3)
			NumArgs = 3
			Linkage = D
			ReturnType = int
			Parameters = [
				sParameterReflection("x", "int", "void", "void", sStorageClass(false, false, false, false, false, false)),
				sParameterReflection("y", "inout(float)", "void", "void", sStorageClass(false, false, false, false, false, false)),
				sParameterReflection("x7", "double", "void", "void", sStorageClass(false, false, false, false, false, false))
			]
			,
			Id = foo
			TypeName =
			FullName = mModel.cDerived!(int).foo
			ModuleName = mModel
			MangledName = _D6mModel__T8cDerivedTiZQm3fooMFiKdlfZi
			Protection = public
			Body =
			Uses = []
			Attributes = [
				sAttributeReflection("attr!string(\"test\", 432)", "attr!string"),
				sAttributeReflection("4", "int")
			]
			DType = function
			Signature = int(int x, ref double y, long q = 3L, float z = 43234.3F)
			NumArgs = 4
			Linkage = D
			ReturnType = int
			Parameters = [
				sParameterReflection("x", "int", "void", "void", sStorageClass(false, false, false, false, false, false)),
				sParameterReflection("y", "double", "void", "void", sStorageClass(false, false, false, true, false, false)),
				sParameterReflection("q", "long", "3L", "long", sStorageClass(false, false, false, false, false, false)),
				sParameterReflection("z", "float", "43234.3F", "float", sStorageClass(false, false, false, false, false, false))
			]
		]
		DType = delegate
		,
		Id = ValueProp
		TypeName =
		FullName = mModel.cDerived!(int).ValueProp
		ModuleName = mModel
		MangledName = _D6mModel__T8cDerivedTiZQm9ValuePropMFNdZi
		Protection = public
		Body =
		Uses = []
		Attributes = [sAttributeReflection("VP att", "string")]
		Signature = @property int()
		NumArgs = 0
		Linkage = D
		ReturnType = int
		Parameters = []
		Overloads = []
		DType = delegate
	]
	InheritedInterfaces = [
		Id = iX
		TypeName = iX
		FullName = mModel.iX
		ModuleName = mModel
		MangledName = C6mModel2iX
		Protection = public
		Body =
		Uses = []
		Attributes = []
		IsNested = false
		IsInnerClass = false
		HasUnsharedAliasing = true
		HasNested = false
		HasIndirections = true
		HasElaborateDestructor = false
		HasElaborateCopyConstructor = false
		HasElaborateAssign = false
		HasAliasing = true
		TypeParameters = []
		AliasThis = []
		NestedAggregates = []
		DerivedClasses = []
		Fields = [
			Id =
			TypeName =
			FullName =
			ModuleName =
			MangledName =
			Protection =
			Body =
			Uses = []
			Attributes = []
			DType = field
		]
		Methods = []
		DType = interface
		InheritedInterfaces = []
		,
		Id = iY
		TypeName = iY
		FullName = mModel.iY
		ModuleName = mModel
		MangledName = C6mModel2iY
		Protection = public
		Body =
		Uses = []
		Attributes = []
		IsNested = false
		IsInnerClass = false
		HasUnsharedAliasing = true
		HasNested = false
		HasIndirections = true
		HasElaborateDestructor = false
		HasElaborateCopyConstructor = false
		HasElaborateAssign = false
		HasAliasing = true
		TypeParameters = []
		AliasThis = []
		NestedAggregates = []
		DerivedClasses = []
		Fields = [
			Id =
			TypeName =
			FullName =
			ModuleName =
			MangledName =
			Protection =
			Body =
			Uses = []
			Attributes = []
			DType = field
		]
		Methods = []
		DType = interface
		InheritedInterfaces = []
	]
	DType = class
	IsAbstract = false
	Alignment = 8
	InheritedClasses = [
		Id = cBase
		TypeName = cBase
		FullName = mModel.cBase
		ModuleName = mModel
		MangledName = C6mModel5cBase
		Protection = public
		Body =
		Uses = []
		Attributes = []
		IsNested = false
		IsInnerClass = false
		HasUnsharedAliasing = true
		HasNested = false
		HasIndirections = true
		HasElaborateDestructor = false
		HasElaborateCopyConstructor = false
		HasElaborateAssign = false
		HasAliasing = true
		TypeParameters = []
		AliasThis = []
		NestedAggregates = []
		DerivedClasses = []
		Fields = [
			Id = testField
			TypeName = cBase.testField
			FullName = mModel.cBase.testField
			ModuleName = mModel
			MangledName = C6mModel5cBase
			Protection = public
			Body =
			Uses = []
			Attributes = []
			DType = field
		]
		Methods = [
			Id = fooBase
			TypeName =
			FullName = mModel.cBase.fooBase
			ModuleName = mModel
			MangledName = _D6mModel5cBase7fooBaseMFCQy5iBaseZCQBiQBe
			Protection = public
			Body =
			Uses = []
			Attributes = []
			Signature = cBase(iBase c)
			NumArgs = 1
			Linkage = D
			ReturnType = cBase
			Parameters = [
				sParameterReflection("c", "iBase", "void", "void", sStorageClass(false, false, false, false, false, false))
			]
			Overloads = []
			DType = delegate
		]
		InheritedInterfaces = [
			Id = iBase
			TypeName = iBase
			FullName = mModel.iBase
			ModuleName = mModel
			MangledName = C6mModel5iBase
			Protection = public
			Body =
			Uses = []
			Attributes = [
				sAttributeReflection("fdsa", "string"),
				sAttributeReflection("4", "int")
			]
			IsNested = false
			IsInnerClass = false
			HasUnsharedAliasing = true
			HasNested = false
			HasIndirections = true
			HasElaborateDestructor = false
			HasElaborateCopyConstructor = false
			HasElaborateAssign = false
			HasAliasing = true
			TypeParameters = []
			AliasThis = []
			NestedAggregates = []
			DerivedClasses = []
			Fields = [
				Id =
				TypeName =
				FullName =
				ModuleName =
				MangledName =
				Protection =
				Body =
				Uses = []
				Attributes = []
				DType = field
			]
			Methods = [
				Id = fooBase
				TypeName =
				FullName = mModel.iBase.fooBase
				ModuleName = mModel
				MangledName = _D6mModel5iBase7fooBaseMFCQyQtZQg
				Protection = public
				Body =
				Uses = []
				Attributes = []
				Signature = iBase(iBase)
				NumArgs = 1
				Linkage = D
				ReturnType = iBase
				Parameters = [
					sParameterReflection("", "iBase", "void", "void", sStorageClass(false, false, false, false, false, false))
				]
				Overloads = []
				DType = delegate
			]
			DType = interface
			InheritedInterfaces = []
		]
		DType = class
		IsAbstract = false
		Alignment = 4
		InheritedClasses = [Object]
	]

	Id = bar
	TypeName =
	FullName = mMain.bar
	ModuleName = mMain
	MangledName = _D5mMain3barFiKdfZv
	Protection = public
	Body =
	Uses = []
	Attributes = [
		sAttributeReflection("attr!string(\"test\", 432)", "attr!string"),
		sAttributeReflection("4", "int")
	]
	DType = function
	Signature = void(int x, ref double y, float z = 43234.3F)
	NumArgs = 3
	Linkage = D
	ReturnType = void
	Parameters = [
		sParameterReflection("x", "int", "void", "void", sStorageClass(false, false, false, false, false, false)),
		sParameterReflection("y", "double", "void", "void", sStorageClass(false, false, false, true, false, false)),
		sParameterReflection("z", "float", "43234.3F", "float", sStorageClass(false, false, false, false, false, false))
	]
	Overloads = [
		Id = bar
		TypeName =
		FullName = mMain.bar
		ModuleName = mMain
		MangledName = _D5mMain3barFiKdlfZv
		Protection = public
		Body =
		Uses = []
		Attributes = [sAttributeReflection("564", "int")]
		DType = function
		Signature = void(int x, ref double y, long q = 3L, float z = 43234.3F)
		NumArgs = 4
		Linkage = D
		ReturnType = void
		Parameters = [
			sParameterReflection("x", "int", "void", "void", sStorageClass(false, false, false, false, false, false)),
			sParameterReflection("y", "double", "void", "void", sStorageClass(false, false, false, true, false, false)),
			sParameterReflection("q", "long", "3L", "long", sStorageClass(false, false, false, false, false, false)),
			sParameterReflection("z", "float", "43234.3F", "float", sStorageClass(false, false, false, false, false, false))
		]
	]



April 06, 2019
On Saturday, 6 April 2019 at 12:20:28 UTC, Alex wrote:
> static foreach (f; typeof(__traits(getOverloads, T, m)))

Why are you using typeof here?

> probably 90% of the mixins are of the form
>
> mixin(`Protection = __traits(getProtection, (`~T.stringof~`).`~name~`);`);


Try following this rule:

NEVER use .stringof.

> Protection = __traits(getProtection, T.name);

But (unless T.name is private; this is a design flaw in __traits(getProtection)),

__traits(getProtection, __traits(getMember, T, name))

will work.
April 07, 2019
On Saturday, 6 April 2019 at 13:03:31 UTC, Adam D. Ruppe wrote:
> On Saturday, 6 April 2019 at 12:20:28 UTC, Alex wrote:
>> static foreach (f; typeof(__traits(getOverloads, T, m)))
>
> Why are you using typeof here?

I don't know, I want to say I copied that code from somewhere but it might have been a left over or when I was trying to get the code to work. Since it partially worked(notice that it "works" and only gives the errors in parameters).

>> probably 90% of the mixins are of the form
>>
>> mixin(`Protection = __traits(getProtection, (`~T.stringof~`).`~name~`);`);
>
>
> Try following this rule:
>
> NEVER use .stringof.

rules are meant to be broken. As I mentioned in the other post it doesn't help when writing the mixin as a pragma to inform one of the actual type being used.

I'd say the rule is actually crap because of this(if debugging mixins and meta code had more support it might be a good rule but it's very helpful to know the type. Sure we can add a pragma(msg, T) but sometimes I just replace mixin( with pragma(msg, and I want something more than it display T. I want to see the full string to make sure it is formatted correctly what what is being used for T.

What you need to tell me is why using .stringof is bad. You have simply conjured up a rule and are stating it but not giving any reason why it is not a good idea to follow when, in fact, not following can be shown to be beneficial.

You can't expect to lead by authority. Give a good reason why I should avoid it and change my current ways and I will. Just telling me to do it won't change my mind.

The only reason I can see why it is a good rule is that one doesn't have to use T.stringof when they can just use T directly, making the code a little easier to read.

But I've pointed out that T.stringof has it's use when viewing the mixin as a string, which overrides your rule if the only reason is it's not technically needed.

See, it might just be your own bias that makes you not like it when in reality it might not matter either way. So far it seems it is your bias but I hope you have a good objective reason why as it would same a few characters in typing. A good reason is "It breaks the compiler in these cases" or "It causes this problem here when you do this".

If it's just about code readability then I will keep using them and maybe when I get the code in to shape I will try to format it to take them out. But in that case you have to learn to accept them in prototyping because then they are useful for mixin->pragma(msg,






>> Protection = __traits(getProtection, T.name);
>
> But (unless T.name is private; this is a design flaw in __traits(getProtection)),
>
> __traits(getProtection, __traits(getMember, T, name))
>
> will work.

Ok, so I used it and it got rid of one error where I get the protection.


I still get a protection issue for a private field using this code though:

mixin(`static foreach(a;  __traits(getAttributes, T.`~name~`)) Attributes ~= sAttributeReflection(to!string(a), typeof(a).stringof);`);

So it seems like the same design flaw exists? Have any work arounds for that?


Thanks for your help!

April 07, 2019
On 4/6/19 11:47 PM, Alex wrote:
> What you need to tell me is why using .stringof is bad. You have simply conjured up a rule and are stating it but not giving any reason why it is not a good idea to follow when, in fact, not following can be shown to be beneficial.

I'm not Adam, but I've also run into problems with .stringof, and have found avoiding it to be a good idea in a lot of situations.

The problem with .stringof and string mixins is that types and symbols carry information about their context with them--what module they're from, what scope they're defined in, etc. This is why, for example, you can pass a type defined in module a to a template defined in module b and have it work without needed to add `import a` to module b.

When you convert a type or symbol to a string using .stringof, all of this context information is stripped away. And in many cases, once that information has been lost, it's impossible to recover. For example, if all you have is the string "S", and two modules in your program define a `struct S`, there's no way to know which one of those types your string refers to.

If you say, "fine, I'll just use fully-qualified names," well, that doesn't work either, because some types in D don't *have* externally-visible names [1]. If you convert a type like that to a string, you can never get the original type (with its context info) back, no matter what you do.

All that said, it's perfectly fine to use .stringof for debugging and custom error messages. But if you're using it to generate code, you are almost certainly making a mistake.

[1] https://wiki.dlang.org/Voldemort_types
April 07, 2019
On Sunday, 7 April 2019 at 03:47:25 UTC, Alex wrote:
> What you need to tell me is why using .stringof is bad. You have simply conjured up a rule and are stating it but not giving any reason why it is not a good idea to follow when, in fact, not following can be shown to be beneficial.
>
> You can't expect to lead by authority. Give a good reason why I should avoid it and change my current ways and I will.

I have a couple times times now.

https://forum.dlang.org/post/nvpsrxxkfmbbxognjsit@forum.dlang.org

https://forum.dlang.org/post/fahrmmocegtthztzgkaa@forum.dlang.org

I go into a lot of detail in the link on the second link.

And the pains you are personally experiencing are a direct result of stringof. If you were to actually following my rule, you'd learn by doing how much better it is.



> So it seems like the same design flaw exists? Have any work arounds for that?

It won't work for private, you can use static if __traits(compiles) as a filter to get rid of them.
April 07, 2019
On Sunday, 7 April 2019 at 03:47:25 UTC, Alex wrote:
> rules are meant to be broken.

No they're not! Almost by definition not!

More comprehensively, if you break a rule you take responsibility for the outcome. You wanna use stringof? "Don't use stringof for that." "rules are meant to be broken." -- "Wah, my code doesn't work, stringof is shit, bad design, fix D pls." Don't ask questions if you don't care about the answers. More importantly, don't ignore advice and then complain about it.

> You can't expect to lead by authority. Give a good reason why I should avoid it and change my current ways and I will.

Your code will break in surprising and unfixable ways. `stringof` is not *for* mixin. If you use it for mixin, you will be on your own design-wise. The language will not be changed to "fix" the "bugs" you run into. It will work until it won't work, and then you'll have to rewrite the entire thing anyway.

Don't use stringof for mixin.
« First   ‹ Prev
1 2 3 4