MCPcopy
hub / github.com/tinygo-org/tinygo / testValueSetInterface

Function testValueSetInterface

testdata/reflect.go:773–794  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

771}
772
773func testValueSetInterface() {
774 c := &NodeContainer{
775 Nodes: []IfaceNode{&FooNode{V: 1}, &FooNode{V: 2}},
776 }
777
778 // Use reflect to replace elements
779 v := reflect.ValueOf(c).Elem().FieldByName("Nodes")
780 v.Index(0).Set(reflect.ValueOf(&BarNode{V: 10}))
781
782 switch n := c.Nodes[0].(type) {
783 case *BarNode:
784 println("Set[0] to BarNode:", n.V) // 10
785 default:
786 println("FAIL: expected *BarNode")
787 }
788 switch n := c.Nodes[1].(type) {
789 case *FooNode:
790 println("Set[1] still FooNode:", n.V) // 2
791 default:
792 println("FAIL: expected *FooNode")
793 }
794}
795
796var xorshift32State uint32 = 1
797

Callers 1

testImplementsFunction · 0.85

Calls 4

FieldByNameMethod · 0.65
ElemMethod · 0.65
SetMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected