digitalmars.D.learn - __traits(compiles) + mixin
- cal (14/14) Mar 04 2013 I'm confused about this:
- Andrej Mitrovic (4/18) Mar 05 2013 You can't test declarations inside of __traits(compiles), only
- cal (9/12) Mar 05 2013 So why does this work:
- simendsjo (4/16) Mar 05 2013 Hmm.. And this also works:
- cal (4/7) Mar 05 2013 But it gets this right, in that c is false. I had thought that by
- Andrej Mitrovic (2/10) Mar 05 2013 That's a function literal, i.e. an expression.
- simendsjo (3/24) Mar 05 2013 The errormessage is rather cryptic though.. Makes it look like
- Timon Gehr (2/14) Mar 05 2013 Compiles as expected with DMD 2.060. It is probably a regression.
- cal (2/4) Mar 05 2013 Ah you're right, also with 2.061. I'll file.
I'm confused about this: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto a = new "~s~";}")); // line 1 mixin("auto a = "~s~";"); // line 2 } This does not compile, giving errors about instantiating std.conv.to!(int).to!(string). If I switch the order of lines 1 and 2 it compiles. Is this a bug or something I don't understand about __traits(compiles)?
Mar 04 2013
On Tuesday, 5 March 2013 at 07:53:15 UTC, cal wrote:I'm confused about this: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto a = new "~s~";}")); // line 1 mixin("auto a = "~s~";"); // line 2 } This does not compile, giving errors about instantiating std.conv.to!(int).to!(string). If I switch the order of lines 1 and 2 it compiles. Is this a bug or something I don't understand about __traits(compiles)?You can't test declarations inside of __traits(compiles), only expressions. It's in the docs: http://dlang.org/traits.html#compiles
Mar 05 2013
On Tuesday, 5 March 2013 at 08:04:12 UTC, Andrej Mitrovic wrote:You can't test declarations inside of __traits(compiles), only expressions. It's in the docs: http://dlang.org/traits.html#compilesSo why does this work: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto x = "~s~";}")); // true }
Mar 05 2013
On Tuesday, 5 March 2013 at 08:09:37 UTC, cal wrote:On Tuesday, 5 March 2013 at 08:04:12 UTC, Andrej Mitrovic wrote:Hmm.. And this also works: enum c = __traits(compiles, mixin("{auto a = new 1;}")); Something to do with CTFE combined with mixins?You can't test declarations inside of __traits(compiles), only expressions. It's in the docs: http://dlang.org/traits.html#compilesSo why does this work: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto x = "~s~";}")); // true }
Mar 05 2013
On Tuesday, 5 March 2013 at 08:14:58 UTC, simendsjo wrote:Hmm.. And this also works: enum c = __traits(compiles, mixin("{auto a = new 1;}")); Something to do with CTFE combined with mixins?But it gets this right, in that c is false. I had thought that by wrapping the declaration in braces, making it a function, that got around the 'no declarations' limitation.
Mar 05 2013
On 3/5/13, cal <callumenator gmail.com> wrote:So why does this work: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto x = "~s~";}")); // true }That's a function literal, i.e. an expression.
Mar 05 2013
On Tuesday, 5 March 2013 at 08:04:12 UTC, Andrej Mitrovic wrote:On Tuesday, 5 March 2013 at 07:53:15 UTC, cal wrote:The errormessage is rather cryptic though.. Makes it look like there is something with conv rather than compiles.I'm confused about this: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto a = new "~s~";}")); // line 1 mixin("auto a = "~s~";"); // line 2 } This does not compile, giving errors about instantiating std.conv.to!(int).to!(string). If I switch the order of lines 1 and 2 it compiles. Is this a bug or something I don't understand about __traits(compiles)?You can't test declarations inside of __traits(compiles), only expressions. It's in the docs: http://dlang.org/traits.html#compiles
Mar 05 2013
On 03/05/2013 08:53 AM, cal wrote:I'm confused about this: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto a = new "~s~";}")); // line 1 mixin("auto a = "~s~";"); // line 2 } This does not compile, giving errors about instantiating std.conv.to!(int).to!(string). If I switch the order of lines 1 and 2 it compiles. Is this a bug or something I don't understand about __traits(compiles)?Compiles as expected with DMD 2.060. It is probably a regression.
Mar 05 2013
On Tuesday, 5 March 2013 at 12:58:57 UTC, Timon Gehr wrote:Compiles as expected with DMD 2.060. It is probably a regression.Ah you're right, also with 2.061. I'll file.
Mar 05 2013