www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1887] New: compiler freeze on array of dyn. arrays with empty first initializer

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

           Summary: compiler freeze on array of dyn. arrays with empty first
                    initializer
           Product: D
           Version: 2.011
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: adolf.mathias googlemail.com


The program at the end of this post causes dmd 2.011 to emit the messages

adjac.d(7): Error: cannot implicitly convert expression ([0]) of type int[1u]
to void[]
adjac.d(7): Error: cannot implicitly convert expression ([0,1]) of type int[2u]
to void[]
adjac.d(7): Error: cannot implicitly convert expression ([0,2]) of type int[2u]
to void[]
adjac.d(7): Error: cannot implicitly convert expression ([1,2]) of type int[2u]
to void[]
adjac.d(7): Error: cannot implicitly convert expression ([1,2,3,4]) of type
int[4u] to void[]
adjac.d(7): Error: cannot implicitly convert expression ([2,3,5]) of type
int[3u] to void[]
adjac.d(7): Error: cannot implicitly convert expression ([4,5,6]) of type
int[3u] to void[]

and then to freeze. After replacing the invariant declaration, dmd 1.027 gives
me the same messages but terminates. 
I unfortunately have to set the first element in the initializer of neighbors
to something else than [], and then after initialization, use the out-commented
length modification. Don't know whether that behavior is according to the
specs...


// http://www.ocf.berkeley.edu/~wwu/riddles/medium.shtml adjacency grid

import std.stdio;

void main() {
  invariant int maxi = 8;
  int[][maxi] neighbors = [ [ ], [ 0 ], [ 0, 1], [ 0, 2], [1, 2], [1, 2, 3, 4],
[ 2, 3, 5], [ 4, 5, 6 ] ];
  int[maxi] grid;

  // neighbors[0].length = 0;

  void place(int k, uint mask)
  { if(k<maxi) {
      for(uint m = 1, d = 1; d <= maxi; d++, m<<=1)
        if(!(mask & m)) {
          bool ok = true;
          int dif;
          foreach(nb; neighbors[k]) 
            if((dif=grid[nb]-d)==1 || dif==-1) {
              ok = false; break;
            }
          if(ok) {
            grid[k] = d;
            place(k+1, mask | m);
          }
        }
    } else {
      writef("  %d\n%d %d %d\n%d %d %d\n  %d\n\n",
             grid[0], grid[1], grid[2], grid[3], grid[4], grid[5], grid[6],
grid[7]);
    }
  }
  place(0, 0);
}


-- 
Mar 02 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1887






I'll fix the freezing issue, but the current way the type of the array is
deduced is by looking at the type of the first element. With [] being the first
element, its type is void[], which doesn't match the rest of the elements. Try
casting the [] to int[].


-- 
Mar 02 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1887


bugzilla digitalmars.com changed:

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





Fixed dmd 2.012


-- 
Mar 06 2008