Skip to content

Commit

Permalink
Fix ranger selection when indirecting to a map.
Browse files Browse the repository at this point in the history
  • Loading branch information
tooolbox authored and sauerbraten committed Sep 8, 2020
1 parent 0916c64 commit c7f9655
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1556,25 +1556,28 @@ func getRanger(v reflect.Value) Ranger {
return v.Interface().(Ranger)
}
k := tuP.Kind()
switch k {
case reflect.Ptr, reflect.Interface:
v = v.Elem()
k = v.Kind()
fallthrough
case reflect.Slice, reflect.Array:
sliceranger := pool_sliceRanger.Get().(*sliceRanger)
sliceranger.i = -1
sliceranger.len = v.Len()
sliceranger.v = v
return sliceranger
case reflect.Map:
mapranger := pool_mapRanger.Get().(*mapRanger)
*mapranger = mapRanger{v: v, keys: v.MapKeys(), len: v.Len()}
return mapranger
case reflect.Chan:
chanranger := pool_chanRanger.Get().(*chanRanger)
*chanranger = chanRanger{v: v}
return chanranger
for {
switch k {
case reflect.Ptr, reflect.Interface:
v = v.Elem()
k = v.Kind()
continue
case reflect.Slice, reflect.Array:
sliceranger := pool_sliceRanger.Get().(*sliceRanger)
sliceranger.i = -1
sliceranger.len = v.Len()
sliceranger.v = v
return sliceranger
case reflect.Map:
mapranger := pool_mapRanger.Get().(*mapRanger)
*mapranger = mapRanger{v: v, keys: v.MapKeys(), len: v.Len()}
return mapranger
case reflect.Chan:
chanranger := pool_chanRanger.Get().(*chanRanger)
*chanranger = chanRanger{v: v}
return chanranger
}
break
}
panic(fmt.Errorf("type %s is not rangeable", tuP))
}
Expand Down

0 comments on commit c7f9655

Please sign in to comment.