1// run
2
3// Copyright 2012 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
7// Test that initializing struct fields out of order still runs
8// functions in the right order.  This failed with gccgo.
9
10package main
11
12type S struct {
13	i1, i2, i3 int
14}
15
16var G int
17
18func v(i int) int {
19	if i != G {
20		panic(i)
21	}
22	G = i + 1
23	return G
24}
25
26func F() S {
27	return S{
28		i1: v(0),
29		i3: v(1),
30		i2: v(2),
31	}
32}
33
34func main() {
35	s := F()
36	if s != (S{1, 3, 2}) {
37		panic(s)
38	}
39}
40