In [ ]:
type Data struct {
value string
}
func (d Data) Value() string {
return d.value
}
type WithValue interface {
Value() string
}
In [ ]:
d := Data{"hello"}
In [3]:
// Got a link error because of https://github.com/golang/go/issues/22998
d.Value()
In [ ]:
// This works without any problem.
WithValue(d).Value()
In [ ]:
import (
"fmt"
)
i := 0
go func() {
defer func() {
fmt.Println("Canceled")
}()
for i = 0;; i++ {}
}()
In [ ]:
import (
"fmt"
"time"
)
go func() {
panic("die!")
}()
time.Sleep(100 * time.Millisecond)
fmt.Println("main done")
If you invoke a method through an interface in lgo, it crashes with runtime error: invalid memory address or nil pointer dereference (bug).
In [ ]:
import (
"fmt"
)
type Hello interface {
SayHello()
}
type person struct {
name string
}
func (p *person) SayHello() {
fmt.Printf("Hello, I'm %s.\n", p.name)
}
p := person{"yunabe"}
fmt.Println("---- 1 ----")
p.SayHello()
var h Hello = &p
fmt.Println("---- 2 ----")
h.SayHello()
The following crashes with fatal error: found bad pointer in Go heap (incorrect use of unsafe or cgo?) message (bug).
In [ ]:
import (
"fmt"
"log"
"runtime"
"runtime/debug"
)
type MyData struct {
b []byte
}
func (m *MyData) Size() int {
return len(m.b)
}
func NewMyData() *MyData {
return &MyData{
b: make([]byte, 10 * (1 << 20)),
}
}
var l []*MyData
for i := 0; i < 100; i++ {
d := NewMyData()
l = append(l, d)
}
l = nil
debug.FreeOSMemory()
runtime.GC()
The following code must output goroutine: 0, goroutine: 1 and goroutine: 2 in a random order.
But lgo shows goroutine: 3 three times (bug).
In [ ]:
import (
"fmt"
)
for i := 0; i < 3; i++ {
go func(id int) {
fmt.Println("goroutine:", id)
}(i)
}