Actually fixed the panic but reverted back to old working
All checks were successful
Build / build (push) Successful in 1m41s

This commit is contained in:
Leon Mika 2024-12-12 08:20:02 +11:00
parent 4a527cfe3d
commit a16afd0bc2

View file

@ -89,23 +89,25 @@ func (r *REPL) displayResult(ctx context.Context, w io.Writer, res any, concise
fmt.Fprintf(w, "]") fmt.Fprintf(w, "]")
} else { } else {
// In the off-chance that this is actually a slice of printables // In the off-chance that this is actually a slice of printables
vt := reflect.ValueOf(res).Type() if len(v) > 0 {
if tp, ok := r.typePrinters[vt]; ok { vt := reflect.SliceOf(reflect.TypeOf(v[0]))
canDisplay := true if tp, ok := r.typePrinters[vt]; ok {
canDisplay := true
typeSlice := reflect.MakeSlice(vt, len(v), len(v)) typeSlice := reflect.MakeSlice(vt, len(v), len(v))
for i := 0; i < len(v); i++ { for i := 0; i < len(v); i++ {
vv := reflect.ValueOf(v[i]) vv := reflect.ValueOf(v[i])
if vv.CanConvert(vt.Elem()) { if vv.CanConvert(vt.Elem()) {
typeSlice.Index(i).Set(vv) typeSlice.Index(i).Set(vv)
} else { } else {
canDisplay = false canDisplay = false
break break
}
} }
}
if canDisplay { if canDisplay {
return tp(w, typeSlice.Interface(), concise) return tp(w, typeSlice.Interface(), concise)
}
} }
} }