Commit b4eb22d7 authored by Robert Griesemer's avatar Robert Griesemer

spec: clarify panic behavior when deferring nil functions

Fixes #8107.

LGTM=iant, rsc, r
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/145960043
parent 0e1a0716
<!--{ <!--{
"Title": "The Go Programming Language Specification", "Title": "The Go Programming Language Specification",
"Subtitle": "Version of August 28, 2014", "Subtitle": "Version of September 19, 2014",
"Path": "/ref/spec" "Path": "/ref/spec"
}--> }-->
...@@ -5243,13 +5243,16 @@ Calls of built-in functions are restricted as for ...@@ -5243,13 +5243,16 @@ Calls of built-in functions are restricted as for
</p> </p>
<p> <p>
Each time the "defer" statement Each time a "defer" statement
executes, the function value and parameters to the call are executes, the function value and parameters to the call are
<a href="#Calls">evaluated as usual</a> <a href="#Calls">evaluated as usual</a>
and saved anew but the actual function body is not executed. and saved anew but the actual function is not invoked.
Instead, deferred functions are executed immediately before Instead, deferred functions are invoked immediately before
the surrounding function returns, in the reverse order the surrounding function returns, in the reverse order
they were deferred. they were deferred.
If a deferred function value evaluates
to <code>nil</code>, execution <a href="#Handling_panics">panics</a>
when the function is invoked not when the "defer" statement is executed.
</p> </p>
<p> <p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment