[Issue 7493] Initialization of void[][N]
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Mar 21 15:13:09 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7493
--- Comment #6 from timon.gehr at gmx.ch 2012-03-21 15:13:28 PDT ---
(In reply to comment #5)
> (In reply to comment #4)
> > DMD is inconsistent here. It is not clear what the behavior should be.
> >
> > void main(){
> > string[] s1,s2;
> > s1=s1~[];
> > s2~=[];
> > writeln(s1," ",s2); // [""] []
> > }
> >
> > I think most reasonable would be to check the array type for implicit
> > conversions first and to consider the element type for implicit conversions
> > only after the conversion to the array has failed.
>
> I don't think that's the same issue,
It is very closely related. It is the same kind of issue.
> and I don't like that approach for
> initialization of void[]. It would mean that
> void[][3] a = [ str, str, str];
> void[][2] b = [ str, str, str];
>
> means
>
> a[0] == str
> b[0] == [str, str, str]
I see. That is a problem.
>
> I think this particular issue is specific to void[], since it is a recursive
> type (an array literal of void[] elements is also of type void[]).
>
The particular issue is specific to void[]. Possible resolutions could affect
the entire language. (for example, this issue came up because of an only
roughly related fix)
> The most intuitive approaches I would think are:
> * void[][ANYTHING] = [ WHATEVER ] is _always_ a whole-array assignment;
I think that is the best behavior. Block assignment can still work with []= .
> OR
> it is _always_ an error.
Then how do you initialize it? Element-wise?
> The current compiler behaviour, where it is always a block assignment, is less
> intuitive but I think defensible.
> But allowing it to be one or the other, depending on whether the implicit
> conversion succeeds, is horribly unpredictable.
>
> As far as I can tell, there is no mention at all of block assignment in the
> spec! Did I miss it?
>
The conversion rules for arrays and array literals are almost completely
unspecified afaik.
Another ambiguous case:
import std.stdio;
class A{
A[] as;
this(){as = [new A(0),new A(0)];}
this(int){}
alias as this;
}
void main(){
A a = new A;
A[] as1;
A[] as2;
as1=as1~a;
as2~=a;
writeln(as1.length," ",as2.length); // 2 2
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list