Standard library / go/scanner

go/scanner.ErrorList.Sort()

Sorts diagnostics by source position and message. Expected stdout: 'first second\n'.

Formal Syntax & Structure

go syntaxgo
func (p ErrorList) Sort()

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/scanner"  "go/token")
func main() {  var es scanner.ErrorList  es.Add(token.Position{Filename: "demo.go", Line: 2, Column: 1}, "second")  es.Add(token.Position{Filename: "demo.go", Line: 1, Column: 1}, "first")  es.Sort()  fmt.Println(es[0].Msg, es[1].Msg)}
Go Reference