...
Run Format

Source file src/runtime/race/testdata/issue12664_test.go

Documentation: runtime/race/testdata

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package race_test
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  )
    11  
    12  var issue12664 = "hi"
    13  
    14  func TestRaceIssue12664(t *testing.T) {
    15  	c := make(chan struct{})
    16  	go func() {
    17  		issue12664 = "bye"
    18  		close(c)
    19  	}()
    20  	fmt.Println(issue12664)
    21  	<-c
    22  }
    23  
    24  type MyI interface {
    25  	foo()
    26  }
    27  
    28  type MyT int
    29  
    30  func (MyT) foo() {
    31  }
    32  
    33  var issue12664_2 MyT = 0
    34  
    35  func TestRaceIssue12664_2(t *testing.T) {
    36  	c := make(chan struct{})
    37  	go func() {
    38  		issue12664_2 = 1
    39  		close(c)
    40  	}()
    41  	func(x MyI) {
    42  		// Never true, but prevents inlining.
    43  		if x.(MyT) == -1 {
    44  			close(c)
    45  		}
    46  	}(issue12664_2)
    47  	<-c
    48  }
    49  
    50  var issue12664_3 MyT = 0
    51  
    52  func TestRaceIssue12664_3(t *testing.T) {
    53  	c := make(chan struct{})
    54  	go func() {
    55  		issue12664_3 = 1
    56  		close(c)
    57  	}()
    58  	var r MyT
    59  	var i interface{} = r
    60  	issue12664_3 = i.(MyT)
    61  	<-c
    62  }
    63  
    64  var issue12664_4 MyT = 0
    65  
    66  func TestRaceIssue12664_4(t *testing.T) {
    67  	c := make(chan struct{})
    68  	go func() {
    69  		issue12664_4 = 1
    70  		close(c)
    71  	}()
    72  	var r MyT
    73  	var i MyI = r
    74  	issue12664_4 = i.(MyT)
    75  	<-c
    76  }
    77  

View as plain text