...
Run Format

Source file test/nilptr2.go

Documentation: test

     1  // run
     2  
     3  // Copyright 2013 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  func main() {
    10  	ok := true
    11  	for _, tt := range tests {
    12  		func() {
    13  			defer func() {
    14  				if err := recover(); err == nil {
    15  					println(tt.name, "did not panic")
    16  					ok = false
    17  				}
    18  			}()
    19  			tt.fn()
    20  		}()
    21  	}
    22  	if !ok {
    23  		println("BUG")
    24  	}
    25  }
    26  
    27  var intp *int
    28  var slicep *[]byte
    29  var a10p *[10]int
    30  var a10Mp *[1<<20]int
    31  var structp *Struct
    32  var bigstructp *BigStruct
    33  var i int
    34  var m *M
    35  var m1 *M1
    36  var m2 *M2
    37  
    38  func use(interface{}) {
    39  }
    40  
    41  var tests = []struct{
    42  	name string
    43  	fn func()
    44  }{
    45  	// Edit .+1,/^}/s/^[^	].+/	{"&", func() { println(&) }},\n	{"\&&", func() { println(\&&) }},/g
    46  	{"*intp", func() { println(*intp) }},
    47  	{"&*intp", func() { println(&*intp) }},
    48  	{"*slicep", func() { println(*slicep) }},
    49  	{"&*slicep", func() { println(&*slicep) }},
    50  	{"(*slicep)[0]", func() { println((*slicep)[0]) }},
    51  	{"&(*slicep)[0]", func() { println(&(*slicep)[0]) }},
    52  	{"(*slicep)[i]", func() { println((*slicep)[i]) }},
    53  	{"&(*slicep)[i]", func() { println(&(*slicep)[i]) }},
    54  	{"*a10p", func() { use(*a10p) }},
    55  	{"&*a10p", func() { println(&*a10p) }},
    56  	{"a10p[0]", func() { println(a10p[0]) }},
    57  	{"&a10p[0]", func() { println(&a10p[0]) }},
    58  	{"a10p[i]", func() { println(a10p[i]) }},
    59  	{"&a10p[i]", func() { println(&a10p[i]) }},
    60  	{"*structp", func() { use(*structp) }},
    61  	{"&*structp", func() { println(&*structp) }},
    62  	{"structp.i", func() { println(structp.i) }},
    63  	{"&structp.i", func() { println(&structp.i) }},
    64  	{"structp.j", func() { println(structp.j) }},
    65  	{"&structp.j", func() { println(&structp.j) }},
    66  	{"structp.k", func() { println(structp.k) }},
    67  	{"&structp.k", func() { println(&structp.k) }},
    68  	{"structp.x[0]", func() { println(structp.x[0]) }},
    69  	{"&structp.x[0]", func() { println(&structp.x[0]) }},
    70  	{"structp.x[i]", func() { println(structp.x[i]) }},
    71  	{"&structp.x[i]", func() { println(&structp.x[i]) }},
    72  	{"structp.x[9]", func() { println(structp.x[9]) }},
    73  	{"&structp.x[9]", func() { println(&structp.x[9]) }},
    74  	{"structp.l", func() { println(structp.l) }},
    75  	{"&structp.l", func() { println(&structp.l) }},
    76  	{"*bigstructp", func() { use(*bigstructp) }},
    77  	{"&*bigstructp", func() { println(&*bigstructp) }},
    78  	{"bigstructp.i", func() { println(bigstructp.i) }},
    79  	{"&bigstructp.i", func() { println(&bigstructp.i) }},
    80  	{"bigstructp.j", func() { println(bigstructp.j) }},
    81  	{"&bigstructp.j", func() { println(&bigstructp.j) }},
    82  	{"bigstructp.k", func() { println(bigstructp.k) }},
    83  	{"&bigstructp.k", func() { println(&bigstructp.k) }},
    84  	{"bigstructp.x[0]", func() { println(bigstructp.x[0]) }},
    85  	{"&bigstructp.x[0]", func() { println(&bigstructp.x[0]) }},
    86  	{"bigstructp.x[i]", func() { println(bigstructp.x[i]) }},
    87  	{"&bigstructp.x[i]", func() { println(&bigstructp.x[i]) }},
    88  	{"bigstructp.x[9]", func() { println(bigstructp.x[9]) }},
    89  	{"&bigstructp.x[9]", func() { println(&bigstructp.x[9]) }},
    90  	{"bigstructp.x[100<<20]", func() { println(bigstructp.x[100<<20]) }},
    91  	{"&bigstructp.x[100<<20]", func() { println(&bigstructp.x[100<<20]) }},
    92  	{"bigstructp.l", func() { println(bigstructp.l) }},
    93  	{"&bigstructp.l", func() { println(&bigstructp.l) }},
    94  	{"m1.F()", func() { println(m1.F()) }},
    95  	{"m1.M.F()", func() { println(m1.M.F()) }},
    96  	{"m2.F()", func() { println(m2.F()) }},
    97  	{"m2.M.F()", func() { println(m2.M.F()) }},
    98  }
    99  
   100  type Struct struct {
   101  	i int
   102  	j float64
   103  	k string
   104  	x [10]int
   105  	l []byte
   106  }
   107  
   108  type BigStruct struct {
   109  	i int
   110  	j float64
   111  	k string
   112  	x [128<<20]byte
   113  	l []byte
   114  }
   115  
   116  type M struct {
   117  }
   118  
   119  func (m *M) F() int {return 0}
   120  
   121  type M1 struct {
   122  	M
   123  }
   124  
   125  type M2 struct {
   126  	x int
   127  	M
   128  }
   129  

View as plain text