From 033cbfc76dfa25372f183e2f55365d274e77adef Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Tue, 10 May 2022 22:18:32 -0400 Subject: [PATCH] internal/typeparams: run go generate with go1.18.2 And fix a minor issue in copytermlist.go -- copytermlist.go replaces type names from go/types with qualified type names. Use of token.NoPos (filled with ast.NewIdent) however confuses the go/format printer. As a result, while transforming func (x *term) includes(t Type) bool to func (x *term) includes(t types.Type) bool go/format printer failed to compute the end position of the parameter list, concluded RPAREN should be in a different line from the parameter list, added a comma, and printed func (x *term) includes(t types.Type,) bool Reuse the replaced node's position instead. (not 100% correct, but better than NoPos) Change-Id: Ia34e11562cc80c68dcf4b921ffffd926971c2215 Reviewed-on: https://go-review.googlesource.com/c/tools/+/405536 Reviewed-by: Hyang-Ah Hana Kim Reviewed-by: Robert Findley --- internal/typeparams/copytermlist.go | 6 +++--- internal/typeparams/termlist.go | 9 --------- internal/typeparams/typeterm.go | 9 +++++---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/internal/typeparams/copytermlist.go b/internal/typeparams/copytermlist.go index b8f458ac3b..5357f9d2fd 100644 --- a/internal/typeparams/copytermlist.go +++ b/internal/typeparams/copytermlist.go @@ -42,7 +42,7 @@ func doCopy() error { return err } file.Name.Name = "typeparams" - file.Doc = &ast.CommentGroup{List: []*ast.Comment{&ast.Comment{Text: "DO NOT MODIFY"}}} + file.Doc = &ast.CommentGroup{List: []*ast.Comment{{Text: "DO NOT MODIFY"}}} var needImport bool selectorType := reflect.TypeOf((*ast.SelectorExpr)(nil)) astutil.Apply(file, func(c *astutil.Cursor) bool { @@ -70,8 +70,8 @@ func doCopy() error { } needImport = true c.Replace(&ast.SelectorExpr{ - X: ast.NewIdent("types"), - Sel: ast.NewIdent(id.Name), + X: &ast.Ident{NamePos: id.NamePos, Name: "types"}, + Sel: &ast.Ident{NamePos: id.NamePos, Name: id.Name, Obj: id.Obj}, }) } return true diff --git a/internal/typeparams/termlist.go b/internal/typeparams/termlist.go index 10857d504c..933106a23d 100644 --- a/internal/typeparams/termlist.go +++ b/internal/typeparams/termlist.go @@ -97,15 +97,6 @@ func (xl termlist) norm() termlist { return rl } -// If the type set represented by xl is specified by a single (non-𝓤) term, -// structuralType returns that type. Otherwise it returns nil. -func (xl termlist) structuralType() types.Type { - if nl := xl.norm(); len(nl) == 1 { - return nl[0].typ // if nl.isAll() then typ is nil, which is ok - } - return nil -} - // union returns the union xl ∪ yl. func (xl termlist) union(yl termlist) termlist { return append(xl, yl...).norm() diff --git a/internal/typeparams/typeterm.go b/internal/typeparams/typeterm.go index 7350bb702a..7ddee28d98 100644 --- a/internal/typeparams/typeterm.go +++ b/internal/typeparams/typeterm.go @@ -10,10 +10,11 @@ import "go/types" // A term describes elementary type sets: // -// ∅: (*term)(nil) == ∅ // set of no types (empty set) -// 𝓤: &term{} == 𝓤 // set of all types (𝓤niverse) -// T: &term{false, T} == {T} // set of type T -// ~t: &term{true, t} == {t' | under(t') == t} // set of types with underlying type t +// ∅: (*term)(nil) == ∅ // set of no types (empty set) +// 𝓤: &term{} == 𝓤 // set of all types (𝓤niverse) +// T: &term{false, T} == {T} // set of type T +// ~t: &term{true, t} == {t' | under(t') == t} // set of types with underlying type t +// type term struct { tilde bool // valid if typ != nil typ types.Type