1// run 2 3// Copyright 2011 The Go Authors. All rights reserved. 4// Use of this source code is governed by a BSD-style 5// license that can be found in the LICENSE file. 6 7package main 8 9import "fmt" 10 11var s string 12 13func accum(args ...interface{}) { 14 s += fmt.Sprintln(args...) 15} 16 17func f(){ 18 v := 0.0 19 for i := 0; i < 3; i++ { 20 v += 0.1 21 defer accum(v) 22 } 23} 24 25func main() { 26 f() 27 if s != "0.30000000000000004\n0.2\n0.1\n" { 28 println("BUG: defer") 29 print(s) 30 } 31} 32