1
0
mirror of https://github.com/golang/go synced 2024-11-11 23:20:24 -07:00

fix one bug involving [...] constructors.

added iant's bug202 (in main code)
and ken's bug203 (in init function).
bug187 remains at large.

R=ken
OCL=34293
CL=34293
This commit is contained in:
Russ Cox 2009-09-02 23:26:13 -07:00
parent 5db1d3867f
commit a1391c2d13
5 changed files with 44 additions and 2 deletions

View File

@ -199,9 +199,12 @@ dowidth(Type *t)
if(t->type == T)
break;
dowidth(t->type);
w = sizeof_Array;
if(t->bound >= 0)
w = t->bound * t->type->width;
else if(t->bound == -1)
w = sizeof_Array;
else
fatal("dowidth %T", t); // probably [...]T
break;
case TSTRUCT:

View File

@ -1061,6 +1061,8 @@ Tpretty(Fmt *fp, Type *t)
case TARRAY:
if(t->bound >= 0)
return fmtprint(fp, "[%d]%T", (int)t->bound, t->type);
if(t->bound == -100)
return fmtprint(fp, "[...]%T", t->type);
return fmtprint(fp, "[]%T", t->type);
case TINTER:

View File

@ -159,7 +159,8 @@ reswitch:
n->type = t;
n->left = N;
n->right = N;
checkwidth(t);
if(t->bound != -100)
checkwidth(t);
break;
case OTMAP:

16
test/fixedbugs/bug202.go Normal file
View File

@ -0,0 +1,16 @@
// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG should run
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
func f() {
v := [...]string{"a", "b"};
}
func main() {
f();
}

20
test/fixedbugs/bug203.go Normal file
View File

@ -0,0 +1,20 @@
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
var s [8]string
func
init()
{
s = [...]string{ "now", "is", "the", "time", "to", "fix", "this", "bug"}
}
func
main()
{
}