Source file test/fixedbugs/issue7863.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  package main
     8  
     9  import (
    10  	"fmt"
    11  )
    12  
    13  type Foo int64
    14  
    15  func (f *Foo) F() int64 {
    16  	return int64(*f)
    17  }
    18  
    19  type Bar int64
    20  
    21  func (b Bar) F() int64 {
    22  	return int64(b)
    23  }
    24  
    25  type Baz int32
    26  
    27  func (b Baz) F() int64 {
    28  	return int64(b)
    29  }
    30  
    31  func main() {
    32  	foo := Foo(123)
    33  	f := foo.F
    34  	if foo.F() != f() {
    35  		bug()
    36  		fmt.Println("foo.F", foo.F(), f())
    37  	}
    38  	bar := Bar(123)
    39  	f = bar.F
    40  	if bar.F() != f() {
    41  		bug()
    42  		fmt.Println("bar.F", bar.F(), f()) // duh!
    43  	}
    44  
    45  	baz := Baz(123)
    46  	f = baz.F
    47  	if baz.F() != f() {
    48  		bug()
    49  		fmt.Println("baz.F", baz.F(), f())
    50  	}
    51  }
    52  
    53  var bugged bool
    54  
    55  func bug() {
    56  	if !bugged {
    57  		bugged = true
    58  		fmt.Println("BUG")
    59  	}
    60  }
    61  

View as plain text