On Mon, 24 Jan 2011 18:39:39 -0500, Simen kjaeraas <simen.kja...@gmail.com> wrote:

Ellery Newcomer <ellery-newco...@utulsa.edu> wrote:

in the following:

void main(){
   char[] x;
   string s;
   string y;

   y = s ~ x;
}

tok.d(5): Error: cannot implicitly convert expression (cast(const(char)[])s ~ x) of type char[] to string

why should typeof(s ~ x) == char[] ?

http://d.puremagic.com/issues/show_bug.cgi?id=1654

I have since felt that the bug report I filed may be more trouble than it's worth. It makes perfect sense for strings or other arrays of non references, but it doesn't make sense for more complex types (as can be seen by the later discussions on that report).

From the original issue, s ~ x is concatenating two different types, what should the result type be? Either choice is going to cause problems. The only "correct" choice is a polysemous type that can implicitly cast into either type on the assumption that the data is unique. This is pretty much what I wanted from the bug report, but I was very green back then, didn't know the right way to say it.

If the enhancement can be implemented, I think it would help, but it would be nice to solve this problem in the general sense (not just for arrays). There was a suggestion earlier that a strong-pure function could return an implicitly castable type, but concatenating a mutable and immutable string would not be such a function. We would need some other way to mark a function.

-Steve

Reply via email to