Home | History | Annotate | Download | only in fixedbugs
      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 
     10 package main
     11 
     12 type S struct {
     13 	i1, i2, i3 int
     14 }
     15 
     16 var G int
     17 
     18 func v(i int) int {
     19 	if i != G {
     20 		panic(i)
     21 	}
     22 	G = i + 1
     23 	return G
     24 }
     25 
     26 func F() S {
     27 	return S{
     28 		i1: v(0),
     29 		i3: v(1),
     30 		i2: v(2),
     31 	}
     32 }
     33 
     34 func main() {
     35 	s := F()
     36 	if s != (S{1, 3, 2}) {
     37 		panic(s)
     38 	}
     39 }
     40