Skip to content

go/token: add (*File).String method #76285

@adonovan

Description

@adonovan

Proposal Details

Background: This behavior is not helpful:

	f := token.NewFileSet().AddFile("foo.go", -1, 0)
	fmt.Println(f) // "&{foo.go 1 0 {{} {0 0}} [0] []}"

Proposal: We propose to add this String method to token.File:

package token // "go/token"

// String returns a brief description of the file.
func (f *File) String() string {
        return fmt.Sprintf("%s(%d-%d)", f.Name(), f.Base(), f.End())
}

[Edited Nov 13 to return more than just the name.]

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Accepted

Relationships

None yet

Development

No branches or pull requests

Issue actions