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 <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Hana (Hyang-Ah) Kim 2022-05-10 22:18:32 -04:00 committed by Hyang-Ah Hana Kim
parent bc0e26ea12
commit 033cbfc76d
3 changed files with 8 additions and 16 deletions

View File

@ -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

View File

@ -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()

View File

@ -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