spec: adjust conversion rules for type parameters

Change-Id: I7bfddf4be0d1d95419f312bb349ae2e16b74b795
Reviewed-on: https://go-review.googlesource.com/c/go/+/365915
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Robert Griesemer 2021-11-20 13:17:27 -08:00
parent 939480033a
commit ce2a20af46

View file

@ -4633,7 +4633,9 @@ as for non-constant <code>x</code>.
</p>
<p>
Converting a constant yields a typed constant as result.
Converting a constant to a type that is not a <a href="#Type_parameters">type parameter</a>
yields a typed constant.
Converting a constant to a type parameter yields a non-constant value of that type.
</p>
<pre>
@ -4669,7 +4671,7 @@ in any of these cases:
<li>
ignoring struct tags (see below),
<code>x</code>'s type and <code>T</code> are pointer types
that are not <a href="#Type_definitions">defined types</a>,
that are not <a href="#Types">named types</a>,
and their pointer base types have identical underlying types.
</li>
<li>
@ -4692,6 +4694,28 @@ in any of these cases:
</li>
</ul>
<p>
Additionally, if <code>T</code> or </code><code>x's</code> type <code>V</code> are type
parameters with <a href="#Structure_of_interfaces">specific types</a>, <code>x</code>
can also be converted to type <code>T</code> if one of the following conditions applies:
</p>
<ul>
<li>
Both <code>V</code> and <code>T</code> are type parameters and a value of each
specific type of <code>V</code> can be converted to each specific type
of <code>T</code>.
</li>
<li>
Only <code>V</code> is a type parameter and a value of each
specific type of <code>V</code> can be converted to <code>T</code>.
</li>
<li>
Only <code>T</code> is a type parameter and <code>x</code> can can be converted to each
specific type of <code>T</code>.
</li>
</ul>
<p>
<a href="#Struct_types">Struct tags</a> are ignored when comparing struct types
for identity for the purpose of conversion: