Standard library / go/scanner
go/scanner.ErrorList.Add()
Appends a diagnostic with position and message. Expected stdout: '2\n'.
Formal Syntax & Structure
go syntaxgo
func (p *ErrorList) Add(pos token.Position, msg string)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| pos | token.Position | Source position associated with the diagnostic. |
| msg | string | Diagnostic message. |
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") fmt.Println(es.Len())}