On 02/04/12 23:44, Timon Gehr wrote: > On 02/04/2012 11:23 PM, Artur Skawina wrote: >> On 02/04/12 22:20, Timon Gehr wrote: >>> On 02/04/2012 06:55 PM, Artur Skawina wrote: >>>> Semi-related quiz: >>>> >>>> immutable(char)[] a = "a"; >>>> const (char)[] b = "b"; >>>> >>>> auto aa = a ~ a; >>>> auto bb = b ~ b; >>>> auto ab = a ~ b; >>>> >>>> writeln("aa: ", typeid(aa), " bb: ", typeid(bb), " ab: ", >>>> typeid(ab)); >>>> >>>> And the question is: How many people, who have not already been bitten by >>>> this, >>>> will give the correct answer to: "What will this program print?"? >>>> >>> >>> I think this is covered in this issue: >>> >>> http://d.puremagic.com/issues/show_bug.cgi?id=7311 >>> >>> But feel free to open a more specific enhancement/bug report. >> >> Apparently, there's already a bug open for everything. >> I'm not sure if it's a good or bad thing. :) >> >> I don't think there's one correct answer here - you're right that unique >> const >> does not really make sense. But is mutable (non-const) really better than >> immutable? It depends, sometimes you will want one, sometimes the other. >> I first ran into this while doing a custom string class - there it was the >> cause >> of the one and only cast - (string ~ const(char)[]) can obviously still be a >> string, but the compiler won't accept it without a cast. >> I'm not sure how often you'll want the result of concatenation to be mutable, >> compared to immutable. Anyway, the result really is "unique", not mutable, >> const >> or immutable, at least until it is converted to one of those, hence the >> solution >> described below. >> > > > Well, string = string ~ const(char)[] and char[] = string ~ const(char)[] > should work, regardless of the type of immutable[] ~ const[]. The compiler > can track the uniqueness of the data at the expression level without actually > introducing a type modifier. There is precedent: Array literals are > covariant, because it is safe. Do you want to open the enhancement or should > I do it? (I really thought I already had an issue open for this...)
Please do; i've been avoiding filing dmd bugs, because i'm only using gdc, not dmd. (so i can't even easily check if the issue still exists in the current tree) artur