1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:47:58 -07:00

simple fix to not have 'exp/eval' panic in presence of slices like s[:2]

R=golang-dev, gri
CC=binet, golang-dev
https://golang.org/cl/3782044
This commit is contained in:
Sebastien Binet 2010-12-27 10:05:32 -08:00 committed by Robert Griesemer
parent 03e259664f
commit 33145c4868

View File

@ -595,9 +595,15 @@ func (a *exprCompiler) compile(x ast.Expr, callCtx bool) *expr {
return ei.compileIndexExpr(l, r)
case *ast.SliceExpr:
var hi *expr
var lo, hi *expr
arr := a.compile(x.X, false)
lo := a.compile(x.Index, false)
if x.Index == nil {
// beginning was omitted, so we need to provide it
ei := &exprInfo{a.compiler, x.Pos()}
lo = ei.compileIntLit("0")
} else {
lo = a.compile(x.Index, false)
}
if x.End == nil {
// End was omitted, so we need to compute len(x.X)
ei := &exprInfo{a.compiler, x.Pos()}