Standard library / go/types

go/types.Scope.WriteTo()

Writes debug text with sorted declarations; recurse includes child scopes. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
func (s *Scope) WriteTo(w io.Writer, n int, recurse bool)

Parameters & Attributes

NameTypeDescription
wio.WriterInput to the operation as described above.
nintInput to the operation as described above.
recurseboolInput to the operation as described above.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "go/types"  "strings")
func scope() *types.Scope {  s := types.NewScope(nil, 10, 100, "outer")  types.NewScope(s, 20, 40, "inner")  s.Insert(types.NewVar(11, nil, "X", types.Typ[types.Int]))  return s}
func main() {  s := scope()  var b bytes.Buffer  s.WriteTo(&b, 0, true)  fmt.Println(strings.Contains(b.String(), "X"), strings.Contains(b.String(), "inner"))}
Go Reference