Russ Cox | 57eb06f | 2012-02-16 23:51:04 -0500 | [diff] [blame] | 1 | // run |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 2 | |
| 3 | // Copyright 2010 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 | // Test of basic recover functionality. |
| 8 | |
| 9 | package main |
| 10 | |
Alan Donovan | aa5aaab | 2013-02-21 12:48:38 -0500 | [diff] [blame] | 11 | import ( |
| 12 | "os" |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 13 | "reflect" |
Alan Donovan | aa5aaab | 2013-02-21 12:48:38 -0500 | [diff] [blame] | 14 | "runtime" |
| 15 | ) |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 16 | |
| 17 | func main() { |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 18 | // go.tools/ssa/interp still has: |
| 19 | // - some lesser bugs in recover() |
| 20 | // - incomplete support for reflection |
| 21 | interp := os.Getenv("GOSSAINTERP") != "" |
| 22 | |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 23 | test1() |
| 24 | test1WithClosures() |
| 25 | test2() |
| 26 | test3() |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 27 | if !interp { |
Alan Donovan | aa5aaab | 2013-02-21 12:48:38 -0500 | [diff] [blame] | 28 | test4() |
Alan Donovan | aa5aaab | 2013-02-21 12:48:38 -0500 | [diff] [blame] | 29 | } |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 30 | test5() |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 31 | test6() |
| 32 | test6WithClosures() |
| 33 | test7() |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 34 | test8() |
| 35 | test9() |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 36 | if !interp { |
| 37 | test9reflect1() |
| 38 | test9reflect2() |
| 39 | } |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 40 | test10() |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 41 | if !interp { |
| 42 | test10reflect1() |
| 43 | test10reflect2() |
| 44 | } |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 45 | test11() |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 46 | if !interp { |
| 47 | test11reflect1() |
| 48 | test11reflect2() |
| 49 | } |
Russ Cox | 8473695 | 2014-09-06 13:19:08 -0400 | [diff] [blame^] | 50 | test111() |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 51 | test12() |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 52 | if !interp { |
| 53 | test12reflect1() |
| 54 | test12reflect2() |
| 55 | } |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 56 | test13() |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 57 | if !interp { |
| 58 | test13reflect1() |
| 59 | test13reflect2() |
| 60 | } |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 61 | test14() |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 62 | if !interp { |
| 63 | test14reflect1() |
| 64 | test14reflect2() |
| 65 | test15() |
| 66 | } |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | func die() { |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 70 | runtime.Breakpoint() // can't depend on panic |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 73 | func mustRecoverBody(v1, v2, v3, x interface{}) { |
| 74 | v := v1 |
| 75 | if v != nil { |
| 76 | println("spurious recover", v) |
| 77 | die() |
| 78 | } |
| 79 | v = v2 |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 80 | if v == nil { |
Russ Cox | 8473695 | 2014-09-06 13:19:08 -0400 | [diff] [blame^] | 81 | println("missing recover", x.(int)) |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 82 | die() // panic is useless here |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 83 | } |
| 84 | if v != x { |
| 85 | println("wrong value", v, x) |
| 86 | die() |
| 87 | } |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 88 | |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 89 | // the value should be gone now regardless |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 90 | v = v3 |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 91 | if v != nil { |
| 92 | println("recover didn't recover") |
| 93 | die() |
| 94 | } |
| 95 | } |
| 96 | |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 97 | func doubleRecover() interface{} { |
| 98 | return recover() |
| 99 | } |
| 100 | |
| 101 | func mustRecover(x interface{}) { |
| 102 | mustRecoverBody(doubleRecover(), recover(), recover(), x) |
| 103 | } |
| 104 | |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 105 | func mustNotRecover() { |
| 106 | v := recover() |
| 107 | if v != nil { |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 108 | println("spurious recover", v) |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 109 | die() |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | func withoutRecover() { |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 114 | mustNotRecover() // because it's a sub-call |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | func test1() { |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 118 | defer mustNotRecover() // because mustRecover will squelch it |
| 119 | defer mustRecover(1) // because of panic below |
| 120 | defer withoutRecover() // should be no-op, leaving for mustRecover to find |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 121 | panic(1) |
| 122 | } |
| 123 | |
| 124 | // Repeat test1 with closures instead of standard function. |
| 125 | // Interesting because recover bases its decision |
| 126 | // on the frame pointer of its caller, and a closure's |
| 127 | // frame pointer is in the middle of its actual arguments |
| 128 | // (after the hidden ones for the closed-over variables). |
| 129 | func test1WithClosures() { |
| 130 | defer func() { |
| 131 | v := recover() |
| 132 | if v != nil { |
| 133 | println("spurious recover in closure") |
| 134 | die() |
| 135 | } |
| 136 | }() |
| 137 | defer func(x interface{}) { |
| 138 | mustNotRecover() |
| 139 | v := recover() |
| 140 | if v == nil { |
Russ Cox | 8473695 | 2014-09-06 13:19:08 -0400 | [diff] [blame^] | 141 | println("missing recover", x.(int)) |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 142 | die() |
| 143 | } |
| 144 | if v != x { |
| 145 | println("wrong value", v, x) |
| 146 | die() |
| 147 | } |
| 148 | }(1) |
| 149 | defer func() { |
| 150 | mustNotRecover() |
| 151 | }() |
| 152 | panic(1) |
| 153 | } |
| 154 | |
| 155 | func test2() { |
| 156 | // Recover only sees the panic argument |
| 157 | // if it is called from a deferred call. |
| 158 | // It does not see the panic when called from a call within a deferred call (too late) |
| 159 | // nor does it see the panic when it *is* the deferred call (too early). |
| 160 | defer mustRecover(2) |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 161 | defer recover() // should be no-op |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 162 | panic(2) |
| 163 | } |
| 164 | |
| 165 | func test3() { |
| 166 | defer mustNotRecover() |
| 167 | defer func() { |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 168 | recover() // should squelch |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 169 | }() |
| 170 | panic(3) |
| 171 | } |
| 172 | |
| 173 | func test4() { |
| 174 | // Equivalent to test3 but using defer to make the call. |
| 175 | defer mustNotRecover() |
| 176 | defer func() { |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 177 | defer recover() // should squelch |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 178 | }() |
| 179 | panic(4) |
| 180 | } |
| 181 | |
| 182 | // Check that closures can set output arguments. |
| 183 | // Run g(). If it panics, return x; else return deflt. |
| 184 | func try(g func(), deflt interface{}) (x interface{}) { |
| 185 | defer func() { |
| 186 | if v := recover(); v != nil { |
| 187 | x = v |
| 188 | } |
| 189 | }() |
| 190 | defer g() |
| 191 | return deflt |
| 192 | } |
| 193 | |
| 194 | // Check that closures can set output arguments. |
| 195 | // Run g(). If it panics, return x; else return deflt. |
| 196 | func try1(g func(), deflt interface{}) (x interface{}) { |
| 197 | defer func() { |
| 198 | if v := recover(); v != nil { |
| 199 | x = v |
| 200 | } |
| 201 | }() |
| 202 | defer g() |
| 203 | x = deflt |
| 204 | return |
| 205 | } |
| 206 | |
| 207 | func test5() { |
| 208 | v := try(func() { panic(5) }, 55).(int) |
| 209 | if v != 5 { |
| 210 | println("wrong value", v, 5) |
| 211 | die() |
| 212 | } |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 213 | |
| 214 | s := try(func() {}, "hi").(string) |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 215 | if s != "hi" { |
| 216 | println("wrong value", s, "hi") |
| 217 | die() |
| 218 | } |
| 219 | |
| 220 | v = try1(func() { panic(5) }, 55).(int) |
| 221 | if v != 5 { |
| 222 | println("try1 wrong value", v, 5) |
| 223 | die() |
| 224 | } |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 225 | |
| 226 | s = try1(func() {}, "hi").(string) |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 227 | if s != "hi" { |
| 228 | println("try1 wrong value", s, "hi") |
| 229 | die() |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // When a deferred big call starts, it must first |
| 234 | // create yet another stack segment to hold the |
| 235 | // giant frame for x. Make sure that doesn't |
| 236 | // confuse recover. |
| 237 | func big(mustRecover bool) { |
| 238 | var x [100000]int |
| 239 | x[0] = 1 |
| 240 | x[99999] = 1 |
| 241 | _ = x |
Russ Cox | f75d0d2 | 2010-04-01 22:31:27 -0700 | [diff] [blame] | 242 | |
Russ Cox | b6ad074 | 2010-03-31 11:47:09 -0700 | [diff] [blame] | 243 | v := recover() |
| 244 | if mustRecover { |
| 245 | if v == nil { |
| 246 | println("missing big recover") |
| 247 | die() |
| 248 | } |
| 249 | } else { |
| 250 | if v != nil { |
| 251 | println("spurious big recover") |
| 252 | die() |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | func test6() { |
| 258 | defer big(false) |
| 259 | defer big(true) |
| 260 | panic(6) |
| 261 | } |
| 262 | |
| 263 | func test6WithClosures() { |
| 264 | defer func() { |
| 265 | var x [100000]int |
| 266 | x[0] = 1 |
| 267 | x[99999] = 1 |
| 268 | _ = x |
| 269 | if recover() != nil { |
| 270 | println("spurious big closure recover") |
| 271 | die() |
| 272 | } |
| 273 | }() |
| 274 | defer func() { |
| 275 | var x [100000]int |
| 276 | x[0] = 1 |
| 277 | x[99999] = 1 |
| 278 | _ = x |
| 279 | if recover() == nil { |
| 280 | println("missing big closure recover") |
| 281 | die() |
| 282 | } |
| 283 | }() |
| 284 | panic("6WithClosures") |
| 285 | } |
| 286 | |
| 287 | func test7() { |
| 288 | ok := false |
| 289 | func() { |
| 290 | // should panic, then call mustRecover 7, which stops the panic. |
| 291 | // then should keep processing ordinary defers earlier than that one |
| 292 | // before returning. |
| 293 | // this test checks that the defer func on the next line actually runs. |
| 294 | defer func() { ok = true }() |
| 295 | defer mustRecover(7) |
| 296 | panic(7) |
| 297 | }() |
| 298 | if !ok { |
| 299 | println("did not run ok func") |
| 300 | die() |
| 301 | } |
| 302 | } |
Ian Lance Taylor | b14a664 | 2012-03-01 08:24:03 -0800 | [diff] [blame] | 303 | |
| 304 | func varargs(s *int, a ...int) { |
| 305 | *s = 0 |
| 306 | for _, v := range a { |
| 307 | *s += v |
| 308 | } |
| 309 | if recover() != nil { |
| 310 | *s += 100 |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | func test8a() (r int) { |
| 315 | defer varargs(&r, 1, 2, 3) |
| 316 | panic(0) |
| 317 | } |
| 318 | |
| 319 | func test8b() (r int) { |
| 320 | defer varargs(&r, 4, 5, 6) |
| 321 | return |
| 322 | } |
| 323 | |
| 324 | func test8() { |
| 325 | if test8a() != 106 || test8b() != 15 { |
| 326 | println("wrong value") |
| 327 | die() |
| 328 | } |
| 329 | } |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 330 | |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 331 | type I interface { |
| 332 | M() |
| 333 | } |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 334 | |
| 335 | // pointer receiver, so no wrapper in i.M() |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 336 | type T1 struct{} |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 337 | |
| 338 | func (*T1) M() { |
| 339 | mustRecoverBody(doubleRecover(), recover(), recover(), 9) |
| 340 | } |
| 341 | |
| 342 | func test9() { |
| 343 | var i I = &T1{} |
| 344 | defer i.M() |
| 345 | panic(9) |
| 346 | } |
| 347 | |
| 348 | func test9reflect1() { |
| 349 | f := reflect.ValueOf(&T1{}).Method(0).Interface().(func()) |
| 350 | defer f() |
| 351 | panic(9) |
| 352 | } |
| 353 | |
| 354 | func test9reflect2() { |
| 355 | f := reflect.TypeOf(&T1{}).Method(0).Func.Interface().(func(*T1)) |
| 356 | defer f(&T1{}) |
| 357 | panic(9) |
| 358 | } |
| 359 | |
| 360 | // word-sized value receiver, so no wrapper in i.M() |
| 361 | type T2 uintptr |
| 362 | |
| 363 | func (T2) M() { |
| 364 | mustRecoverBody(doubleRecover(), recover(), recover(), 10) |
| 365 | } |
| 366 | |
| 367 | func test10() { |
| 368 | var i I = T2(0) |
| 369 | defer i.M() |
| 370 | panic(10) |
| 371 | } |
| 372 | |
| 373 | func test10reflect1() { |
| 374 | f := reflect.ValueOf(T2(0)).Method(0).Interface().(func()) |
| 375 | defer f() |
| 376 | panic(10) |
| 377 | } |
| 378 | |
| 379 | func test10reflect2() { |
| 380 | f := reflect.TypeOf(T2(0)).Method(0).Func.Interface().(func(T2)) |
| 381 | defer f(T2(0)) |
| 382 | panic(10) |
| 383 | } |
| 384 | |
| 385 | // tiny receiver, so basic wrapper in i.M() |
Alan Donovan | 3ddf5a6 | 2013-09-18 14:44:57 -0400 | [diff] [blame] | 386 | type T3 struct{} |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 387 | |
| 388 | func (T3) M() { |
| 389 | mustRecoverBody(doubleRecover(), recover(), recover(), 11) |
| 390 | } |
| 391 | |
| 392 | func test11() { |
| 393 | var i I = T3{} |
| 394 | defer i.M() |
| 395 | panic(11) |
| 396 | } |
| 397 | |
| 398 | func test11reflect1() { |
| 399 | f := reflect.ValueOf(T3{}).Method(0).Interface().(func()) |
| 400 | defer f() |
| 401 | panic(11) |
| 402 | } |
| 403 | |
| 404 | func test11reflect2() { |
| 405 | f := reflect.TypeOf(T3{}).Method(0).Func.Interface().(func(T3)) |
| 406 | defer f(T3{}) |
| 407 | panic(11) |
| 408 | } |
| 409 | |
Russ Cox | 8473695 | 2014-09-06 13:19:08 -0400 | [diff] [blame^] | 410 | // tiny receiver, so basic wrapper in i.M() |
| 411 | type T3deeper struct{} |
| 412 | |
| 413 | func (T3deeper) M() { |
| 414 | badstate() // difference from T3 |
| 415 | mustRecoverBody(doubleRecover(), recover(), recover(), 111) |
| 416 | } |
| 417 | |
| 418 | func test111() { |
| 419 | var i I = T3deeper{} |
| 420 | defer i.M() |
| 421 | panic(111) |
| 422 | } |
| 423 | |
| 424 | type Tiny struct{} |
| 425 | |
| 426 | func (Tiny) M() { |
| 427 | panic(112) |
| 428 | } |
| 429 | |
| 430 | // i.M is a wrapper, and i.M panics. |
| 431 | // |
| 432 | // This is a torture test for an old implementation of recover that |
| 433 | // tried to deal with wrapper functions by doing some argument |
| 434 | // positioning math on both entry and exit. Doing anything on exit |
| 435 | // is a problem because sometimes functions exit via panic instead |
| 436 | // of an ordinary return, so panic would have to know to do the |
| 437 | // same math when unwinding the stack. It gets complicated fast. |
| 438 | // This particular test never worked with the old scheme, because |
| 439 | // panic never did the right unwinding math. |
| 440 | // |
| 441 | // The new scheme adjusts Panic.argp on entry to a wrapper. |
| 442 | // It has no exit work, so if a wrapper is interrupted by a panic, |
| 443 | // there's no cleanup that panic itself must do. |
| 444 | // This test just works now. |
| 445 | func badstate() { |
| 446 | defer func() { |
| 447 | recover() |
| 448 | }() |
| 449 | var i I = Tiny{} |
| 450 | i.M() |
| 451 | } |
| 452 | |
Russ Cox | 7276c02 | 2013-09-12 14:00:16 -0400 | [diff] [blame] | 453 | // large receiver, so basic wrapper in i.M() |
| 454 | type T4 [2]string |
| 455 | |
| 456 | func (T4) M() { |
| 457 | mustRecoverBody(doubleRecover(), recover(), recover(), 12) |
| 458 | } |
| 459 | |
| 460 | func test12() { |
| 461 | var i I = T4{} |
| 462 | defer i.M() |
| 463 | panic(12) |
| 464 | } |
| 465 | |
| 466 | func test12reflect1() { |
| 467 | f := reflect.ValueOf(T4{}).Method(0).Interface().(func()) |
| 468 | defer f() |
| 469 | panic(12) |
| 470 | } |
| 471 | |
| 472 | func test12reflect2() { |
| 473 | f := reflect.TypeOf(T4{}).Method(0).Func.Interface().(func(T4)) |
| 474 | defer f(T4{}) |
| 475 | panic(12) |
| 476 | } |
| 477 | |
| 478 | // enormous receiver, so wrapper splits stack to call M |
| 479 | type T5 [8192]byte |
| 480 | |
| 481 | func (T5) M() { |
| 482 | mustRecoverBody(doubleRecover(), recover(), recover(), 13) |
| 483 | } |
| 484 | |
| 485 | func test13() { |
| 486 | var i I = T5{} |
| 487 | defer i.M() |
| 488 | panic(13) |
| 489 | } |
| 490 | |
| 491 | func test13reflect1() { |
| 492 | f := reflect.ValueOf(T5{}).Method(0).Interface().(func()) |
| 493 | defer f() |
| 494 | panic(13) |
| 495 | } |
| 496 | |
| 497 | func test13reflect2() { |
| 498 | f := reflect.TypeOf(T5{}).Method(0).Func.Interface().(func(T5)) |
| 499 | defer f(T5{}) |
| 500 | panic(13) |
| 501 | } |
| 502 | |
| 503 | // enormous receiver + enormous method frame, so wrapper splits stack to call M, |
| 504 | // and then M splits stack to allocate its frame. |
| 505 | // recover must look back two frames to find the panic. |
| 506 | type T6 [8192]byte |
| 507 | |
| 508 | var global byte |
| 509 | |
| 510 | func (T6) M() { |
| 511 | var x [8192]byte |
| 512 | x[0] = 1 |
| 513 | x[1] = 2 |
| 514 | for i := range x { |
| 515 | global += x[i] |
| 516 | } |
| 517 | mustRecoverBody(doubleRecover(), recover(), recover(), 14) |
| 518 | } |
| 519 | |
| 520 | func test14() { |
| 521 | var i I = T6{} |
| 522 | defer i.M() |
| 523 | panic(14) |
| 524 | } |
| 525 | |
| 526 | func test14reflect1() { |
| 527 | f := reflect.ValueOf(T6{}).Method(0).Interface().(func()) |
| 528 | defer f() |
| 529 | panic(14) |
| 530 | } |
| 531 | |
| 532 | func test14reflect2() { |
| 533 | f := reflect.TypeOf(T6{}).Method(0).Func.Interface().(func(T6)) |
| 534 | defer f(T6{}) |
| 535 | panic(14) |
| 536 | } |
| 537 | |
| 538 | // function created by reflect.MakeFunc |
| 539 | |
| 540 | func reflectFunc(args []reflect.Value) (results []reflect.Value) { |
| 541 | mustRecoverBody(doubleRecover(), recover(), recover(), 15) |
| 542 | return nil |
| 543 | } |
| 544 | |
| 545 | func test15() { |
| 546 | f := reflect.MakeFunc(reflect.TypeOf((func())(nil)), reflectFunc).Interface().(func()) |
| 547 | defer f() |
| 548 | panic(15) |
| 549 | } |