Source file test/fixedbugs/bug347.go

     1  // run
     2  
     3  // Copyright 2011 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  	"runtime"
    11  	"strings"
    12  )
    13  
    14  var t *struct {
    15  	c chan int
    16  }
    17  
    18  var c chan int
    19  
    20  func f() {
    21  	select {
    22  	case <-t.c:  // THIS IS LINE 22
    23  		break
    24  	case <-c:
    25  		break
    26  	}
    27  }
    28  
    29  func main() {
    30  	defer func() {
    31  		recover()
    32  		for i := 0;; i++ {
    33  			pc, file, line, ok := runtime.Caller(i)
    34  			if !ok {
    35  				print("BUG: bug347: cannot find caller\n")
    36  				return
    37  			}
    38  			if !strings.Contains(file, "bug347.go") || runtime.FuncForPC(pc).Name() != "main.f" {
    39  				// walk past runtime frames
    40  				continue
    41  			}
    42  			if line != 22 {
    43  				print("BUG: bug347: panic at ", file, ":", line, " in ", runtime.FuncForPC(pc).Name(), "\n")
    44  			}
    45  			return
    46  		}
    47  	}()
    48  	f()
    49  }
    50  

View as plain text