From 6713b5dbbc4b3bbfa2022538501c7f8104f1e5fd Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 18 Dec 2021 15:54:38 -0800 Subject: cmd/doc: don't log on constraint type elements Fixes #50256 Change-Id: I2327a0b28f8173c801ed2946bec8083967667027 Reviewed-on: https://go-review.googlesource.com/c/go/+/373314 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Robert Findley --- src/cmd/doc/pkg.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/cmd/doc/pkg.go') diff --git a/src/cmd/doc/pkg.go b/src/cmd/doc/pkg.go index f51efe08af..0266600730 100644 --- a/src/cmd/doc/pkg.go +++ b/src/cmd/doc/pkg.go @@ -865,6 +865,7 @@ func trimUnexportedFields(fields *ast.FieldList, isInterface bool) *ast.FieldLis if len(names) == 0 { // Embedded type. Use the name of the type. It must be of the form ident or // pkg.ident (for structs and interfaces), or *ident or *pkg.ident (structs only). + // Or a type embedded in a constraint. // Nothing else is allowed. ty := field.Type if se, ok := field.Type.(*ast.StarExpr); !isInterface && ok { @@ -872,6 +873,7 @@ func trimUnexportedFields(fields *ast.FieldList, isInterface bool) *ast.FieldLis // embedded types in structs. ty = se.X } + constraint := false switch ident := ty.(type) { case *ast.Ident: if isInterface && ident.Name == "error" && ident.Obj == nil { @@ -885,8 +887,12 @@ func trimUnexportedFields(fields *ast.FieldList, isInterface bool) *ast.FieldLis case *ast.SelectorExpr: // An embedded type may refer to a type in another package. names = []*ast.Ident{ident.Sel} + default: + // An approximation or union or type + // literal in an interface. + constraint = true } - if names == nil { + if names == nil && !constraint { // Can only happen if AST is incorrect. Safe to continue with a nil list. log.Print("invalid program: unexpected type for embedded field") } -- cgit v1.3