Re: Implicit cast to immutable

2011-10-27 Thread Christophe
"Steven Schveighoffer" , dans le message (digitalmars.D.learn:30255), a écrit : > On Fri, 21 Oct 2011 11:20:01 -0400, Christophe > wrote: > >> "Daniel Murphy" , dans le message (digitalmars.D.learn:30139), a écrit : >>> "bearophile" wrote in message >>> news:j7jepi$prp$1...@digitalmars.com...

Re: Implicit cast to immutable

2011-10-24 Thread Steven Schveighoffer
On Fri, 21 Oct 2011 11:20:01 -0400, Christophe wrote: "Daniel Murphy" , dans le message (digitalmars.D.learn:30139), a écrit : "bearophile" wrote in message news:j7jepi$prp$1...@digitalmars.com... Daniel Murphy: 2) immutable(int[]) fun() { return new int[]; } // conversion happens here

Re: Implicit cast to immutable

2011-10-21 Thread Christophe
"Daniel Murphy" , dans le message (digitalmars.D.learn:30139), a écrit : > "bearophile" wrote in message > news:j7jepi$prp$1...@digitalmars.com... >> Daniel Murphy: >> >>> 2) >>> immutable(int[]) fun() { return new int[]; } // conversion happens here >>> immutable x = fun(); >>> >>> Bearophile's

Re: Implicit cast to immutable

2011-10-19 Thread Steven Schveighoffer
ws:op.v3h06olweav7ka@localhost.localdomain... That sounds like an incorrect restriction. The implicit cast to immutable should depend on whether the function being *called* qualifies, not if the function you are calling *from* qualifies. I think you've misunderstood what I'm saying. The patch I made im

Re: Implicit cast to immutable

2011-10-19 Thread Daniel Murphy
... >>> >>> That sounds like an incorrect restriction. The implicit cast to >>> immutable >>> should depend on whether the function being *called* qualifies, not if >>> the >>> function you are calling *from* qualifies. >>> >> >>

Re: Implicit cast to immutable

2011-10-19 Thread Steven Schveighoffer
On Tue, 18 Oct 2011 02:40:12 -0400, Daniel Murphy wrote: "Steven Schveighoffer" wrote in message news:op.v3h06olweav7ka@localhost.localdomain... That sounds like an incorrect restriction. The implicit cast to immutable should depend on whether the function being *called* qual

Re: Implicit cast to immutable

2011-10-18 Thread Daniel Murphy
"bearophile" wrote in message news:j7jepi$prp$1...@digitalmars.com... > Daniel Murphy: > >> 2) >> immutable(int[]) fun() { return new int[]; } // conversion happens here >> immutable x = fun(); >> >> Bearophile's example is of the second, where it definately matters what >> the >> purity of the

Re: Implicit cast to immutable

2011-10-18 Thread bearophile
Daniel Murphy: > 2) > immutable(int[]) fun() { return new int[]; } // conversion happens here > immutable x = fun(); > > Bearophile's example is of the second, where it definately matters what the > purity of the function is. This is the enhancement request I have written days ago: http://d.pu

Re: Implicit cast to immutable

2011-10-17 Thread Daniel Murphy
"Steven Schveighoffer" wrote in message news:op.v3h06olweav7ka@localhost.localdomain... > > That sounds like an incorrect restriction. The implicit cast to immutable > should depend on whether the function being *called* qualifies, not if the > function you are calling

Re: Implicit cast to immutable

2011-10-17 Thread Steven Schveighoffer
return new int[1]; } void main() { immutable x = foo([1, 2, 3].idup); } That sounds like an incorrect restriction. The implicit cast to immutable should depend on whether the function being *called* qualifies, not if the function you are calling *from* qualifies. Qualifying means the

Re: Implicit cast to immutable

2011-10-15 Thread Daniel Murphy
The implicit conversion to immutable is only possible inside strongly pure functions. When the parameter is 'in int[]' foo cannot be strongly pure, only const pure. As 'in int[2]' is a value type, the second foo can be strongly pure. 'new' expressions will hopefully be able to be converted to

Re: Implicit cast to immutable

2011-10-06 Thread Steven Schveighoffer
On Wed, 05 Oct 2011 19:19:37 -0400, bearophile wrote: Do you know why this program doesn't compile (with DMD 2.056head)? immutable(int[]) foo(in int[] x) pure { return new int[1]; } void main() {} It gives: test.d(2): Error: cannot implicitly convert expression (new int[](1u)) of ty

Re: Implicit cast to immutable

2011-10-06 Thread bearophile
Christophe: > That is very consistent, so I don't think this > should be considered as a bug. There may be an improvement to ask to > make the compiler able to check when the cast to immutable is safe, but > I don't think there is a bug. The compiler already performs such checks, in this case

Re: Implicit cast to immutable

2011-10-06 Thread Christophe
bearophile , dans le message (digitalmars.D.learn:29961), a écrit : > Andrej Mitrovic: > >> Maybe: >> >> immutable(int[]) foo(in int[] x) pure { >>return new immutable(int[1]); >> } >> >> void main() {} > > I'd like to know why the code in my original post doesn't compile. I suspect > it's

Re: Implicit cast to immutable

2011-10-05 Thread bearophile
Andrej Mitrovic: > Maybe: > > immutable(int[]) foo(in int[] x) pure { >return new immutable(int[1]); > } > > void main() {} I'd like to know why the code in my original post doesn't compile. I suspect it's a DMD bug, but I am not sure. > Or does this have something to do with implicit ca

Re: Implicit cast to immutable

2011-10-05 Thread Andrej Mitrovic
Maybe: immutable(int[]) foo(in int[] x) pure { return new immutable(int[1]); } void main() {} Or does this have something to do with implicit casts to immutable for pure functions? I'm only vaguely familiar with pure..

Implicit cast to immutable

2011-10-05 Thread bearophile
Do you know why this program doesn't compile (with DMD 2.056head)? immutable(int[]) foo(in int[] x) pure { return new int[1]; } void main() {} It gives: test.d(2): Error: cannot implicitly convert expression (new int[](1u)) of type int[] to immutable(int[]) This program instead compiles (