www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7493] New: Initialization of void[][N]

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7493

           Summary: Initialization of void[][N]
           Product: D
           Version: D1
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: thecybershadow gmail.com



06:26:16 PST ---
void main()
{
    string str = "Hi";
    void[][1] arr = [str];
    assert(arr[0].length == str.length);
}

Notably, changing the second line to
    void[][1] arr = str;
will make the assert pass, so I guess DMD is now trying some new way of array
assignment which succeeds due to the implicit void[] conversion.

Worked in 1.070, doesn't work in 1.071 or the latest D1 beta.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 13 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7493


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com



00:48:11 PST ---
Since it's not a regression in 1.072, I'm going to defer this until the next
cycle.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7493


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Version|D1                          |D1 & D2



Also applies to D2. The problem is that there are two possible interpretations:

void[] x = [str];
typeof(x)[1] = x;

void[] y = str;
typeof(y)[1] = [ y ];

I think this should be an error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7493


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch



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. This would make
appending/concatenating with an empty array literal a no-op for all array types
and it would restore the behavior the OP expects.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7493





 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, 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 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 most intuitive approaches I would think are: * void[][ANYTHING] = [ WHATEVER ] is _always_ a whole-array assignment; OR it is _always_ an error. 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?
 This would make
 appending/concatenating with an empty array literal a no-op for all array types
 and it would restore the behavior the OP expects.
-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7493






 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: -------
Mar 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7493




https://github.com/D-Programming-Language/dmd/pull/866

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 04 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7493




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/43796a5a0e5b6e86753cb7624fb502e6b36dce83
Fix issue 7493  Initialization of void[][N]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 04 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7493


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 05 2012