diff options
author | Sebastien Binet <seb.binet@gmail.com> | 2010-12-27 10:05:32 -0800 |
---|---|---|
committer | Sebastien Binet <seb.binet@gmail.com> | 2010-12-27 10:05:32 -0800 |
commit | bf44242277c642b3439559f92c97e85ebccb8f2a (patch) | |
tree | 27e9821f270c4554829f11460391abc7c8548804 | |
parent | 994a703f947c691839cd65ed0f71cba107f97983 (diff) | |
download | go-bf44242277c642b3439559f92c97e85ebccb8f2a.tar.gz |
simple fix to not have 'exp/eval' panic in presence of slices like s[:2]
R=golang-dev, gri
CC=binet, golang-dev
http://codereview.appspot.com/3782044
Committer: Robert Griesemer <gri@golang.org>
-rw-r--r-- | src/pkg/exp/eval/expr.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/pkg/exp/eval/expr.go b/src/pkg/exp/eval/expr.go index 66adeef95..f633aea39 100644 --- a/src/pkg/exp/eval/expr.go +++ b/src/pkg/exp/eval/expr.go @@ -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()} |