Source file test/fixedbugs/issue5607.go

     1  // run
     2  
     3  // Copyright 2013 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 5607: generation of init() function incorrectly
     8  // uses initializers of blank variables inside closures.
     9  
    10  package main
    11  
    12  var Test = func() {
    13  	var mymap = map[string]string{"a": "b"}
    14  
    15  	var innerTest = func() {
    16  		// Used to crash trying to compile this line as
    17  		// part of init() (funcdepth mismatch).
    18  		var _, x = mymap["a"]
    19  		println(x)
    20  	}
    21  	innerTest()
    22  }
    23  
    24  var Test2 = func() {
    25  	// The following initializer should not be part of init()
    26  	// The compiler used to generate a call to Panic() in init().
    27  	var _, x = Panic()
    28  	_ = x
    29  }
    30  
    31  func Panic() (int, int) {
    32  	panic("omg")
    33  	return 1, 2
    34  }
    35  
    36  func main() {}
    37  

View as plain text