Standard library / go/types
go/types.Scope.Child()
Returns the child scope at the given zero-based index. Expected stdout: '20\n'.
Formal Syntax & Structure
go syntaxgo
func (s *Scope) Child(i int) *ScopeParameters & Attributes
| Name | Type | Description |
|---|---|---|
| i | int | Zero-based member index. |
Return Value
*Scope
Returns the child scope at the given zero-based index.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
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() { v := scope(); fmt.Println(v.Child(0).Pos()) }