Hello!

I keep getting:
panic: interface conversion: interface {} is *interface {}, not *int64
[recovered]
panic: interface conversion: interface {} is *interface {}, not *int64

I *suspect* what is happening is that the KDElem struct has an item field
whose
type is interface{}, so that you can store a pointer to some struct (of
your own making),
or an index into an array of structs, or... *whatever*, but in my case,
it's an index into an array
of objects. The itemfunc (or genBox in my test code) is supposed to set the
item field in
the KDElem struct to the proper index, as the struct has just been created,
and the job
of the itemfunc is to make it point to the right object, and set the bounds
info in the new struct.

type KdElem struct {
    item       interface{} // a ptr to a particular struct, or an index
into an array of objects, or....
    ...
}

And the func that calls the itemfunc (genBox) looks like this:

func loadItems(itemfunc func(arg interface{}, val interface{}, size *KdBox)
int, arg interface{}, extent KdBox, length *int64, mean *float64) *KdElem {
     ...
     newItem = new(KdElem)
     if itemfunc(arg, &newItem.item, newItem.size) != 0 {
     ...


And, in this case the itemfunc declaration looks like this:

func genBox(arg interface{}, val interface{}, box *KdBox) int {
     var offsetp = arg.(*int64)         // successful
     var offset = *offsetp                 // successful
     // fmt.Printf("genBox: offset=%v offsetp=%v\n", offset, offsetp)
     fmt.Printf("genBox: arg type=%T argval=%v,     val type=%T, val
val=%v\n", arg, arg, val, val)
     if offset < KDBoxes {
          fmt.Printf("genBox: val=%v  *int64=%v\n", val, val)
          var realval *int64 = val.(*int64)     //  <<-- This is line 43!
Compiles.... but... Crash!!!
          *realval = offset + 1
...

Now, I get this from a go test:

KdBuild: arg type=*int64  argval=0xc0000d2078;
genBox: arg type=*int64 argval=0xc0000d2078,     val type=*interface {},
val val=0xc0000ba640
genBox: val=0xc0000ba640  *int64=0xc0000ba640
--- FAIL: TestKd1 (0.08s)
panic: interface conversion: interface {} is *interface {}, not *int64
[recovered]
panic: interface conversion: interface {} is *interface {}, not *int64

goroutine 19 [running]:
testing.tRunner.func1(0xc000108100)
/usr/lib/go-1.13/src/testing/testing.go:874 +0x3a3
panic(0x523360, 0xc0000c2360)
/usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2
parsetree.com/kdtree.genBox(0x50eec0, 0xc0000d2078, 0x50ef40, 0xc0000ba640,
0x0, 0x0)
/home/murf/go/kdtree/kdtree1_test.go:43 +0x270
parsetree.com/kdtree.loadItems(0x5570f8, 0x50eec0, 0xc0000d2078,
0x7fffffffffffffff, 0x7fffffffffffffff, 0x8000000000000000,
0x8000000000000000, 0xc00096ab38, 0xc00096ab30, 0x0)
/home/murf/go/kdtree/kdtree.go:683 +0xec
parsetree.com/kdtree.KdBuild(0x5570f8, 0x50eec0, 0xc0000d2078, 0x0)
/home/murf/go/kdtree/kdtree.go:168 +0x17e
parsetree.com/kdtree.TestKd1(0xc000108100)
/home/murf/go/kdtree/kdtree1_test.go:72 +0x13a
testing.tRunner(0xc000108100, 0x5570f0)
/usr/lib/go-1.13/src/testing/testing.go:909 +0

How do I set realval to the (*int64) value that's in val?

murf

-- 

Steve Murphy
ParseTree Corporation
57 Lane 17
Cody, WY 82414
✉  murf at parsetree dot com
☎ 307-899-0510

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAPPCp8HGQAcdw7J_vFLW8NKsXqfh5kgUtCrQn41dBLRamQggNA%40mail.gmail.com.

Reply via email to