blob: f69f23b5913366f8f1638282351cb641656a99a7 [file] [log] [blame]
Russ Cox2b1c9b42012-02-16 23:49:30 -05001// run
Russ Cox6e8524b2009-08-30 18:47:48 -07002
3// Copyright 2009 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
9type S struct {
Rob Pike325cf8e2010-03-24 16:46:53 -070010 a []int
Russ Cox6e8524b2009-08-30 18:47:48 -070011}
Rob Pike325cf8e2010-03-24 16:46:53 -070012
Russ Cox6e8524b2009-08-30 18:47:48 -070013var s = &S{make([]int, 10)}
14
15func main() {
Rob Pike325cf8e2010-03-24 16:46:53 -070016 s.a[f()] = 1 // 6g used to call f twice here
Russ Cox6e8524b2009-08-30 18:47:48 -070017}
18
19var n int
Rob Pike325cf8e2010-03-24 16:46:53 -070020
21func f() int {
Russ Cox6e8524b2009-08-30 18:47:48 -070022 if n++; n > 1 {
Rob Pike325cf8e2010-03-24 16:46:53 -070023 println("f twice")
24 panic("fail")
Russ Cox6e8524b2009-08-30 18:47:48 -070025 }
26 return 0
27}