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
| Name | Type | Description |
|---|---|---|
| offset | int | Zero-based byte offset within the source file. |
| filename | string | Source filename used in diagnostics. |
| line | int | One-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)))}