Source file test/fixedbugs/issue8139.go

     1  // run
     2  
     3  // Copyright 2014 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 8139. The x.(T) assertions used to write 1 (unexpected)
     8  // return byte for the 0-byte return value T.
     9  
    10  package main
    11  
    12  import "fmt"
    13  
    14  type T struct{}
    15  
    16  func (T) M() {}
    17  
    18  type M interface {
    19  	M()
    20  }
    21  
    22  var e interface{} = T{}
    23  var i M = T{}
    24  var b bool
    25  
    26  func f1() int {
    27  	if b {
    28  		return f1() // convince inliner not to inline
    29  	}
    30  	z := 0x11223344
    31  	_ = e.(T)
    32  	return z
    33  }
    34  
    35  func f2() int {
    36  	if b {
    37  		return f1() // convince inliner not to inline
    38  	}
    39  	z := 0x11223344
    40  	_ = i.(T)
    41  	return z
    42  }
    43  
    44  func main() {
    45  	x := f1()
    46  	y := f2()
    47  	if x != 0x11223344 || y != 0x11223344 {
    48  		fmt.Printf("BUG: x=%#x y=%#x, want 0x11223344 for both\n", x, y)
    49  	}
    50  }
    51  

View as plain text