From a1391c2d136f0715b4deab8d295f155ba686d368 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 2 Sep 2009 23:26:13 -0700 Subject: [PATCH] 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 --- src/cmd/gc/align.c | 5 ++++- src/cmd/gc/subr.c | 2 ++ src/cmd/gc/typecheck.c | 3 ++- test/fixedbugs/bug202.go | 16 ++++++++++++++++ test/fixedbugs/bug203.go | 20 ++++++++++++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 test/fixedbugs/bug202.go create mode 100644 test/fixedbugs/bug203.go diff --git a/src/cmd/gc/align.c b/src/cmd/gc/align.c index 9a013ca6e2..c7c1dfd622 100644 --- a/src/cmd/gc/align.c +++ b/src/cmd/gc/align.c @@ -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: diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index 9f160d456d..8b75560158 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -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: diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index 9f0beb559f..67c6777cf9 100644 --- a/src/cmd/gc/typecheck.c +++ b/src/cmd/gc/typecheck.c @@ -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: diff --git a/test/fixedbugs/bug202.go b/test/fixedbugs/bug202.go new file mode 100644 index 0000000000..7e5cc7a3fd --- /dev/null +++ b/test/fixedbugs/bug202.go @@ -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(); +} + + + \ No newline at end of file diff --git a/test/fixedbugs/bug203.go b/test/fixedbugs/bug203.go new file mode 100644 index 0000000000..5b04b2efbc --- /dev/null +++ b/test/fixedbugs/bug203.go @@ -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() +{ +} -- 2.48.1