Actually, this part is a bit more relevant:
"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."
On Fri, Dec 24, 2021, 12:50
Specifically, this part from the #Defer_statements linked by Peter:
"For instance, if the deferred function is a function literal and the
surrounding function has named result parameters that are in scope within
the literal, the deferred function may access and modify the result
parameters befo
The Go Programming Language Specification
https://go.dev/ref/spec
Defer statements
https://go.dev/ref/spec#Defer_statements
Peter
On Friday, December 24, 2021 at 8:34:58 AM UTC-5 muhorto...@gmail.com wrote:
> https://play.golang.com/p/lypWMc6Kuff
> Why do we get 2 in test() and 1 in another