diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 13:14:23 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 13:14:23 +0000 |
commit | 73df946d56c74384511a194dd01dbe099584fd1a (patch) | |
tree | fd0bcea490dd81327ddfbb31e215439672c9a068 /test/nilptr2.go | |
parent | Initial commit. (diff) | |
download | golang-1.16-upstream.tar.xz golang-1.16-upstream.zip |
Adding upstream version 1.16.10.upstream/1.16.10upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/nilptr2.go | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/test/nilptr2.go b/test/nilptr2.go new file mode 100644 index 0000000..8a85b6d --- /dev/null +++ b/test/nilptr2.go @@ -0,0 +1,131 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + ok := true + for _, tt := range tests { + func() { + defer func() { + if err := recover(); err == nil { + println(tt.name, "did not panic") + ok = false + } + }() + tt.fn() + }() + } + if !ok { + println("BUG") + } +} + +var intp *int +var slicep *[]byte +var a10p *[10]int +var a10Mp *[1<<20]int +var structp *Struct +var bigstructp *BigStruct +var i int +var m *M +var m1 *M1 +var m2 *M2 + +var V interface{} + +func use(x interface{}) { + V = x +} + +var tests = []struct{ + name string + fn func() +}{ + // Edit .+1,/^}/s/^[^ ].+/ {"&", func() { println(&) }},\n {"\&&", func() { println(\&&) }},/g + {"*intp", func() { println(*intp) }}, + {"&*intp", func() { println(&*intp) }}, + {"*slicep", func() { println(*slicep) }}, + {"&*slicep", func() { println(&*slicep) }}, + {"(*slicep)[0]", func() { println((*slicep)[0]) }}, + {"&(*slicep)[0]", func() { println(&(*slicep)[0]) }}, + {"(*slicep)[i]", func() { println((*slicep)[i]) }}, + {"&(*slicep)[i]", func() { println(&(*slicep)[i]) }}, + {"*a10p", func() { use(*a10p) }}, + {"&*a10p", func() { println(&*a10p) }}, + {"a10p[0]", func() { println(a10p[0]) }}, + {"&a10p[0]", func() { println(&a10p[0]) }}, + {"a10p[i]", func() { println(a10p[i]) }}, + {"&a10p[i]", func() { println(&a10p[i]) }}, + {"*structp", func() { use(*structp) }}, + {"&*structp", func() { println(&*structp) }}, + {"structp.i", func() { println(structp.i) }}, + {"&structp.i", func() { println(&structp.i) }}, + {"structp.j", func() { println(structp.j) }}, + {"&structp.j", func() { println(&structp.j) }}, + {"structp.k", func() { println(structp.k) }}, + {"&structp.k", func() { println(&structp.k) }}, + {"structp.x[0]", func() { println(structp.x[0]) }}, + {"&structp.x[0]", func() { println(&structp.x[0]) }}, + {"structp.x[i]", func() { println(structp.x[i]) }}, + {"&structp.x[i]", func() { println(&structp.x[i]) }}, + {"structp.x[9]", func() { println(structp.x[9]) }}, + {"&structp.x[9]", func() { println(&structp.x[9]) }}, + {"structp.l", func() { println(structp.l) }}, + {"&structp.l", func() { println(&structp.l) }}, + {"*bigstructp", func() { use(*bigstructp) }}, + {"&*bigstructp", func() { println(&*bigstructp) }}, + {"bigstructp.i", func() { println(bigstructp.i) }}, + {"&bigstructp.i", func() { println(&bigstructp.i) }}, + {"bigstructp.j", func() { println(bigstructp.j) }}, + {"&bigstructp.j", func() { println(&bigstructp.j) }}, + {"bigstructp.k", func() { println(bigstructp.k) }}, + {"&bigstructp.k", func() { println(&bigstructp.k) }}, + {"bigstructp.x[0]", func() { println(bigstructp.x[0]) }}, + {"&bigstructp.x[0]", func() { println(&bigstructp.x[0]) }}, + {"bigstructp.x[i]", func() { println(bigstructp.x[i]) }}, + {"&bigstructp.x[i]", func() { println(&bigstructp.x[i]) }}, + {"bigstructp.x[9]", func() { println(bigstructp.x[9]) }}, + {"&bigstructp.x[9]", func() { println(&bigstructp.x[9]) }}, + {"bigstructp.x[100<<20]", func() { println(bigstructp.x[100<<20]) }}, + {"&bigstructp.x[100<<20]", func() { println(&bigstructp.x[100<<20]) }}, + {"bigstructp.l", func() { println(bigstructp.l) }}, + {"&bigstructp.l", func() { println(&bigstructp.l) }}, + {"m1.F()", func() { println(m1.F()) }}, + {"m1.M.F()", func() { println(m1.M.F()) }}, + {"m2.F()", func() { println(m2.F()) }}, + {"m2.M.F()", func() { println(m2.M.F()) }}, +} + +type Struct struct { + i int + j float64 + k string + x [10]int + l []byte +} + +type BigStruct struct { + i int + j float64 + k string + x [128<<20]byte + l []byte +} + +type M struct { +} + +func (m *M) F() int {return 0} + +type M1 struct { + M +} + +type M2 struct { + x int + M +} |