From 939480033aa2c09f1b511a1928c0b465f41a45da Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 18 Nov 2021 16:11:10 -0800 Subject: [PATCH] spec: adjust assignability rules for type parameters Change-Id: I3c4d8bdb5e92ee7fdca9593fb043f94f467755e8 Reviewed-on: https://go-review.googlesource.com/c/go/+/365434 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 186600f015..904132adf0 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1848,21 +1848,22 @@ A value x is assignable to a variable
  • x's type V and T have identical -underlying types and at least one of V -or T is not a defined type. +underlying types and at least one of V +or T is not a named type.
  • -T is an interface type and -x implements T. +x's type V and T are channel types with +identical element types, V is a bidirectional channel, +and at least one of V or T is not a named type.
  • -x is a bidirectional channel value, T is a channel type, -x's type V and T have identical element types, -and at least one of V or T is not a defined type. +T is an interface type, but not a type parameter, and +x implements T.
  • x is the predeclared identifier nil and T -is a pointer, function, slice, map, channel, or interface type. +is a pointer, function, slice, map, channel, or interface type, +but not a type parameter.
  • x is an untyped constant @@ -1871,6 +1872,29 @@ by a value of type T.
  • +

    +Additionally, if x's type V or T are type parameters +with specific types, x +is assignable to a variable of type T if one of the following conditions applies: +

    + +
      +
    • +x is the predeclared identifier nil, T is +a type parameter, and x is assignable to each specific type of +T. +
    • +
    • +V is not a named type, T is +a type parameter, and x is assignable to each specific type of +T. +
    • +
    • +V is a type parameter and T is not a named type, +and values of each specific type of V are assignable +to T. +
    • +

    Representability

    -- 2.50.0