From 2546155a816759168ca046ad8da001e93802b86f Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sun, 8 Nov 2009 23:22:06 -0800 Subject: bug212, bug213. R=ken http://go/go-review/1026032 --- src/cmd/gc/print.c | 7 +++++++ src/cmd/gc/subr.c | 19 ++++++++++++------- src/cmd/gc/swt.c | 10 +++++++--- src/pkg/debug/dwarf/open.go | 2 +- test/bugs/bug212.go | 12 ------------ test/bugs/bug213.go | 16 ---------------- test/fixedbugs/bug212.go | 12 ++++++++++++ test/fixedbugs/bug213.go | 16 ++++++++++++++++ test/golden.out | 6 ------ 9 files changed, 55 insertions(+), 45 deletions(-) delete mode 100644 test/bugs/bug212.go delete mode 100644 test/bugs/bug213.go create mode 100644 test/fixedbugs/bug212.go create mode 100644 test/fixedbugs/bug213.go diff --git a/src/cmd/gc/print.c b/src/cmd/gc/print.c index 14dd57fa1..ce4f721ae 100644 --- a/src/cmd/gc/print.c +++ b/src/cmd/gc/print.c @@ -328,6 +328,13 @@ exprfmt(Fmt *f, Node *n, int prec) } fmtprint(f, ")"); break; + + case OMAKEMAP: + fmtprint(f, "make(%#T)", n->type); + break; + + case OMAPLIT: + fmtprint(f, "map literal"); } if(prec > nprec) diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index ccb2b7653..35a3a2f95 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -1654,7 +1654,7 @@ iscomposite(Type *t) int eqtype1(Type *t1, Type *t2, int d, int names) { - if(d >= 10) + if(d >= 20) return 1; if(t1 == t2) return 1; @@ -1720,14 +1720,19 @@ eqtype1(Type *t1, Type *t2, int d, int names) return 1; case TARRAY: - if(t1->bound == t2->bound) - break; - return 0; + if(t1->bound != t2->bound) + return 0; + break; case TCHAN: - if(t1->chan == t2->chan) - break; - return 0; + if(t1->chan != t2->chan) + return 0; + break; + + case TMAP: + if(!eqtype1(t1->down, t2->down, d+1, names)) + return 0; + break; } return eqtype1(t1->type, t2->type, d+1, names); } diff --git a/src/cmd/gc/swt.c b/src/cmd/gc/swt.c index 1cd4cfaa8..952c47246 100644 --- a/src/cmd/gc/swt.c +++ b/src/cmd/gc/swt.c @@ -313,9 +313,13 @@ casebody(Node *sw, Node *typeswvar) // botch - shouldnt fall thru declaration last = stat->end->n; - if(last->op == OXFALL) + if(last->op == OXFALL) { + if(typeswvar) { + setlineno(last); + yyerror("cannot fallthrough in type switch"); + } last->op = OFALL; - else + } else stat = list(stat, br); } @@ -771,7 +775,7 @@ walkswitch(Node *sw) sw->ntest = nodbool(1); typecheck(&sw->ntest, Erv); } - + if(sw->ntest->op == OTYPESW) { typeswitch(sw); //dump("sw", sw); diff --git a/src/pkg/debug/dwarf/open.go b/src/pkg/debug/dwarf/open.go index 6fc34fed3..1b50beaa4 100644 --- a/src/pkg/debug/dwarf/open.go +++ b/src/pkg/debug/dwarf/open.go @@ -51,7 +51,7 @@ func New(abbrev, aranges, frame, info, line, pubnames, ranges, str []byte) (*Dat ranges: ranges, str: str, abbrevCache: make(map[uint32]abbrevTable), - typeCache: make(map[uint32]Type), + typeCache: make(map[Offset]Type), }; // Sniff .debug_info to figure out byte order. diff --git a/test/bugs/bug212.go b/test/bugs/bug212.go deleted file mode 100644 index 079bb5791..000000000 --- a/test/bugs/bug212.go +++ /dev/null @@ -1,12 +0,0 @@ -// errchk $G $D/$F.go - -// 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 -type I int -type S struct { f map[I]int } -var v1 = S{ make(map[int]int) } // ERROR "cannot|illegal|incompatible|wrong" -var v2 map[I]int = map[int]int{} // ERROR "cannot|illegal|incompatible|wrong" -var v3 = S{ make(map[uint]int) } // ERROR "cannot|illegal|incompatible|wrong" diff --git a/test/bugs/bug213.go b/test/bugs/bug213.go deleted file mode 100644 index 07d9f9029..000000000 --- a/test/bugs/bug213.go +++ /dev/null @@ -1,16 +0,0 @@ -// errchk $G $D/$F.go - -// 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 main() { - var v interface{} = 0; - switch x := v.(type) { - case int: - fallthrough; // ERROR "fallthrough" - default: - panic("fell through"); - } -} diff --git a/test/fixedbugs/bug212.go b/test/fixedbugs/bug212.go new file mode 100644 index 000000000..51df9b8ae --- /dev/null +++ b/test/fixedbugs/bug212.go @@ -0,0 +1,12 @@ +// errchk $G $D/$F.go + +// 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 +type I int +type S struct { f map[I]int } +var v1 = S{ make(map[int]int) } // ERROR "cannot|illegal|incompatible|wrong" +var v2 map[I]int = map[int]int{} // ERROR "cannot|illegal|incompatible|wrong" +var v3 = S{ make(map[uint]int) } // ERROR "cannot|illegal|incompatible|wrong" diff --git a/test/fixedbugs/bug213.go b/test/fixedbugs/bug213.go new file mode 100644 index 000000000..07d9f9029 --- /dev/null +++ b/test/fixedbugs/bug213.go @@ -0,0 +1,16 @@ +// errchk $G $D/$F.go + +// 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 main() { + var v interface{} = 0; + switch x := v.(type) { + case int: + fallthrough; // ERROR "fallthrough" + default: + panic("fell through"); + } +} diff --git a/test/golden.out b/test/golden.out index d23369b6e..a7dcd090a 100644 --- a/test/golden.out +++ b/test/golden.out @@ -201,9 +201,3 @@ throw: interface conversion panic PC=xxx == bugs/ - -=========== bugs/bug212.go -BUG: errchk: command succeeded unexpectedly - -=========== bugs/bug213.go -BUG: errchk: command succeeded unexpectedly -- cgit v1.2.3