Skip to content

Commit 083ef54

Browse files
committed
spec: fix conversion rules (match implementation)
As written, the conversion P(x), where P and the type of x are type parameters with identical underlying types (i.e., identical constraints), is valid. However, unless the type of x and P are identical (which is covered with the assignability rule), such a conversion is not valid in general (consider the case where both type parameters are different type parameters with constraint "any"). This change adjusts the rules to prohibit type parameters in this case. The same reasoning applies and the analogue change is made for pointer types. The type checker already implements these updated rules. Change-Id: Id90187900cb2820f6a0a0cf582cf26cdf8addbce Reviewed-on: https://go-review.googlesource.com/c/go/+/371074 Trust: Robert Griesemer <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent acc65b4 commit 083ef54

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

doc/go_spec.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification - Go 1.18 Draft (incomplete)",
3-
"Subtitle": "Version of Nov 29, 2021",
3+
"Subtitle": "Version of Dec 13, 2021",
44
"Path": "/ref/spec"
55
}-->
66

@@ -4782,14 +4782,16 @@ <h3 id="Conversions">Conversions</h3>
47824782
</li>
47834783
<li>
47844784
ignoring struct tags (see below),
4785-
<code>x</code>'s type and <code>T</code> have <a href="#Type_identity">identical</a>
4786-
<a href="#Types">underlying types</a>.
4785+
<code>x</code>'s type and <code>T</code> are not
4786+
<a href="#Type_parameters">type parameters</a> but have
4787+
<a href="#Type_identity">identical</a> <a href="#Types">underlying types</a>.
47874788
</li>
47884789
<li>
47894790
ignoring struct tags (see below),
47904791
<code>x</code>'s type and <code>T</code> are pointer types
47914792
that are not <a href="#Types">named types</a>,
4792-
and their pointer base types have identical underlying types.
4793+
and their pointer base types are not type parameters but
4794+
have identical underlying types.
47934795
</li>
47944796
<li>
47954797
<code>x</code>'s type and <code>T</code> are both integer or floating

0 commit comments

Comments
 (0)