modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue5607.go (about)

     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() {}