Standard library / go/scanner
go/scanner.ErrorList.Swap()
Exchanges two diagnostics by index. Expected stdout: 'first\n'.
Formal Syntax & Structure
go syntaxgo
func (p ErrorList) Swap(i, j int)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| i | int | Zero-based index among remaining positional arguments. |
| j | int | Input to the operation as described above. |
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.Swap(0, 1) fmt.Println(es[0].Msg)}