diff --git a/doc/go_spec.html b/doc/go_spec.html index 57bb3b53f5..32336e86f8 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -5546,7 +5546,10 @@ executes, the function value and parameters to the call are and saved anew but the actual function is not invoked. Instead, deferred functions are invoked immediately before the surrounding function returns, in the reverse order -they were deferred. +they were deferred. That is, if the surrounding function +returns through an explicit return statement, +deferred functions are executed after any result parameters are set +by that return statement but before the function returns to its caller. If a deferred function value evaluates to nil, execution panics when the function is invoked, not when the "defer" statement is executed. @@ -5572,12 +5575,13 @@ for i := 0; i <= 3; i++ { defer fmt.Print(i) } -// f returns 1 +// f returns 42 func f() (result int) { defer func() { - result++ + // result is accessed after it was set to 6 by the return statement + result *= 7 }() - return 0 + return 6 }