From f84e8b3f0373c97ce6fd7e98971110f63604d797 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 29 Apr 2014 19:58:47 -0700 Subject: [PATCH] go.tools/cmd/godex: print correct type for const/var decls The old code printed the underlying type; e.g., the type of time.Millisecond was reported to be int64 rather than time.Duration. Testsuite (and corresponding tests) in progress (another CL). LGTM=adonovan R=adonovan, dsymonds CC=golang-codereviews https://golang.org/cl/94770045 --- cmd/godex/print.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/godex/print.go b/cmd/godex/print.go index e02f5e20..e8b87c5f 100644 --- a/cmd/godex/print.go +++ b/cmd/godex/print.go @@ -310,13 +310,15 @@ func valString(v exact.Value, floatFmt bool) string { func (p *printer) printObj(obj types.Object) { p.print(obj.Name()) - // don't write untyped types (for constants) + typ, basic := obj.Type().Underlying().(*types.Basic) - if basic && typ.Info()&types.IsUntyped == 0 { + if basic && typ.Info()&types.IsUntyped != 0 { + // don't write untyped types + } else { p.print(" ") - p.writeType(p.pkg, typ) + p.writeType(p.pkg, obj.Type()) } - // write constant value + if obj, ok := obj.(*types.Const); ok { floatFmt := basic && typ.Info()&(types.IsFloat|types.IsComplex) != 0 p.print(" = ")