go/ir: do not panic on generic type slice expression
Closes:
Closes: [via git-merge-pr]
@@ -669,9 +669,9 @@ 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) {
+ 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)
@@ -680,6 +680,13 @@ func (b *builder) expr0(fn *Function, e ast.Expr, tv types.TypeAndValue) Value {
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)
+ }
+
+ var low, high, max Value
if e.High != nil {
high = b.expr(fn, e.High)
}
