-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Description
~/go/src/github.com/dgryski/bug/aws $ tinygo run main.go
*main.Foo
0
*main.Foo
panic: runtime error at 0x000000010b195139: type assert failed
failed to run compiled binary /var/folders/5b/_hr1d1fd3qn4t9vtfx5p61wm0000gp/T/tinygo3370967634/main: signal: abort trap
~/go/src/github.com/dgryski/bug/aws $ cat main.go
package main
import (
"reflect"
)
func main() {
TestCopy1()
TestCopyIgnoreNilMembers()
}
func TestCopy1() {
type Foo struct {
A int
}
f1 := &Foo{}
fcopy := CopyOf(f1)
f2 := fcopy.(*Foo)
println(f2.A)
}
func TestCopyIgnoreNilMembers() {
type Foo struct {
A *int
}
f1 := &Foo{}
fcopy := CopyOf(f1)
f2 := fcopy.(*Foo) // BOOM -- checking that it's TestCopy1.Foo instead
println(f2.A)
}
func CopyOf(src interface{}) (dst interface{}) {
t := reflect.TypeOf(src)
println(t.String())
dsti := reflect.New(t.Elem())
dst = dsti.Interface()
return dst
}
Metadata
Metadata
Assignees
Labels
No labels