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
This commit is contained in:
Robert Griesemer 2014-04-29 19:58:47 -07:00
parent 55d5722095
commit f84e8b3f03
1 changed files with 6 additions and 4 deletions

View File

@ -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(" = ")