]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: report object path in trace mode
authorRobert Griesemer <gri@golang.org>
Thu, 31 May 2018 01:13:27 +0000 (18:13 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 31 May 2018 18:22:35 +0000 (18:22 +0000)
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>
src/go/types/check.go
src/go/types/decl.go
src/go/types/interfaces.go

index 1d75ab1fc73c4ff19eb5e7946b9af8fa444f43a8..286b1f36a95784338a1b30b72629d2d01bed98eb 100644 (file)
@@ -160,6 +160,18 @@ func (check *Checker) pop() Object {
        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.
 // Package files may be added incrementally via checker.Files.
 func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Checker {
index b1543e8a1121519d7ffab041a9675fb51c08e9ec..9a27fbbed6f0ce7016712ad12d2e72b37545e5db 100644 (file)
@@ -158,7 +158,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
        }
 
        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++
                defer func() {
                        check.indent--
@@ -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
 // p followed by indir, indicating that there's an indirection *p.
 // 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
 // reports an error if it is not.
index b4efebae5d059133d7bf6c2f07048be46d6baa42..e4b42dc5a36b9cecf55fbba727a167ed9dc99e45 100644 (file)
@@ -144,7 +144,7 @@ func (check *Checker) infoFromTypeLit(scope *Scope, iface *ast.InterfaceType, tn
        }
 
        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++
                defer func() {
                        check.indent--