diff --git a/go/ir/builder.go b/go/ir/builder.go index 7cef5f1e1..e5566ade5 100644 --- a/go/ir/builder.go +++ b/go/ir/builder.go @@ -669,17 +669,24 @@ func (b *builder) expr0(fn *Function, e ast.Expr, tv types.TypeAndValue) Value { } case *ast.SliceExpr: - var low, high, max Value var x Value - switch typeutil.CoreType(fn.Pkg.typeOf(e.X)).Underlying().(type) { - case *types.Array: - // Potentially escaping. - x = b.addr(fn, e.X, true).address(fn) - case *types.Basic, *types.Slice, *types.Pointer: // *array + if core := typeutil.CoreType(fn.Pkg.typeOf(e.X)); core != nil { + switch core.Underlying().(type) { + case *types.Array: + // Potentially escaping. + x = b.addr(fn, e.X, true).address(fn) + case *types.Basic, *types.Slice, *types.Pointer: // *array + x = b.expr(fn, e.X) + default: + panic("unreachable") + } + } else { + // We're indexing a string | []byte. Note that other combinations such as []byte | [4]byte are currently not + // allowed by the language. x = b.expr(fn, e.X) - default: - panic("unreachable") } + + var low, high, max Value if e.High != nil { high = b.expr(fn, e.High) }