Bug 1887 – compiler freeze on array of dyn. arrays with empty first initializer

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-03-02T15:44:00Z
Last change time
2015-06-09T01:14:35Z
Assigned to
bugzilla
Creator
adolf.mathias

Comments

Comment #0 by adolf.mathias — 2008-03-02T15:44:54Z
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); }
Comment #1 by bugzilla — 2008-03-02T19:39:41Z
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[].
Comment #2 by adolf.mathias — 2008-03-04T15:21:41Z
> ------- Comment #1 from [email protected] 2008-03-02 19:39 ------- > 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[]. > I've tried int[][maxi] neighbors = [ cast(int[])[], [0], [ 0, 1], [ 0, 2], [1, 2], [1, 2, 3, 4], [ 2, 3, 5], [ 4, 5, 6 ] ]; but I get the same error messages, and the compiler freezes, too. <br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">------- Comment #1 from <a href="mailto:[email protected]">[email protected]</a> &nbsp;2008-03-02 19:39 -------<br> I&#39;ll fix the freezing issue, but the current way the type of the array is<br> deduced is by looking at the type of the first element. With [] being the first<br> element, its type is void[], which doesn&#39;t match the rest of the elements. Try<br> casting the [] to int[].<br> </blockquote></div><br>I&#39;ve tried<br> <br> &nbsp; int[][maxi] neighbors = [ cast(int[])[], [0], [ 0, 1], [ 0, 2], [1, 2], [1, 2, 3, 4], [ 2, 3, 5], [ 4, 5, 6 ] ];<br> <br> but I get the same error messages, and the compiler freezes, too. <br> <br>
Comment #3 by bugzilla — 2008-03-07T00:40:32Z
Fixed dmd 2.012