github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/test/fixedbugs/bug177.go (about)

     1  // run
     2  
     3  // Copyright 2009 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  package main
     8  
     9  import "reflect"
    10  
    11  type S1 struct{ i int }
    12  type S2 struct{ S1 }
    13  
    14  func main() {
    15  	typ := reflect.TypeOf(S2{})
    16  	f := typ.Field(0)
    17  	if f.Name != "S1" || f.Anonymous != true {
    18  		println("BUG: ", f.Name, f.Anonymous)
    19  		return
    20  	}
    21  	f, ok := typ.FieldByName("S1")
    22  	if !ok {
    23  		println("BUG: missing S1")
    24  		return
    25  	}
    26  	if !f.Anonymous {
    27  		println("BUG: S1 is not anonymous")
    28  		return
    29  	}
    30  }