Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
April 12, 2014 alias this and constructor | ||||
---|---|---|---|---|
| ||||
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 |
April 12, 2014 Re: alias this and constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | If you just comment out constructor, then it compiles. |
April 12, 2014 Re: alias this and constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | 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/25572b0f6d0b
Maybe, because compiler cannot distinguish between default constructor which takes int and your one, which also takes int.
|
April 12, 2014 Re: alias this and constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | 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.
|
April 12, 2014 Re: alias this and constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to MrSmith | 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.
|
April 12, 2014 Re: alias this and constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | 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: > >> 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. 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_r7175502 |
April 12, 2014 Re: alias this and constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | And this doesn't compile too http://dpaste.dzfl.pl/1d48eed7e0fb The same reason? |
April 12, 2014 Re: alias this and constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | 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.
|
Copyright © 1999-2021 by the D Language Foundation