Skip to content

SetField doesn't appear to work #13

@eric-s-raymond

Description

@eric-s-raymond

I get the following trace:

`
--- FAIL: TestGetSetAttr (0.00s)
panic: reflect: call of reflect.Value.Elem on struct Value [recovered]
panic: reflect: call of reflect.Value.Elem on struct Value

goroutine 38 [running]:
testing.tRunner.func1(0xc4202544b0)
/usr/lib/go-1.10/src/testing/testing.go:742 +0x29d
panic(0x5d92e0, 0xc4201e9760)
/usr/lib/go-1.10/src/runtime/panic.go:502 +0x229
reflect.Value.Elem(0x5ef860, 0xc4202159e0, 0x99, 0xc4202159e0, 0x99, 0x20)
/usr/lib/go-1.10/src/reflect/value.go:775 +0x1b7
goreposurgeon.SetField(0x5ef860, 0xc4202159e0, 0x618dc0, 0x3, 0x5cb320, 0x64de00, 0x7, 0x61a0b5)
/home/esr/public_html/reposurgeon/src/goreposurgeon/goreposurgeon_test.go:1597 +0x6f
goreposurgeon.TestGetSetAttr(0xc4202544b0)
/home/esr/public_html/reposurgeon/src/goreposurgeon/goreposurgeon_test.go:1644 +0x1fa
testing.tRunner(0xc4202544b0, 0x632770)
/usr/lib/go-1.10/src/testing/testing.go:777 +0xd0
created by testing.(*T).Run
/usr/lib/go-1.10/src/testing/testing.go:824 +0x2e0
FAIL goreposurgeon 0.017s
`

That appears to relate to this line: structValue := reflect.ValueOf(obj).Elem()

If I remove the Elem() call, the function runs to completion but silently fails. e.g the field is not set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions