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

     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  func f() {
    15  	var x *string
    16  	
    17  	for _, i := range *x {  // THIS IS LINE 17
    18  		println(i)
    19  	}
    20  }
    21  
    22  func g() {
    23  }
    24  
    25  func main() {
    26  	defer func() {
    27  		for i := 0;; i++ {
    28  			pc, file, line, ok := runtime.Caller(i)
    29  			if !ok {
    30  				print("BUG: bug348: cannot find caller\n")
    31  				return
    32  			}
    33  			if !strings.Contains(file, "bug348.go") || runtime.FuncForPC(pc).Name() != "main.f" {
    34  				// walk past runtime frames
    35  				continue
    36  			}
    37  			if line != 17 {
    38  				print("BUG: bug348: panic at ", file, ":", line, " in ", runtime.FuncForPC(pc).Name(), "\n")
    39  				return
    40  			}
    41  			recover()
    42  			return
    43  		}
    44  	}()
    45  	f()
    46  }