Home | History | Annotate | Download | only in fixedbugs
      1 // run
      2 
      3 // Copyright 2016 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 // This checks partially initialized structure literals
      8 // used to create value.method functions have their
      9 // non-initialized fields properly zeroed/nil'd
     10 
     11 package main
     12 
     13 type X struct {
     14 	A, B, C *int
     15 }
     16 
     17 //go:noinline
     18 func (t X) Print() {
     19 	if t.B != nil {
     20 		panic("t.B must be nil")
     21 	}
     22 }
     23 
     24 //go:noinline
     25 func caller(f func()) {
     26 	f()
     27 }
     28 
     29 //go:noinline
     30 func test() {
     31 	var i, j int
     32 	x := X{A: &i, C: &j}
     33 	caller(func() { X{A: &i, C: &j}.Print() })
     34 	caller(X{A: &i, C: &j}.Print)
     35 	caller(x.Print)
     36 }
     37 
     38 func main() {
     39 	test()
     40 }
     41