Skip to content

Maps and init function not playing nice: Redux #1307

@ribasushi

Description

@ribasushi

TLDR
The problem described in #545 appears to have not been fully fixed.

Version
tinygo version 0.14.0 darwin/amd64 (using go version go1.14.7 and LLVM version 10.0.0)

Failure

~$ tinygo run tiny.go 
panic: interp: load from a bitcast

goroutine 1 [running]:
github.com/tinygo-org/tinygo/interp.(*LocalValue).Load(0xc0057c6480, 0xc0057c6480)
        /Users/admin/devel/tinygo/interp/values.go:61 +0x220
github.com/tinygo-org/tinygo/interp.(*LocalValue).Load(0xc0057c6470, 0x1d)
        /Users/admin/devel/tinygo/interp/values.go:58 +0x12f
github.com/tinygo-org/tinygo/interp.(*frame).evalBasicBlock(0xc003605730, 0x37fb72a0, 0x37fb6f50, 0xc0057b65b8, 0x8, 0x0, 0x0, 0xc0057ac860, 0x1, 0x1, ...)
        /Users/admin/devel/tinygo/interp/frame.go:98 +0xd684
github.com/tinygo-org/tinygo/interp.(*evalPackage).function(0xc0036074c0, 0xb422508, 0xc00467d200, 0x6, 0x8, 0xc0057b65b8, 0x8, 0x8, 0xc00573deb0, 0x0)
        /Users/admin/devel/tinygo/interp/interp.go:113 +0x238
github.com/tinygo-org/tinygo/interp.(*frame).evalBasicBlock(0xc0036064f0, 0x388f8750, 0x388f8640, 0x44be553, 0x4, 0x0, 0x0, 0xc0057ac750, 0x1, 0x1, ...)
        /Users/admin/devel/tinygo/interp/frame.go:570 +0x6463
github.com/tinygo-org/tinygo/interp.(*evalPackage).function(0xc0036074c0, 0xb41ea98, 0xc0021c8020, 0x2, 0x2, 0x44be553, 0x4, 0x2, 0xc0057b2fb0, 0x0)
        /Users/admin/devel/tinygo/interp/interp.go:113 +0x238
github.com/tinygo-org/tinygo/interp.(*frame).evalBasicBlock(0xc0036072b0, 0x388f7380, 0x388f6170, 0x0, 0x0, 0x0, 0x0, 0xc0057ac678, 0x1, 0x1, ...)
        /Users/admin/devel/tinygo/interp/frame.go:570 +0x6463
github.com/tinygo-org/tinygo/interp.(*evalPackage).function(0xc0036074c0, 0xb41e9b8, 0xc0036074d8, 0x2, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0)
        /Users/admin/devel/tinygo/interp/interp.go:113 +0x238
github.com/tinygo-org/tinygo/interp.Run(0xb2113a0, 0x0, 0x0, 0x0)
        /Users/admin/devel/tinygo/interp/interp.go:85 +0x7fe
github.com/tinygo-org/tinygo/builder.Build(0x7ffeefbff93b, 0x7, 0x44be5ff, 0x4, 0xc000270c00, 0xc003607c80, 0x0, 0x0)
        /Users/admin/devel/tinygo/builder/build.go:51 +0x20d
main.Run(0x7ffeefbff93b, 0x7, 0xc00020a0e0, 0xe, 0x0)
        /Users/admin/devel/tinygo/main.go:442 +0xaf
main.main()
        /Users/admin/devel/tinygo/main.go:944 +0x105a```

Expectation

~$ go run tiny.go 
name1341341341

Testcase

package main

import "fmt"

type thingDef struct {
	label string
	thing []byte
}

var veryLongListOfAvailableThings = map[string]thingDef{
	"name1":          {},
	"name2":          {},
	"name1341341341": {},
}

func init() {
	for k, v := range veryLongListOfAvailableThings {
		v.label = k
		veryLongListOfAvailableThings[k] = v
	}
}

func main() {
	fmt.Println(veryLongListOfAvailableThings["name1341341341"].label)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions