From: Robert Griesemer Date: Tue, 23 Nov 2021 20:02:40 +0000 (-0800) Subject: spec: add definition of "specific types" of an interface X-Git-Tag: go1.18beta1~191 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5d8c49a5a13d922c24dc30675d64f0c49b676535;p=gostls13.git spec: add definition of "specific types" of an interface The notion of specific types will be used to define rules for assignability, convertability, etc. when type parameters are involved. Change-Id: Ic5c134261e2a9fe05cdf25efd342f052458ab5c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/366754 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- diff --git a/doc/go_spec.html b/doc/go_spec.html index ecd2f084c9..176e1a755d 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -1290,8 +1290,8 @@ UnderlyingType = "~" Type .

An interface type is specified by a list of interface elements. -An interface element is either a method or a type element, -where a type element is a union of one or more type terms. +An interface element is either a method or a type element, +where a type element is a union of one or more type terms. A type term is either a single type or a single underlying type.

@@ -1926,7 +1926,60 @@ x T x is not representable by a value of T because 1e1000 float64 1e1000 overflows to IEEE +Inf after rounding -

Structural interfaces

+

Structure of interfaces

+ +

+An interface specification which contains type elements +that are not interface types defines a (possibly empty) set of specific types. +Loosely speaking, these are the types T that appear in the +interface definition in terms of the form T, ~T, +or in unions of such terms. +

+ +

+More precisely, for a given interface, the set of specific types is defined as follows: +

+ +
    +
  • The set of specific types of the empty interface is the empty set. +
  • + +
  • The set of specific types of a non-empty interface is the intersection + of the specific types of its interface elements. +
  • + +
  • The set of specific types of a method specification is the empty set. +
  • + +
  • The set of specific types of a non-interface type term T + or ~T is the set consisting of the type T. +
  • + +
  • The set of specific types of a union of terms + t1|t2|…|tn + is the union of the specific types of the terms. +
  • +
+ +

+If the set of specific types is empty, the interface has no specific types. +

+ +

+Examples of interfaces with their specific types: +

+ +
+type Celsius float32
+type Kelvin  float32
+
+interface{}                    // no specific types
+interface{ int }               // int
+interface{ ~string }           // string
+interface{ int|~string }       // int, string
+interface{ Celsius|Kelvin }    // Celsius, Kelvin
+interface{ int; string }       // no specific types (intersection is empty)
+

An interface T is called structural if one of the following @@ -1966,9 +2019,6 @@ Examples of structural interfaces with their structural types:

-type Celsius float32
-type Kelvin  float32
-
 interface{ int }                          // int
 interface{ Celsius|Kelvin }               // float32
 interface{ ~chan int }                    // chan int