Standard library / go/types
go/types.Scope.Insert()
Adds an object if its name is not already present; returns an existing object on collision. Expected stdout: 'true true\n'.
Formal Syntax & Structure
go syntaxgo
func (s *Scope) Insert(obj Object) ObjectParameters & Attributes
| Name | Type | Description |
|---|---|---|
| obj | Object | Object associated with the type or scope. |
Return Value
Object
Adds an object if its name is not already present; returns an existing object on collision.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { s := types.NewScope(nil, 1, 10, "demo") v := types.NewVar(2, nil, "x", types.Typ[types.Int]) fmt.Println(s.Insert(v) == nil, s.Insert(v) == v)}