mirror of
https://github.com/golang/go
synced 2024-11-19 01:54:39 -07:00
go.tools/go/types: use package-local type names in errors referring to operands
LGTM=adonovan R=adonovan CC=golang-codereviews https://golang.org/cl/77670043
This commit is contained in:
parent
62216e60bb
commit
6256e2d81b
@ -30,6 +30,8 @@ func (check *checker) sprintf(format string, args ...interface{}) string {
|
||||
arg = "<nil>"
|
||||
case operand:
|
||||
panic("internal error: should always pass *operand")
|
||||
case *operand:
|
||||
arg = operandString(check.pkg, a)
|
||||
case token.Pos:
|
||||
arg = check.fset.Position(a).String()
|
||||
case ast.Expr:
|
||||
|
@ -94,7 +94,7 @@ func (x *operand) pos() token.Pos {
|
||||
// commaok <expr> (<untyped kind> <mode> )
|
||||
// commaok <expr> ( <mode> of type <typ>)
|
||||
//
|
||||
func (x *operand) String() string {
|
||||
func operandString(this *Package, x *operand) string {
|
||||
var buf bytes.Buffer
|
||||
|
||||
var expr string
|
||||
@ -105,7 +105,7 @@ func (x *operand) String() string {
|
||||
case builtin:
|
||||
expr = predeclaredFuncs[x.id].name
|
||||
case typexpr:
|
||||
expr = TypeString(nil, x.typ)
|
||||
expr = TypeString(this, x.typ)
|
||||
case constant:
|
||||
expr = x.val.String()
|
||||
}
|
||||
@ -147,7 +147,7 @@ func (x *operand) String() string {
|
||||
if hasType {
|
||||
if x.typ != Typ[Invalid] {
|
||||
buf.WriteString(" of type ")
|
||||
WriteType(&buf, nil, x.typ)
|
||||
WriteType(&buf, this, x.typ)
|
||||
} else {
|
||||
buf.WriteString(" with invalid type")
|
||||
}
|
||||
@ -161,6 +161,10 @@ func (x *operand) String() string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func (x *operand) String() string {
|
||||
return operandString(nil, x)
|
||||
}
|
||||
|
||||
// setConst sets x to the untyped constant for literal lit.
|
||||
func (x *operand) setConst(tok token.Token, lit string) {
|
||||
val := exact.MakeFromLiteral(lit, tok)
|
||||
|
6
go/types/testdata/errors.src
vendored
6
go/types/testdata/errors.src
vendored
@ -48,4 +48,8 @@ func _() {
|
||||
// Add more tests as needed.
|
||||
func _() {
|
||||
if err := foo /* ERROR undeclared */ (); err != nil /* no error here */ {}
|
||||
}
|
||||
}
|
||||
|
||||
// Use unqualified names for package-local objects.
|
||||
type T struct{}
|
||||
var _ int = T /* ERROR value of type T */ {} // use T in error message rather then errors.T
|
||||
|
Loading…
Reference in New Issue
Block a user