You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TinyGo incorrectly panics on a nil pointer dereference when accessing a struct field from a map lookup, while standard Go handles the same code without errors. This inconsistency suggests that TinyGo does not optimize nil pointer access in maps the same way as the Go compiler does.
$ cat test.go
package main
import "fmt"type thing struct {
field int
}
func main() {
m := map[string]*thing{}
t, ok := m["abc"]
valid := t.field >= 0
if!ok ||!valid {
fmt.Printf("got: %v\n", t)
t = &thing{field: 0}
m["abc"] = t
}
t.field += 3
fmt.Println(t.field)
}
$ go version
go version go1.24.1 linux/amd64
$ go run test.go
got: <nil>
3
$ tinygo version
tinygo version 0.36.0 linux/amd64 (using go version go1.24.1 and LLVM version 19.1.2)
$ tinygo run test.go
panic: runtime error at 0x000000000021261d: nil pointer dereference
[tinygo: panic at /usr/local/lib/tinygo/src/runtime/scheduler_cooperative.go]
failed to run compiled binary /tmp/tinygo4289749700/main: signal: aborted
The text was updated successfully, but these errors were encountered:
TinyGo incorrectly panics on a nil pointer dereference when accessing a struct field from a map lookup, while standard Go handles the same code without errors. This inconsistency suggests that TinyGo does not optimize nil pointer access in maps the same way as the Go compiler does.
The text was updated successfully, but these errors were encountered: