digitalmars.D.learn - alias this and constructor
- Jack Applegame (13/13) Apr 12 2014 Why this code doesn't want to compile?
- Jack Applegame (1/1) Apr 12 2014 If you just comment out constructor, then it compiles.
- MrSmith (3/16) Apr 12 2014 Maybe, because compiler cannot distinguish between default
- Jack Applegame (3/5) Apr 12 2014 I don't think so. Without alias this, but with constructor it
- monarch_dodra (10/15) Apr 12 2014 The issue is that a call that was essentially supposed to do
- Jack Applegame (3/3) Apr 12 2014 And this doesn't compile too
- monarch_dodra (3/6) Apr 12 2014 Looks like it's something different. I think I know the cause.
- monarch_dodra (6/7) Apr 12 2014 Aye! That's my bad!
Why this code doesn't want to compile? import std.algorithm; import std.array; struct Foo { int a; this(int v) {} alias a this; } void main() { immutable(Foo)[] foo; auto arr = array(foo.filter!(o => true)); } http://dpaste.dzfl.pl/25572b0f6d0b
Apr 12 2014
If you just comment out constructor, then it compiles.
Apr 12 2014
On Saturday, 12 April 2014 at 11:48:36 UTC, Jack Applegame wrote:Why this code doesn't want to compile? import std.algorithm; import std.array; struct Foo { int a; this(int v) {} alias a this; } void main() { immutable(Foo)[] foo; auto arr = array(foo.filter!(o => true)); } http://dpaste.dzfl.pl/25572b0f6d0bMaybe, because compiler cannot distinguish between default constructor which takes int and your one, which also takes int.
Apr 12 2014
On Saturday, 12 April 2014 at 12:47:02 UTC, MrSmith wrote:Maybe, because compiler cannot distinguish between default constructor which takes int and your one, which also takes int.I don't think so. Without alias this, but with constructor it compiles.
Apr 12 2014
On Saturday, 12 April 2014 at 13:08:48 UTC, Jack Applegame wrote:On Saturday, 12 April 2014 at 12:47:02 UTC, MrSmith wrote:The issue is that a call that was essentially supposed to do nothing, accidentally calls your constructor. Because the call "that does nothing" was not expected to do much, it was marked as safe, pure and nothrow. This conflicts with your constructor, which is none of those. That's the explanation for the behavior you are seeing, it shouldn't be happening. You can work around it by marking your constructor as safe, pure and nothrow. https://github.com/D-Programming-Language/phobos/pull/1529#discussion_r7175502Maybe, because compiler cannot distinguish between default constructor which takes int and your one, which also takes int.I don't think so. Without alias this, but with constructor it compiles.
Apr 12 2014
And this doesn't compile too http://dpaste.dzfl.pl/1d48eed7e0fb The same reason?
Apr 12 2014
On Saturday, 12 April 2014 at 14:00:06 UTC, Jack Applegame wrote:And this doesn't compile too http://dpaste.dzfl.pl/1d48eed7e0fb The same reason?Looks like it's something different. I think I know the cause. Could you file it in the bug tracker? I will fix it.
Apr 12 2014
On Saturday, 12 April 2014 at 11:48:36 UTC, Jack Applegame wrote:Why this code doesn't want to compile?Aye! That's my bad! It's a bug I introduced, while fixing more bugs :/ The good news is it only affect 2.065.0. It's already fixed in HEAD. 1000 apologies.
Apr 12 2014