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: defer of nil interface call does not panic #15975

Closed
aclements opened this issue Jun 6, 2016 · 2 comments
Closed

cmd/compile: defer of nil interface call does not panic #15975

aclements opened this issue Jun 6, 2016 · 2 comments
Milestone

Comments

@aclements
Copy link
Member

The following program behaves differently depending on whether or not it's compiled with SSA:

package main

type Closer interface {
    Close()
}

func main() {
    var x Closer
    defer x.Close()
    println("not reached")
}

When compiled without SSA, it does not print "not reached". However, when compiled with SSA, it does print "not reached". Based on my understanding of the spec, this program should not print "not reached" because the evaluation of x.Close to a function value happens on the defer line and should cause a nil panic (though either way it shouldn't change with SSA).

$ go run -gcflags -ssa=0 x.go
panic: runtime error: invalid memory address or nil pointer dereference
...

$ go run x.go
not reached
panic: runtime error: invalid memory address or nil pointer dereference

This pattern appears in test/fixedbugs/issue6055.go.

/cc @cherrymui @randall77

@aclements aclements added this to the Go1.7 milestone Jun 6, 2016
@dsnet dsnet changed the title cmd/compile: defer of nil interface call dose not panic cmd/compile: defer of nil interface call does not panic Jun 6, 2016
@cherrymui
Copy link
Member

It also behaves differently for go statement (change the defer to go in the above test case).
CL 23820 mailed for matching the old behavior.

@gopherbot
Copy link

CL https://golang.org/cl/23820 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants