From a16afd0bc29ca3a12561d527a4d0fecfc60f568d Mon Sep 17 00:00:00 2001 From: Leon Mika Date: Thu, 12 Dec 2024 08:20:02 +1100 Subject: [PATCH] Actually fixed the panic but reverted back to old working --- repl/evaldisplay.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/repl/evaldisplay.go b/repl/evaldisplay.go index f4e72d8..f09254c 100644 --- a/repl/evaldisplay.go +++ b/repl/evaldisplay.go @@ -89,23 +89,25 @@ func (r *REPL) displayResult(ctx context.Context, w io.Writer, res any, concise fmt.Fprintf(w, "]") } else { // In the off-chance that this is actually a slice of printables - vt := reflect.ValueOf(res).Type() - if tp, ok := r.typePrinters[vt]; ok { - canDisplay := true + if len(v) > 0 { + vt := reflect.SliceOf(reflect.TypeOf(v[0])) + if tp, ok := r.typePrinters[vt]; ok { + canDisplay := true - typeSlice := reflect.MakeSlice(vt, len(v), len(v)) - for i := 0; i < len(v); i++ { - vv := reflect.ValueOf(v[i]) - if vv.CanConvert(vt.Elem()) { - typeSlice.Index(i).Set(vv) - } else { - canDisplay = false - break + typeSlice := reflect.MakeSlice(vt, len(v), len(v)) + for i := 0; i < len(v); i++ { + vv := reflect.ValueOf(v[i]) + if vv.CanConvert(vt.Elem()) { + typeSlice.Index(i).Set(vv) + } else { + canDisplay = false + break + } } - } - if canDisplay { - return tp(w, typeSlice.Interface(), concise) + if canDisplay { + return tp(w, typeSlice.Interface(), concise) + } } }