diff --git a/src/cmd/cover/cover.go b/src/cmd/cover/cover.go index 1748606c5e7..e04c8834bd8 100644 --- a/src/cmd/cover/cover.go +++ b/src/cmd/cover/cover.go @@ -386,6 +386,9 @@ func (f *File) addCounters(pos, insertPos, blockEnd token.Pos, list []ast.Stmt, f.edit.Insert(f.offset(insertPos), f.newCounter(insertPos, blockEnd, 0)+";") return } + // Make a copy of the list, as we may mutate it and should leave the + // existing list intact. + list = append([]ast.Stmt(nil), list...) // We have a block (statement list), but it may have several basic blocks due to the // appearance of statements that affect the flow of control. for { diff --git a/src/cmd/cover/testdata/test.go b/src/cmd/cover/testdata/test.go index 0b03ef91ab5..b794962205d 100644 --- a/src/cmd/cover/testdata/test.go +++ b/src/cmd/cover/testdata/test.go @@ -132,6 +132,10 @@ func testBlockRun() { func testSwitch() { for i := 0; i < 5; func() { i++; check(LINE, 5) }() { + goto label2 + label1: + goto label1 + label2: switch i { case 0: check(LINE, 1)