Standard library / go/scanner

go/scanner.ErrorList.RemoveMultiples()

Sorts diagnostics and retains only the first per filename and line. Expected stdout: '2 first\n'.

Formal Syntax & Structure

go syntaxgo
func (p *ErrorList) RemoveMultiples()

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.Add(token.Position{Filename: "demo.go", Line: 1, Column: 3}, "another")  es.RemoveMultiples()  fmt.Println(es.Len(), es[0].Msg)}
Go Reference