Commit e4259d67 authored by Robert Griesemer's avatar Robert Griesemer

go/types: report object path in trace mode

For debugging only; disabled (dead code) by default
unless internal constant trace flag is set to true.

For #8699.

Change-Id: Ib7b272c6ac8efacccbbbe24650ef500c5a9ddcf5
Reviewed-on: https://go-review.googlesource.com/115457Reviewed-by: default avatarAlan Donovan <adonovan@google.com>
parent 6dbaf035
...@@ -160,6 +160,18 @@ func (check *Checker) pop() Object { ...@@ -160,6 +160,18 @@ func (check *Checker) pop() Object {
return obj return obj
} }
// pathString returns a string of the form a->b-> ... ->g for an object path [a, b, ... g].
func (check *Checker) pathString() string {
var s string
for i, p := range check.objPath {
if i > 0 {
s += "->"
}
s += p.Name()
}
return s
}
// NewChecker returns a new Checker instance for a given package. // NewChecker returns a new Checker instance for a given package.
// Package files may be added incrementally via checker.Files. // Package files may be added incrementally via checker.Files.
func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Checker { func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Checker {
......
...@@ -158,7 +158,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) { ...@@ -158,7 +158,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
} }
if trace { if trace {
check.trace(obj.Pos(), "-- checking %s (path = %s)", obj, pathString(path)) check.trace(obj.Pos(), "-- checking %s (path = %s, objPath = %s)", obj, pathString(path), check.pathString())
check.indent++ check.indent++
defer func() { defer func() {
check.indent-- check.indent--
...@@ -208,7 +208,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) { ...@@ -208,7 +208,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
// to the next. For instance, for "type p *p" the object path contains // to the next. For instance, for "type p *p" the object path contains
// p followed by indir, indicating that there's an indirection *p. // p followed by indir, indicating that there's an indirection *p.
// Indirections are used to break type cycles. // Indirections are used to break type cycles.
var indir = new(TypeName) var indir = NewTypeName(token.NoPos, nil, "*", nil)
// typeCycle checks if the cycle starting with obj is valid and // typeCycle checks if the cycle starting with obj is valid and
// reports an error if it is not. // reports an error if it is not.
......
...@@ -144,7 +144,7 @@ func (check *Checker) infoFromTypeLit(scope *Scope, iface *ast.InterfaceType, tn ...@@ -144,7 +144,7 @@ func (check *Checker) infoFromTypeLit(scope *Scope, iface *ast.InterfaceType, tn
} }
if trace { if trace {
check.trace(iface.Pos(), "-- collect methods for %v (path = %s)", iface, pathString(path)) check.trace(iface.Pos(), "-- collect methods for %v (path = %s, objPath = %s)", iface, pathString(path), check.pathString())
check.indent++ check.indent++
defer func() { defer func() {
check.indent-- check.indent--
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment