From ce2a20af467c8dfa10874abc4b45af413e2b1954 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Sat, 20 Nov 2021 13:17:27 -0800 Subject: [PATCH] spec: adjust conversion rules for type parameters Change-Id: I7bfddf4be0d1d95419f312bb349ae2e16b74b795 Reviewed-on: https://go-review.googlesource.com/c/go/+/365915 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 904132adf0..d8e6bb7b8e 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -4633,7 +4633,9 @@ as for non-constant x.

-Converting a constant yields a typed constant as result. +Converting a constant to a type that is not a type parameter +yields a typed constant. +Converting a constant to a type parameter yields a non-constant value of that type.

@@ -4669,7 +4671,7 @@ in any of these cases:
 	
  • ignoring struct tags (see below), x's type and T are pointer types - that are not defined types, + that are not named types, and their pointer base types have identical underlying types.
  • @@ -4692,6 +4694,28 @@ in any of these cases:
  • +

    +Additionally, if T or x's type V are type +parameters with specific types, x +can also be converted to type T if one of the following conditions applies: +

    + +
      +
    • +Both V and T are type parameters and a value of each +specific type of V can be converted to each specific type +of T. +
    • +
    • +Only V is a type parameter and a value of each +specific type of V can be converted to T. +
    • +
    • +Only T is a type parameter and x can can be converted to each +specific type of T. +
    • +
    +

    Struct tags are ignored when comparing struct types for identity for the purpose of conversion: