Source file test/fixedbugs/bug446.go

     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  // Issue 3824.
     8  // Method calls are ignored when deciding initialization
     9  // order.
    10  
    11  package main
    12  
    13  type T int
    14  
    15  func (r T) Method1() int { return a }
    16  func (r T) Method2() int { return b }
    17  
    18  // dummy1 and dummy2 must be initialized after a and b.
    19  var dummy1 = T(0).Method1()
    20  var dummy2 = T.Method2(0)
    21  
    22  // Use a function call to force generating code.
    23  var a = identity(1)
    24  var b = identity(2)
    25  
    26  func identity(a int) int { return a }
    27  
    28  func main() {
    29  	if dummy1 != 1 {
    30  		panic("dummy1 != 1")
    31  	}
    32  	if dummy2 != 2 {
    33  		panic("dummy2 != 2")
    34  	}
    35  }
    36  
    37  

View as plain text