neugram / ng

scripting language integrated with Go
https://neugram.io
BSD 2-Clause "Simplified" License
917 stars 43 forks source link

Iterating maps panics #231

Closed vmarkovtsev closed 6 years ago

vmarkovtsev commented 6 years ago

The following code:

a := map[int]bool{1: true, 2: true}
for k := range a {
  print(k)
}

panics with

ng eval panic: reflect: call of reflect.Value.Set on zero Value
goroutine 1 [running]:
runtime/debug.Stack(0x40, 0x0, 0x0)
    /usr/lib/go-1.9/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
    /usr/lib/go-1.9/src/runtime/debug/stack.go:16 +0x22
neugram.io/ng/eval.(*Program).Eval.func1(0xc4200f8280, 0xc42011b610, 0xc42011b5f8)
    /home/vadim/Projects/go_unix/src/neugram.io/ng/eval/eval.go:476 +0x204
panic(0xbb0f60, 0xc42000c200)
    /usr/lib/go-1.9/src/runtime/panic.go:491 +0x283
reflect.flag.mustBeAssignable(0x0)
    /usr/lib/go-1.9/src/reflect/value.go:221 +0xe6
reflect.Value.Set(0x0, 0x0, 0x0, 0xb88720, 0xc420016220, 0x81)
    /usr/lib/go-1.9/src/reflect/value.go:1351 +0x2f
neugram.io/ng/eval.(*Program).evalStmt(0xc4200f8280, 0x115a540, 0xc42009c840, 0x0, 0x0, 0x0)
    /home/vadim/Projects/go_unix/src/neugram.io/ng/eval/eval.go:804 +0x508f
neugram.io/ng/eval.(*Program).Eval(0xc4200f8280, 0x115a540, 0xc42009c840, 0xc4201520c0, 0x0, 0x0, 0x0, 0x11535c0, 0xc420010170)
    /home/vadim/Projects/go_unix/src/neugram.io/ng/eval/eval.go:497 +0x38c
main.handleResult(0x1, 0xc420010160, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/vadim/Projects/go_unix/src/neugram.io/ng/ng.go:393 +0x7ff
main.loop(0xc400000000)
    /home/vadim/Projects/go_unix/src/neugram.io/ng/ng.go:385 +0x611
main.main()
    /home/vadim/Projects/go_unix/src/neugram.io/ng/ng.go:147 +0x641
ng: ng eval panic: reflect: call of reflect.Value.Set on zero Value

however, this code works:

a := map[int]bool{1: true, 2: true}
for k, _ := range a {
  print(k)
}