| Thread overview | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 14, 2014 [Issue 13079] Need 'this' to access member - function literal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13079 hsteoh@quickfur.ath.cx changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hsteoh@quickfur.ath.cx --- Comment #1 from hsteoh@quickfur.ath.cx --- Are you sure that's valid syntax? Don't you mean this: ---- class Test { mixin(string func() { return ""; }); } ---- The diagnostic should be improved, though. The current error message doesn't make sense. -- | ||||
July 14, 2014 [Issue 13079] Need 'this' to access member - function literal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13079 --- Comment #2 from Daniel Čejchan <czdanol@gmail.com> --- (In reply to hsteoh from comment #1) > Are you sure that's valid syntax? Don't you mean this: > ---- > class Test { > mixin(string func() { > return ""; > }); > } > ---- > The diagnostic should be improved, though. The current error message doesn't make sense. That one can't be compiled either. -- | ||||
July 14, 2014 [Issue 13079] Need 'this' to access member - function literal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13079 --- Comment #3 from hsteoh@quickfur.ath.cx --- Sorry, it should be: ---- class Test { mixin({ return ""; }()); } ---- -- | ||||
July 14, 2014 [Issue 13079] Need 'this' to access member - function literal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13079 --- Comment #4 from Daniel Čejchan <czdanol@gmail.com> --- (In reply to hsteoh from comment #3) > Sorry, it should be: > ---- > class Test { > mixin({ return ""; }()); > } > ---- Neither that one can be compiled :P http://dpaste.dzfl.pl/6fa47fdf9f35 -- | ||||
July 14, 2014 [Issue 13079] Need 'this' to access member - function literal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13079 --- Comment #5 from hsteoh@quickfur.ath.cx --- Hmm. That one works in git HEAD. Is it a bug that was recently fixed? -- | ||||
July 14, 2014 [Issue 13079] Need 'this' to access member - function literal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13079 --- Comment #6 from hsteoh@quickfur.ath.cx --- I'm also curious why you want this odd construction to work. I assume you have a non-trivial use case in mind? Because otherwise, you could just write mixin(""); directly instead of going a roundabout way using function literals. -- | ||||
July 14, 2014 [Issue 13079] Need 'this' to access member - function literal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13079 --- Comment #7 from Daniel Čejchan <czdanol@gmail.com> --- (In reply to hsteoh from comment #6) > I'm also curious why you want this odd construction to work. I assume you have a non-trivial use case in mind? Because otherwise, you could just write mixin(""); directly instead of going a roundabout way using function literals. http://pastebin.com/r1nwiQUK -- | ||||
July 14, 2014 [Issue 13079] Need 'this' to access member - function literal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13079 --- Comment #8 from hsteoh@quickfur.ath.cx --- Ahh, I see. So you're basically using mixin as a macro system for generating code inside a single class. Makes sense. The following code works for me (dmd git HEAD): ---- import std.string; class C { mixin({ string code=""; foreach (i; 0..10) { code ~= format("int x%d;\n", i); } return code; }()); } void main() { foreach (memb; __traits(allMembers, C)) { static if (is(typeof(__traits(getMember, C.init, memb)) T)) { pragma(msg, memb); } } } ---- So obviously, it's possible to use a code block to generate declarations inside the class, at least on dmd git HEAD. You should be able to adapt this code to your needs. (The code in main() is just to prove that those declarations actually got inserted, you can ignore it.) Which version of dmd are you using? -- | ||||
July 15, 2014 [Issue 13079] Need 'this' to access member - function literal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13079 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |DUPLICATE --- Comment #9 from Kenji Hara <k.hara.pg@gmail.com> --- (In reply to hsteoh from comment #5) > Hmm. That one works in git HEAD. Is it a bug that was recently fixed? Dup of issue 11545, and it will be properly fixed in 2.066 release. *** This issue has been marked as a duplicate of issue 11545 *** -- | ||||
July 15, 2014 [Issue 13079] Need 'this' to access member - function literal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13079 --- Comment #10 from Daniel Čejchan <czdanol@gmail.com> --- (In reply to hsteoh from comment #8) > Ahh, I see. So you're basically using mixin as a macro system for generating code inside a single class. Makes sense. > > The following code works for me (dmd git HEAD): > ... > So obviously, it's possible to use a code block to generate declarations > inside the class, at least on dmd git HEAD. You should be able to adapt this > code to your needs. (The code in main() is just to prove that those > declarations actually got inserted, you can ignore it.) > > Which version of dmd are you using? http://dpaste.dzfl.pl/2f156080d7e3 :P DPaste has 2.065 -- | ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply