From 9657e0b0777f3af3b48908cc39e5ab6d06022422 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 24 Jan 2017 14:53:31 -0500 Subject: [PATCH] [dev.typealias] cmd/doc: update for type alias For #18130. Change-Id: I06b05a2b45a2aa6764053fc51e05883063572dad Reviewed-on: https://go-review.googlesource.com/35670 Run-TryBot: Russ Cox Reviewed-by: Robert Griesemer --- src/cmd/doc/doc_test.go | 14 ++++++++++++++ src/cmd/doc/pkg.go | 6 +++++- src/cmd/doc/testdata/pkg.go | 4 ++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cmd/doc/doc_test.go b/src/cmd/doc/doc_test.go index 1c054fd566..1244476ab2 100644 --- a/src/cmd/doc/doc_test.go +++ b/src/cmd/doc/doc_test.go @@ -71,6 +71,7 @@ var tests = []test{ `const MultiLineConst = ...`, // Multi line constant. `var MultiLineVar = map\[struct{ ... }\]struct{ ... }{ ... }`, // Multi line variable. `func MultiLineFunc\(x interface{ ... }\) \(r struct{ ... }\)`, // Multi line function. + `type T1 = T2`, // Type alias }, []string{ `const internalConstant = 2`, // No internal constants. @@ -89,6 +90,7 @@ var tests = []test{ `unexportedTypedConstant`, // No unexported typed constant. `Field`, // No fields. `Method`, // No methods. + `type T1 T2`, // Type alias does not display as type declaration. }, }, // Package dump -u @@ -265,6 +267,18 @@ var tests = []test{ `error`, // No embedded error. }, }, + // Type T1 dump (alias). + { + "type T1", + []string{p+".T1"}, + []string{ + `type T1 = T2`, + }, + []string{ + `type T1 T2`, + `type ExportedType`, + }, + }, // Type -u with unexported fields. { "type with unexported fields and -u", diff --git a/src/cmd/doc/pkg.go b/src/cmd/doc/pkg.go index daa6ed358c..32d08f21fd 100644 --- a/src/cmd/doc/pkg.go +++ b/src/cmd/doc/pkg.go @@ -258,7 +258,11 @@ func (pkg *Package) oneLineNodeDepth(node ast.Node, depth int) string { return fmt.Sprintf("func %s%s%s", recv, name, fnc) case *ast.TypeSpec: - return fmt.Sprintf("type %s %s", n.Name.Name, pkg.oneLineNodeDepth(n.Type, depth)) + sep := " " + if n.Assign.IsValid() { + sep = " = " + } + return fmt.Sprintf("type %s%s%s", n.Name.Name, sep, pkg.oneLineNodeDepth(n.Type, depth)) case *ast.FuncType: var params []string diff --git a/src/cmd/doc/testdata/pkg.go b/src/cmd/doc/testdata/pkg.go index 924daa171b..0ebea67d58 100644 --- a/src/cmd/doc/testdata/pkg.go +++ b/src/cmd/doc/testdata/pkg.go @@ -172,3 +172,7 @@ const ( ) const ConstGroup4 ExportedType = ExportedType{} + +type T2 int + +type T1 = T2