Skip to content

Commit e4259d6

Browse files
committed
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/115457 Reviewed-by: Alan Donovan <adonovan@google.com>
1 parent 6dbaf03 commit e4259d6

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/go/types/check.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ func (check *Checker) pop() Object {
160160
return obj
161161
}
162162

163+
// pathString returns a string of the form a->b-> ... ->g for an object path [a, b, ... g].
164+
func (check *Checker) pathString() string {
165+
var s string
166+
for i, p := range check.objPath {
167+
if i > 0 {
168+
s += "->"
169+
}
170+
s += p.Name()
171+
}
172+
return s
173+
}
174+
163175
// NewChecker returns a new Checker instance for a given package.
164176
// Package files may be added incrementally via checker.Files.
165177
func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Checker {

src/go/types/decl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
158158
}
159159

160160
if trace {
161-
check.trace(obj.Pos(), "-- checking %s (path = %s)", obj, pathString(path))
161+
check.trace(obj.Pos(), "-- checking %s (path = %s, objPath = %s)", obj, pathString(path), check.pathString())
162162
check.indent++
163163
defer func() {
164164
check.indent--
@@ -208,7 +208,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
208208
// to the next. For instance, for "type p *p" the object path contains
209209
// p followed by indir, indicating that there's an indirection *p.
210210
// Indirections are used to break type cycles.
211-
var indir = new(TypeName)
211+
var indir = NewTypeName(token.NoPos, nil, "*", nil)
212212

213213
// typeCycle checks if the cycle starting with obj is valid and
214214
// reports an error if it is not.

src/go/types/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (check *Checker) infoFromTypeLit(scope *Scope, iface *ast.InterfaceType, tn
144144
}
145145

146146
if trace {
147-
check.trace(iface.Pos(), "-- collect methods for %v (path = %s)", iface, pathString(path))
147+
check.trace(iface.Pos(), "-- collect methods for %v (path = %s, objPath = %s)", iface, pathString(path), check.pathString())
148148
check.indent++
149149
defer func() {
150150
check.indent--

0 commit comments

Comments
 (0)