| 1 |
package a |
| 2 |
|
| 3 |
import ( |
| 4 |
"log" |
| 5 |
"os" |
| 6 |
) |
| 7 |
|
| 8 |
type X struct{ f, g int } |
| 9 |
|
| 10 |
func f(x, y *X) { |
| 11 |
if x == nil { |
| 12 |
print(x.f) |
| 13 |
} else { |
| 14 |
print(x.f) |
| 15 |
} |
| 16 |
|
| 17 |
if x == nil { |
| 18 |
if nil != y { |
| 19 |
print(1) |
| 20 |
panic(0) |
| 21 |
} |
| 22 |
x.f = 1 |
| 23 |
y.f = 1 |
| 24 |
} |
| 25 |
|
| 26 |
var f func() |
| 27 |
if f == nil { |
| 28 |
go f() |
| 29 |
} else { |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
defer f() |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
func f2(ptr *[3]int, i interface{}) { |
| 38 |
if ptr != nil { |
| 39 |
print(ptr[:]) |
| 40 |
*ptr = [3]int{} |
| 41 |
print(*ptr) |
| 42 |
} else { |
| 43 |
print(ptr[:]) |
| 44 |
*ptr = [3]int{} |
| 45 |
print(*ptr) |
| 46 |
|
| 47 |
if ptr != nil { |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
print(*ptr) |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if i != nil { |
| 56 |
print(i.(interface{ f() })) |
| 57 |
} else { |
| 58 |
print(i.(interface{ f() })) |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
func g() error { return nil } |
| 63 |
|
| 64 |
func f3() error { |
| 65 |
err := g() |
| 66 |
if err != nil { |
| 67 |
return err |
| 68 |
} |
| 69 |
if err != nil && err.Error() == "foo" { |
| 70 |
print(0) |
| 71 |
} |
| 72 |
ch := make(chan int) |
| 73 |
if ch == nil { |
| 74 |
print(0) |
| 75 |
} |
| 76 |
if ch != nil { |
| 77 |
print(0) |
| 78 |
} |
| 79 |
return nil |
| 80 |
} |
| 81 |
|
| 82 |
func h(err error, b bool) { |
| 83 |
if err != nil && b { |
| 84 |
return |
| 85 |
} else if err != nil { |
| 86 |
panic(err) |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
func i(*int) error { |
| 91 |
for { |
| 92 |
if err := g(); err != nil { |
| 93 |
return err |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
func f4(x *X) { |
| 99 |
if x == nil { |
| 100 |
panic(x) |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
func f5(x *X) { |
| 105 |
panic(nil) |
| 106 |
} |
| 107 |
|
| 108 |
func f6(x *X) { |
| 109 |
var err error |
| 110 |
panic(err) |
| 111 |
} |
| 112 |
|
| 113 |
func f7() { |
| 114 |
x, err := bad() |
| 115 |
if err != nil { |
| 116 |
panic(0) |
| 117 |
} |
| 118 |
if x == nil { |
| 119 |
panic(err) |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
func bad() (*X, error) { |
| 124 |
return nil, nil |
| 125 |
} |
| 126 |
|
| 127 |
func f8() { |
| 128 |
var e error |
| 129 |
v, _ := e.(interface{}) |
| 130 |
print(v) |
| 131 |
} |
| 132 |
|
| 133 |
func f9(x interface { |
| 134 |
a() |
| 135 |
b() |
| 136 |
c() |
| 137 |
}) { |
| 138 |
x.b() |
| 139 |
xx := interface { |
| 140 |
a() |
| 141 |
b() |
| 142 |
}(x) |
| 143 |
if xx != nil { |
| 144 |
return |
| 145 |
} |
| 146 |
x.c() |
| 147 |
xx.b() |
| 148 |
xxx := interface{ a() }(xx) |
| 149 |
xxx.a() |
| 150 |
|
| 151 |
if unknown() { |
| 152 |
panic(x) |
| 153 |
} |
| 154 |
if unknown() { |
| 155 |
panic(xx) |
| 156 |
} |
| 157 |
if unknown() { |
| 158 |
panic(xxx) |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
func f10() { |
| 163 |
s0 := make([]string, 0) |
| 164 |
if s0 == nil { |
| 165 |
print(0) |
| 166 |
} |
| 167 |
|
| 168 |
var s1 []string |
| 169 |
if s1 == nil { |
| 170 |
print(0) |
| 171 |
} |
| 172 |
s2 := s1[:][:] |
| 173 |
if s2 == nil { |
| 174 |
print(0) |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
func unknown() bool { |
| 179 |
return false |
| 180 |
} |
| 181 |
|
| 182 |
func f11(a interface{}) { |
| 183 |
switch a.(type) { |
| 184 |
case nil: |
| 185 |
return |
| 186 |
} |
| 187 |
switch a.(type) { |
| 188 |
case nil: |
| 189 |
return |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
func f12(a interface{}) { |
| 194 |
switch a { |
| 195 |
case nil: |
| 196 |
return |
| 197 |
} |
| 198 |
switch a { |
| 199 |
case 5, |
| 200 |
nil: |
| 201 |
return |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
type Y struct { |
| 206 |
innerY |
| 207 |
} |
| 208 |
|
| 209 |
type innerY struct { |
| 210 |
value int |
| 211 |
} |
| 212 |
|
| 213 |
func f13() { |
| 214 |
var d *Y |
| 215 |
print(d.value) |
| 216 |
} |
| 217 |
|
| 218 |
func f14() { |
| 219 |
var x struct{ f string } |
| 220 |
if x == struct{ f string }{} { |
| 221 |
print(x) |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
func f15(x any) { |
| 226 |
ptr, ok := x.(*int) |
| 227 |
if ok { |
| 228 |
return |
| 229 |
} |
| 230 |
println(*ptr) |
| 231 |
} |
| 232 |
|
| 233 |
func f16(x any) { |
| 234 |
ptr, ok := x.(*int) |
| 235 |
if !ok { |
| 236 |
println(*ptr) |
| 237 |
return |
| 238 |
} |
| 239 |
println(*ptr) |
| 240 |
} |
| 241 |
|
| 242 |
func f18(x any) { |
| 243 |
ptr, ok := x.(*int) |
| 244 |
if ok { |
| 245 |
println(ptr) |
| 246 |
|
| 247 |
} |
| 248 |
println(*ptr) |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
func f19(slice []int, array *[2]int, m map[string]int, ch chan int) { |
| 255 |
if slice == nil { |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
for range slice { |
| 264 |
} |
| 265 |
for _, v := range slice { |
| 266 |
_ = v |
| 267 |
} |
| 268 |
for i := range slice { |
| 269 |
_ = slice[i] |
| 270 |
} |
| 271 |
{ |
| 272 |
var i int |
| 273 |
for i = range slice { |
| 274 |
} |
| 275 |
_ = slice[i] |
| 276 |
} |
| 277 |
for i := range slice { |
| 278 |
if i < len(slice) { |
| 279 |
_ = slice[i] |
| 280 |
} |
| 281 |
} |
| 282 |
if len(slice) > 3 { |
| 283 |
_ = slice[2] |
| 284 |
} |
| 285 |
for i := 0; i < len(slice); i++ { |
| 286 |
_ = slice[i] |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
if array == nil { |
| 291 |
|
| 292 |
|
| 293 |
for _, v := range array { |
| 294 |
_ = v |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
if m == nil { |
| 299 |
for range m { |
| 300 |
} |
| 301 |
m["one"] = 1 |
| 302 |
} |
| 303 |
|
| 304 |
if ch == nil { |
| 305 |
for range ch { |
| 306 |
} |
| 307 |
<-ch |
| 308 |
ch <- 0 |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
func f20() { |
| 313 |
f, err := os.Open("") |
| 314 |
if err != nil { |
| 315 |
log.Fatal(err) |
| 316 |
} |
| 317 |
if err != nil { |
| 318 |
log.Fatal(err) |
| 319 |
} |
| 320 |
f.Close() |
| 321 |
} |