mirror of
https://github.com/golang/go.git
synced 2025-05-31 23:25:39 +00:00
go/types: generate typeset.go from types2 source
To simplify the translation, use extra atPos calls where needed in the respective types2 source. This CL reduces the amount of code that needs to be maintained manually by about 420 LOC. Change-Id: I839844a6e85ccb1111d76c43de23127d8f9fbbce Reviewed-on: https://go-review.googlesource.com/c/go/+/567776 Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
13e5fd95f5
commit
691f5b8e74
@ -161,6 +161,10 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
|
||||
// set (and don't store it!), so that we still compute the full
|
||||
// type set eventually. Instead, return the top type set and
|
||||
// let any follow-on errors play out.
|
||||
//
|
||||
// TODO(gri) Consider recording when this happens and reporting
|
||||
// it as an error (but only if there were no other errors so to
|
||||
// to not have unnecessary follow-on errors).
|
||||
if !ityp.complete {
|
||||
return &topTypeSet
|
||||
}
|
||||
@ -222,8 +226,8 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
|
||||
case explicit:
|
||||
if check != nil {
|
||||
err := check.newError(DuplicateDecl)
|
||||
err.addf(pos, "duplicate method %s", m.name)
|
||||
err.addf(mpos[other.(*Func)], "other declaration of %s", m.name)
|
||||
err.addf(atPos(pos), "duplicate method %s", m.name)
|
||||
err.addf(atPos(mpos[other.(*Func)]), "other declaration of %s", m.name)
|
||||
err.report()
|
||||
}
|
||||
default:
|
||||
@ -234,13 +238,13 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
|
||||
// error message.
|
||||
if check != nil {
|
||||
check.later(func() {
|
||||
if !check.allowVersion(m.pkg, pos, go1_14) || !Identical(m.typ, other.Type()) {
|
||||
if !check.allowVersion(m.pkg, atPos(pos), go1_14) || !Identical(m.typ, other.Type()) {
|
||||
err := check.newError(DuplicateDecl)
|
||||
err.addf(pos, "duplicate method %s", m.name)
|
||||
err.addf(mpos[other.(*Func)], "other declaration of %s", m.name)
|
||||
err.addf(atPos(pos), "duplicate method %s", m.name)
|
||||
err.addf(atPos(mpos[other.(*Func)]), "other declaration of %s", m.name)
|
||||
err.report()
|
||||
}
|
||||
}).describef(pos, "duplicate method check for %s", m.name)
|
||||
}).describef(atPos(pos), "duplicate method check for %s", m.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -268,7 +272,7 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
|
||||
assert(!isTypeParam(typ))
|
||||
tset := computeInterfaceTypeSet(check, pos, u)
|
||||
// If typ is local, an error was already reported where typ is specified/defined.
|
||||
if check != nil && check.isImportedConstraint(typ) && !check.verifyVersionf(pos, go1_18, "embedding constraint interface %s", typ) {
|
||||
if check != nil && check.isImportedConstraint(typ) && !check.verifyVersionf(atPos(pos), go1_18, "embedding constraint interface %s", typ) {
|
||||
continue
|
||||
}
|
||||
comparable = tset.comparable
|
||||
@ -277,7 +281,7 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
|
||||
}
|
||||
terms = tset.terms
|
||||
case *Union:
|
||||
if check != nil && !check.verifyVersionf(pos, go1_18, "embedding interface element %s", u) {
|
||||
if check != nil && !check.verifyVersionf(atPos(pos), go1_18, "embedding interface element %s", u) {
|
||||
continue
|
||||
}
|
||||
tset := computeUnionTypeSet(check, unionSets, pos, u)
|
||||
@ -291,7 +295,7 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
|
||||
if !isValid(u) {
|
||||
continue
|
||||
}
|
||||
if check != nil && !check.verifyVersionf(pos, go1_18, "embedding non-interface type %s", typ) {
|
||||
if check != nil && !check.verifyVersionf(atPos(pos), go1_18, "embedding non-interface type %s", typ) {
|
||||
continue
|
||||
}
|
||||
terms = termlist{{false, typ}}
|
||||
@ -401,7 +405,7 @@ func computeUnionTypeSet(check *Checker, unionSets map[*Union]*_TypeSet, pos syn
|
||||
allTerms = allTerms.union(terms)
|
||||
if len(allTerms) > maxTermCount {
|
||||
if check != nil {
|
||||
check.errorf(pos, InvalidUnion, "cannot handle more than %d union terms (implementation limitation)", maxTermCount)
|
||||
check.errorf(atPos(pos), InvalidUnion, "cannot handle more than %d union terms (implementation limitation)", maxTermCount)
|
||||
}
|
||||
unionSets[utyp] = &invalidTypeSet
|
||||
return unionSets[utyp]
|
||||
|
@ -165,6 +165,7 @@ var filemap = map[string]action{
|
||||
"termlist_test.go": nil,
|
||||
"tuple.go": nil,
|
||||
"typelists.go": nil,
|
||||
"typeset.go": func(f *ast.File) { fixTokenPos(f); renameSelectors(f, "Trace->_Trace") },
|
||||
"typeparam.go": nil,
|
||||
"typeterm_test.go": nil,
|
||||
"typeterm.go": nil,
|
||||
|
@ -1,3 +1,5 @@
|
||||
// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
|
||||
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
@ -225,8 +227,10 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T
|
||||
mpos[m] = pos
|
||||
case explicit:
|
||||
if check != nil {
|
||||
check.errorf(atPos(pos), DuplicateDecl, "duplicate method %s", m.name)
|
||||
check.errorf(atPos(mpos[other.(*Func)]), DuplicateDecl, "\tother declaration of %s", m.name) // secondary error, \t indented
|
||||
err := check.newError(DuplicateDecl)
|
||||
err.addf(atPos(pos), "duplicate method %s", m.name)
|
||||
err.addf(atPos(mpos[other.(*Func)]), "other declaration of %s", m.name)
|
||||
err.report()
|
||||
}
|
||||
default:
|
||||
// We have a duplicate method name in an embedded (not explicitly declared) method.
|
||||
@ -237,8 +241,10 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T
|
||||
if check != nil {
|
||||
check.later(func() {
|
||||
if !check.allowVersion(m.pkg, atPos(pos), go1_14) || !Identical(m.typ, other.Type()) {
|
||||
check.errorf(atPos(pos), DuplicateDecl, "duplicate method %s", m.name)
|
||||
check.errorf(atPos(mpos[other.(*Func)]), DuplicateDecl, "\tother declaration of %s", m.name) // secondary error, \t indented
|
||||
err := check.newError(DuplicateDecl)
|
||||
err.addf(atPos(pos), "duplicate method %s", m.name)
|
||||
err.addf(atPos(mpos[other.(*Func)]), "other declaration of %s", m.name)
|
||||
err.report()
|
||||
}
|
||||
}).describef(atPos(pos), "duplicate method check for %s", m.name)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user