From 633a2ce096464a63d939c645f31c6bf9d245b042 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 23 Jan 2012 08:40:13 -0800 Subject: [PATCH] spec: function invocation, panic on *nil Document that indirection through a nil pointer will panic. Explain function invocation. This section will need more work, but it's a start. Fixes #1865. Fixes #2252. R=rsc, iant, r CC=golang-dev https://golang.org/cl/5532114 --- doc/go_spec.html | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 8bf6c2195a2..d7b0d763266 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -4493,9 +4515,11 @@ DeferStmt = "defer" Expression .

The expression must be a function or method call. Each time the "defer" statement -executes, the parameters to the function call are evaluated and saved anew but the -function is not invoked. -Deferred function calls are executed in LIFO order +executes, the function value and parameters to the call are +evaluated as usual +and saved anew but the +actual function is not invoked. +Instead, deferred calls are executed in LIFO order immediately before the surrounding function returns, after the return values, if any, have been evaluated, but before they are returned to the caller. For instance, if the deferred function is @@ -4503,6 +4527,8 @@ 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 before they are returned. +If the deferred function has any return values, they are discarded when +the function completes.

@@ -5355,9 +5381,7 @@ A struct or array type has size zero if it contains no fields (or elements, resp
 

-

Implementation differences - TODO

    -
  • len(a) is only a constant if a is a (qualified) identifier denoting an array or pointer to an array.
  • +
  • len(x) is only a constant if x is a (qualified) identifier denoting an array or pointer to an array.
-