From 24898d6948e1651aab909a5abccbfde64dc359cd Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 18 Nov 2021 10:02:08 -0800 Subject: [PATCH] spec: various clarifications/fixes for method sets and interfaces - fixed a typo in the method set section - express in the syntax that ~T denotes an underlying type - be more precise when talking about types vs type terms - refer to "unions" rather than "union expressions" - make it clear in the spec title that this is WIP Change-Id: I9b2c4b1f77bc50dd574ed6893bedd40529c320fc Reviewed-on: https://go-review.googlesource.com/c/go/+/365154 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 63bc6a546ed..7c53a1eb91c 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,16 +1,14 @@ -

Draft Go 1.18 Specification - Work in Progress

+

Earlier version

- -For the pre-Go1.18 spec see +For the pre-Go1.18 specification without generics support see The Go Programming Language Specification. -

Introduction

@@ -852,7 +850,7 @@ Every type has a (possibly empty) method set associated with it:
  • The method set of a pointer *T -to a defined type *T +to a defined type T (where T is neither a pointer nor an interface) is the set of all methods declared with receiver *T or T.
  • @@ -1271,7 +1269,8 @@ InterfaceElem = MethodElem | TypeElem . MethodElem = MethodName Signature . MethodName = identifier . TypeElem = TypeTerm { "|" TypeTerm } . -TypeTerm = [ "~" ] Type . +TypeTerm = Type | UnderlyingType . +UnderlyingType = "~" Type .

    @@ -1415,9 +1414,9 @@ type ReadCloser interface {

    -Finally, in their most general form, an interface element may be an arbitrary type -T, a type term of the form ~T, or a union of type terms -T1 | T2 | … Tn. +Finally, in their most general form, an interface element may also be an arbitrary type term +T, or a term of the form ~T specifying the underlying type T, +or a union of terms t1|t2|…|tn. Together with method specifications, these elements enable the precise definition of an interface's type set as follows:

    @@ -1434,7 +1433,7 @@ definition of an interface's type set as follows: whose method sets include that method. -
  • The type set of a non-interface type is the set consisting +
  • The type set of a non-interface type term is the set consisting of just that type.
  • @@ -1442,7 +1441,8 @@ definition of an interface's type set as follows: is the set of types whose underlying type is T. -
  • The type set of a union of terms T1 | T2 | … Tn +
  • The type set of a union of terms + t1|t2|…|tn is the union of the type sets of the terms.
  • @@ -1487,7 +1487,7 @@ interface {

    -Union expressions denote unions of type sets: +Union elements denote unions of type sets:

    @@ -1500,7 +1500,7 @@ type Floats interface {
     

    -In a union expression, a term cannot be a type parameter, and the type sets of all +In a union, a term cannot be a type parameter, and the type sets of all non-interface terms must be pairwise disjoint (the pairwise intersection of the type sets must be empty). Given a type parameter P:

    @@ -1516,14 +1516,15 @@ interface {

    Implementation restriction: -A union expression with more than one term cannot contain interface types +A union with more than one term cannot contain interface types with non-empty method sets.

    -Interfaces that contain union or tilde terms (not just methods) may only be used -as type constraints, or as elements of other interfaces used as constraints. They -cannot be the types of values or variables, or components of other, non-interface types. +Interfaces that contain non-interface types, terms of the form ~T, +or unions may only be used as type constraints, or as elements of other interfaces used +as constraints. They cannot be the types of values or variables, or components of other, +non-interface types.