Skip to content

go/ast: TypeSpec.Doc is nil? Have to grab documentation at GenDecl #27477

@xibz

Description

@xibz

What version of Go are you using (go version)?

1.11

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

darwin

Question

Noticed in the AST for type instantiated structures, that if I go to the Doc field in ast.TypeSpec the value is nil. I have to visit the ast.GenDecl node instead to grab doc fields.

Is this intended?
If so, why does ast.TypeSpec have a Doc field? Should Doc along with Comment be deprecated, as in mentioned in the docs, since comments/documentation really do not have anything to do with the type specification?

This can reproduce by parsing the code sample below

package foo

// documentation goes here
type Foo struct{}

func main() {
    f := Foo{}
}

expectation

ast.TypeSpec contain non-nil value for Doc when documentation is provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions