blob: f13258854e5c45e72de8bf1447271e576545e662 [file] [log] [blame]
Russ Cox7e97d392013-07-12 13:47:55 -04001// run
2
Emmanuel Odeke53fd5222016-04-10 14:32:26 -07003// Copyright 2013 The Go Authors. All rights reserved.
Russ Cox7e97d392013-07-12 13:47:55 -04004// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package main
8
9import (
10 "fmt"
11 "os"
12 "runtime"
13 "strings"
14)
15
16func main() {
17 f()
18 panic("deferred function not run")
19}
20
21var x = 1
22
23func f() {
24 if x == 0 {
25 return
26 }
27 defer g()
28 panic("panic")
29}
30
31func g() {
Keith Randall69c2c562018-12-04 07:58:18 -080032 _, file, line, _ := runtime.Caller(2)
Russ Cox7e97d392013-07-12 13:47:55 -040033 if !strings.HasSuffix(file, "issue5856.go") || line != 28 {
34 fmt.Printf("BUG: defer called from %s:%d, want issue5856.go:28\n", file, line)
35 os.Exit(1)
36 }
37 os.Exit(0)
38}