mirror of https://go.googlesource.com/go
spec: explain function invocation and passing of parameters more precisely
- Describe that function invocation allocates space for a functions' variables. - Explain parameter passing in terms of assignments. Change-Id: Ia693d73a570f7d1aa2ac05e6095b4e602e4e9bf2 Reviewed-on: https://go-review.googlesource.com/c/go/+/635800 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Bypass: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Rob Pike <r@golang.org>changes/00/635800/5
parent
9f806bb76c
commit
236a0b4ffb
doc
|
@ -1,6 +1,6 @@
|
|||
<!--{
|
||||
"Title": "The Go Programming Language Specification",
|
||||
"Subtitle": "Language version go1.24 (Dec 12, 2024)",
|
||||
"Subtitle": "Language version go1.24 (Dec 16, 2024)",
|
||||
"Path": "/ref/spec"
|
||||
}-->
|
||||
|
||||
|
@ -2819,7 +2819,7 @@ values or variables, or components of other, non-interface types.
|
|||
|
||||
<p>
|
||||
A type argument <code>T</code><i> satisfies</i> a type constraint <code>C</code>
|
||||
if <code>T</code> is an element of the type set defined by <code>C</code>; i.e.,
|
||||
if <code>T</code> is an element of the type set defined by <code>C</code>; in other words,
|
||||
if <code>T</code> <a href="#Implementing_an_interface">implements</a> <code>C</code>.
|
||||
As an exception, a <a href="#Comparison_operators">strictly comparable</a>
|
||||
type constraint may also be satisfied by a <a href="#Comparison_operators">comparable</a>
|
||||
|
@ -4229,8 +4229,7 @@ calls <code>f</code> with arguments <code>a1, a2, … an</code>.
|
|||
Except for one special case, arguments must be single-valued expressions
|
||||
<a href="#Assignability">assignable</a> to the parameter types of
|
||||
<code>F</code> and are evaluated before the function is called.
|
||||
The type of the expression is the result type
|
||||
of <code>F</code>.
|
||||
The type of the expression is the result type of <code>F</code>.
|
||||
A method invocation is similar but the method itself
|
||||
is specified as a selector upon a value of the receiver type for
|
||||
the method.
|
||||
|
@ -4251,9 +4250,14 @@ or used as a function value.
|
|||
<p>
|
||||
In a function call, the function value and arguments are evaluated in
|
||||
<a href="#Order_of_evaluation">the usual order</a>.
|
||||
After they are evaluated, the parameters of the call are passed by value to the function
|
||||
After they are evaluated, new storage is allocated for the function's
|
||||
<a href="#Variables">variables</a>, which includes its parameters
|
||||
and results.
|
||||
Then, the arguments of the call are <i>passed</i> to the function,
|
||||
which means that they are <a href="#Assignment_statements">assigned</a>
|
||||
to their corresponding function parameters,
|
||||
and the called function begins execution.
|
||||
The return parameters of the function are passed by value
|
||||
The return parameters of the function are passed
|
||||
back to the caller when the function returns.
|
||||
</p>
|
||||
|
||||
|
@ -4267,9 +4271,9 @@ As a special case, if the return values of a function or method
|
|||
<code>g</code> are equal in number and individually
|
||||
assignable to the parameters of another function or method
|
||||
<code>f</code>, then the call <code>f(g(<i>parameters_of_g</i>))</code>
|
||||
will invoke <code>f</code> after binding the return values of
|
||||
<code>g</code> to the parameters of <code>f</code> in order. The call
|
||||
of <code>f</code> must contain no parameters other than the call of <code>g</code>,
|
||||
will invoke <code>f</code> after passing the return values of
|
||||
<code>g</code> to the parameters of <code>f</code> in order.
|
||||
The call of <code>f</code> must contain no parameters other than the call of <code>g</code>,
|
||||
and <code>g</code> must have at least one return value.
|
||||
If <code>f</code> has a final <code>...</code> parameter, it is
|
||||
assigned the return values of <code>g</code> that remain after
|
||||
|
@ -4315,7 +4319,7 @@ If <code>f</code> is <a href="#Function_types">variadic</a> with a final
|
|||
parameter <code>p</code> of type <code>...T</code>, then within <code>f</code>
|
||||
the type of <code>p</code> is equivalent to type <code>[]T</code>.
|
||||
If <code>f</code> is invoked with no actual arguments for <code>p</code>,
|
||||
the value passed to <code>p</code> is <code>nil</code>.
|
||||
the value <a href="#Calls">passed</a> to <code>p</code> is <code>nil</code>.
|
||||
Otherwise, the value passed is a new slice
|
||||
of type <code>[]T</code> with a new underlying array whose successive elements
|
||||
are the actual arguments, which all must be <a href="#Assignability">assignable</a>
|
||||
|
|
Loading…
Reference in New Issue