digitalmars.D.learn - Bug or feature?
- Jack Applegame (19/19) Jun 28 2015 I don't see any reason why it should not compile.
- Adam D. Ruppe (2/2) Jun 28 2015 I'd say bug, I think the array function is trying an optimization
- Jack Applegame (1/1) Jun 30 2015 https://issues.dlang.org/show_bug.cgi?id=14751
- Jonathan M Davis via Digitalmars-d-learn (12/31) Jun 29 2015 You haven't declared an immutable constructor, so you can't construct an
- anonymous (3/5) Jun 29 2015 That's not what's happening. Constructing an immutable Foo works
- Jonathan M Davis (3/8) Jun 30 2015 Then I stand corrected.
- Daniel =?UTF-8?B?S296w6Fr?= (4/45) Jun 29 2015 On Mon, 29 Jun 2015 05:04:36 -0700
- Jack Applegame (1/1) Aug 04 2015 fix - https://github.com/D-Programming-Language/phobos/pull/3524
I don't see any reason why it should not compile. import std.array; import std.range; import std.algorithm; class Foo { } void main() { auto result = iota(3).map!(i => new immutable Foo).array(); } /usr/include/dmd/phobos/std/conv.d(4028): Error: cannot implicitly convert expression (arg) of type immutable(Foo) to test.Foo /usr/include/dmd/phobos/std/conv.d(3931): Error: template instance std.conv.emplaceImpl!(immutable(Foo)).emplaceImpl!(immutable(Foo)) error instantiating /usr/include/dmd/phobos/std/array.d(115): instantiated from here: emplaceRef!(immutable(Foo), Foo, immutable(Foo)) test.d(9): instantiated from here: array!(MapResult!(__lambda1, Result))
Jun 28 2015
I'd say bug, I think the array function is trying an optimization it shouldn't be trying for immutable classes.
Jun 28 2015
https://issues.dlang.org/show_bug.cgi?id=14751
Jun 30 2015
On Sunday, June 28, 2015 11:37:59 Jack Applegame via Digitalmars-d-learn wrote:I don't see any reason why it should not compile. import std.array; import std.range; import std.algorithm; class Foo { } void main() { auto result = iota(3).map!(i => new immutable Foo).array(); } /usr/include/dmd/phobos/std/conv.d(4028): Error: cannot implicitly convert expression (arg) of type immutable(Foo) to test.Foo /usr/include/dmd/phobos/std/conv.d(3931): Error: template instance std.conv.emplaceImpl!(immutable(Foo)).emplaceImpl!(immutable(Foo)) error instantiating /usr/include/dmd/phobos/std/array.d(115): instantiated from here: emplaceRef!(immutable(Foo), Foo, immutable(Foo)) test.d(9): instantiated from here: array!(MapResult!(__lambda1, Result))You haven't declared an immutable constructor, so you can't construct an immutable Foo. If the default constructor were pure, then it could be used to construct immutable objects even if it weren't immutable, but the default constructor is neither pure nor immutable, and purity isn't inferred for normal functions. It might make sense as a feature request to request that a class' default constructor be pure (assuming that its base class constructor is pure), since theoretically, it should be able to be pure, but that would be a change in the language. What you're seeing is not a bug. It's how the current design works. - Jonathan M Davis
Jun 29 2015
On Monday, 29 June 2015 at 12:04:46 UTC, Jonathan M Davis wrote:You haven't declared an immutable constructor, so you can't construct an immutable Foo.That's not what's happening. Constructing an immutable Foo works just fine.
Jun 29 2015
On Monday, 29 June 2015 at 14:28:06 UTC, anonymous wrote:On Monday, 29 June 2015 at 12:04:46 UTC, Jonathan M Davis wrote:Then I stand corrected. - Jonathan M DavisYou haven't declared an immutable constructor, so you can't construct an immutable Foo.That's not what's happening. Constructing an immutable Foo works just fine.
Jun 30 2015
On Mon, 29 Jun 2015 05:04:36 -0700 Jonathan M Davis via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:On Sunday, June 28, 2015 11:37:59 Jack Applegame via Digitalmars-d-learn wrote:No it is a bug in std.conv.emplaceRef or more probably in std.array.I don't see any reason why it should not compile. import std.array; import std.range; import std.algorithm; class Foo { } void main() { auto result = iota(3).map!(i => new immutable Foo).array(); } /usr/include/dmd/phobos/std/conv.d(4028): Error: cannot implicitly convert expression (arg) of type immutable(Foo) to test.Foo /usr/include/dmd/phobos/std/conv.d(3931): Error: template instance std.conv.emplaceImpl!(immutable(Foo)).emplaceImpl!(immutable(Foo)) error instantiating /usr/include/dmd/phobos/std/array.d(115): instantiated from here: emplaceRef!(immutable(Foo), Foo, immutable(Foo)) test.d(9): instantiated from here: array!(MapResult!(__lambda1, Result))You haven't declared an immutable constructor, so you can't construct an immutable Foo. If the default constructor were pure, then it could be used to construct immutable objects even if it weren't immutable, but the default constructor is neither pure nor immutable, and purity isn't inferred for normal functions. It might make sense as a feature request to request that a class' default constructor be pure (assuming that its base class constructor is pure), since theoretically, it should be able to be pure, but that would be a change in the language. What you're seeing is not a bug. It's how the current design works. - Jonathan M Davis
Jun 29 2015
fix - https://github.com/D-Programming-Language/phobos/pull/3524
Aug 04 2015