Skip to content

proposal: go/types: publish Error.{Start,End} fields #71803

@adonovan

Description

@adonovan

Background: Since go1.16 (#42290), go/types has internally recorded three positions (start, pos, and end) for type errors. However, only the Pos field is exposed. The x/tools repo has long resorted to unsavory hacks such as reading the non-exported fields, and using heuristics on the source text (!) to guess the end position.

Proposal: We propose to publish the Start and End fields.

package types

type Error struct {
	Fset       *token.FileSet // file set for interpretation of Pos
	// Invariant: Start <= Pos < End || Start == Pos == End.
	Pos        token.Pos      // error position
+	Start, End token.Pos 	  // start, end of containing expression
	Msg        string         // error message
	Soft       bool           // if set, error is "soft"
}

@gri @findleyr

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions