fix: correct iterator in map range on binary values (#644)

* fix: correct iterator in map range on binary values

The map range iterator was not initialized correctly for values
originating from runtime.

Fixes #641.

* test: deterministic output for map28.go
This commit is contained in:
Marc Vertes
2020-05-20 21:37:48 +02:00
committed by GitHub
parent 4f8e1de267
commit 4f39eaf893
2 changed files with 23 additions and 0 deletions

21
_test/map28.go Normal file
View File

@@ -0,0 +1,21 @@
package main
import (
"net/url"
)
func main() {
value1 := url.Values{}
value1.Set("first", "v1")
value1.Set("second", "v2")
l := 0
for k, v := range value1 {
l += len(k) + len(v)
}
println(l)
}
// Output:
// 13

View File

@@ -89,6 +89,8 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
switch typ.Kind() {
case reflect.Map:
n.anc.gen = rangeMap
ityp := &itype{cat: valueT, rtype: reflect.TypeOf((*reflect.MapIter)(nil))}
sc.add(ityp)
ktyp = &itype{cat: valueT, rtype: typ.Key()}
vtyp = &itype{cat: valueT, rtype: typ.Elem()}
case reflect.String: