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

NameTypeDescription
postoken.PositionSource position associated with the diagnostic.
msgstringDiagnostic 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())}
Go Reference