Commit 33145c48 authored by Sebastien Binet's avatar Sebastien Binet Committed by Robert Griesemer

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
parent 03e25966
...@@ -595,9 +595,15 @@ func (a *exprCompiler) compile(x ast.Expr, callCtx bool) *expr { ...@@ -595,9 +595,15 @@ func (a *exprCompiler) compile(x ast.Expr, callCtx bool) *expr {
return ei.compileIndexExpr(l, r) return ei.compileIndexExpr(l, r)
case *ast.SliceExpr: case *ast.SliceExpr:
var hi *expr var lo, hi *expr
arr := a.compile(x.X, false) 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 { if x.End == nil {
// End was omitted, so we need to compute len(x.X) // End was omitted, so we need to compute len(x.X)
ei := &exprInfo{a.compiler, x.Pos()} ei := &exprInfo{a.compiler, x.Pos()}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment