Standard library / go/token

go/token.File.AddLineInfo()

Registers alternative filename and line with column 1; retained for compatibility. Expected stdout: 'virtual.go:20:1\n'.

Formal Syntax & Structure

go syntaxgo
func (f *File) AddLineInfo(offset int, filename string, line int)

Parameters & Attributes

NameTypeDescription
offsetintZero-based byte offset within the source file.
filenamestringSource filename used in diagnostics.
lineintOne-based source line number.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/token")
func main() {  s := token.NewFileSet()  f := s.AddFile("demo.go", -1, 5)  f.AddLineInfo(1, "virtual.go", 20)  fmt.Println(f.Position(f.Pos(1)))}
Go Reference