Skip to content

Maps and init function not playing nice #545

@trivigy

Description

@trivigy

To reproduce simply try to compile the following code:

package main

var test map[string]int

func init() {
	test = make(map[string]int)
	for i := 0; i < 10; i++ {
		test[""] = i
	}
}

func main() {
}

I get the following compilation error:

panic: interface conversion: interp.Value is *interp.LocalValue, not *interp.MapValue

goroutine 1 [running]:
github.com/tinygo-org/tinygo/interp.(*frame).evalBasicBlock(0xc00067a7e8, 0x7f2e18290e40, 0x7f2e18290dc0, 0x34a3f12, 0x4, 0x0, 0x0, 0xc0001a44e8, 0x1, 0x1, ...)
        /home/circleci/project/interp/frame.go:279 +0x92c9
github.com/tinygo-org/tinygo/interp.(*Eval).function(0xc000432120, 0x7f2e1801f8d8, 0xc0001ae760, 0x2, 0x2, 0xc0006ec660, 0xd, 0x34a3f12, 0x4, 0x0, ...)
        /home/circleci/project/interp/interp.go:104 +0x208
github.com/tinygo-org/tinygo/interp.(*frame).evalBasicBlock(0xc00067b310, 0x7f2e18290420, 0x0, 0x0, 0x0, 0xc0182ba918, 0x10, 0x10, 0xc000395d60, 0xa6f821, ...)
        /home/circleci/project/interp/frame.go:449 +0x515a
github.com/tinygo-org/tinygo/interp.(*Eval).function(0xc000432120, 0x7f2e1801f7e8, 0xc00067b450, 0x2, 0x2, 0xc0006ec660, 0xd, 0x0, 0x0, 0x0, ...)
        /home/circleci/project/interp/interp.go:104 +0x208
github.com/tinygo-org/tinygo/interp.(*Eval).Function(...)
        /home/circleci/project/interp/interp.go:87
github.com/tinygo-org/tinygo/interp.Run(0x4c95310, 0x4c8dff0, 0x0, 0x0, 0x0)
        /home/circleci/project/interp/interp.go:74 +0x681
main.Compile(0x7ffe2d091ae5, 0xd, 0x7ffe2d091ac7, 0x10, 0xc000164180, 0xc00067bee0, 0xc00067bd48, 0x0, 0x0)
        /home/circleci/project/main.go:140 +0xc55
main.Build(0x7ffe2d091ae5, 0xd, 0x7ffe2d091ac7, 0x10, 0x7ffe2d091ae0, 0x4, 0xc0000bfee0, 0xc000116260, 0x7f2e2ae7d1b8)
        /home/circleci/project/main.go:337 +0xe2
main.main()
        /home/circleci/project/main.go:696 +0xefd

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