Skip to content

Commit

Permalink
go/ir: do not panic on generic type slice expression
Browse files Browse the repository at this point in the history
Closes: gh-1270
Closes: gh-1271 [via git-merge-pr]
Co-authored-by: Dominik Honnef <dominik@honnef.co>
(cherry picked from commit 67bbe3d)
  • Loading branch information
tdakkota authored and dominikh committed May 16, 2022
1 parent b345e26 commit c6cc483
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions go/ir/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c6cc483

Please sign in to comment.