Skip to content

Commit 27d50bd

Browse files
griesemerwheatman
authored andcommitted
spec: clarify panic behavior when deferring nil functions
Fixes golang#8107. LGTM=iant, rsc, r R=r, rsc, iant, ken CC=golang-codereviews https://golang.org/cl/145960043
1 parent c482921 commit 27d50bd

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

doc/go_spec.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification",
3-
"Subtitle": "Version of August 28, 2014",
3+
"Subtitle": "Version of September 19, 2014",
44
"Path": "/ref/spec"
55
}-->
66

@@ -5240,13 +5240,16 @@ <h3 id="Defer_statements">Defer statements</h3>
52405240
</p>
52415241

52425242
<p>
5243-
Each time the "defer" statement
5243+
Each time a "defer" statement
52445244
executes, the function value and parameters to the call are
52455245
<a href="#Calls">evaluated as usual</a>
5246-
and saved anew but the actual function body is not executed.
5247-
Instead, deferred functions are executed immediately before
5246+
and saved anew but the actual function is not invoked.
5247+
Instead, deferred functions are invoked immediately before
52485248
the surrounding function returns, in the reverse order
52495249
they were deferred.
5250+
If a deferred function value evaluates
5251+
to <code>nil</code>, execution <a href="#Handling_panics">panics</a>
5252+
when the function is invoked not when the "defer" statement is executed.
52505253
</p>
52515254

52525255
<p>

0 commit comments

Comments
 (0)