Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: panic line number of deferred functions is ambiguous #16011

Closed
dsnet opened this issue Jun 8, 2016 · 2 comments
Closed

cmd/compile: panic line number of deferred functions is ambiguous #16011

dsnet opened this issue Jun 8, 2016 · 2 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Jun 8, 2016

Using go1.6

Consider the following:

package main

func Foo(b bool) {
    if b {
        panic("ha")
    }
}

func main() {         // Line  9
    defer Foo(false)  // Line 10
    defer Foo(true)   // Line 11
    defer Foo(false)  // Line 12
    defer Foo(false)  // Line 13
}                     // Line 14

Currently, this prints:

panic: ha

goroutine 1 [running]:
panic(0x94e60, 0x1030a040)
    /usr/local/go/src/runtime/panic.go:481 +0x700
main.Foo(0x10327f01, 0xb4a00)
    /tmp/sandbox118729948/main.go:5 +0x80
main.main()
    /tmp/sandbox118729948/main.go:14 +0x13b

However, the stack trace reports that the panic occurs at Line 14 of main, which is technically correct since it is at the end of the function and now executing deferred functions. However, it is ambiguous exactly which of the calls to Foo was part of the real stack trace.

Any thoughts on having the printed line number be the line number where the defer occurred? In this example, it would be Line 11.

@ianlancetaylor
Copy link
Contributor

See also #14646 and https://tip.golang.org/test/fixedbugs/issue14646.go .

That is, we could change it, but the current behavior is intentional.

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jun 8, 2016
@quentinmit quentinmit added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 11, 2016
@rsc
Copy link
Contributor

rsc commented Oct 21, 2016

Working as intended. The line where the defer was executed is gone.

@rsc rsc closed this as completed Oct 21, 2016
@golang golang locked and limited conversation to collaborators Oct 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants