From ec549a6a25f77e92409177131619f1050b2d6445 Mon Sep 17 00:00:00 2001 From: visualfc Date: Fri, 13 Dec 2024 19:11:52 +0800 Subject: [PATCH] internal/lib/reflect: value.convert check func --- runtime/internal/lib/reflect/value.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/internal/lib/reflect/value.go b/runtime/internal/lib/reflect/value.go index 5ebd6e0d..9204f093 100644 --- a/runtime/internal/lib/reflect/value.go +++ b/runtime/internal/lib/reflect/value.go @@ -1868,7 +1868,12 @@ func (v Value) Convert(t Type) Value { if v.flag&flagMethod != 0 { v = makeMethodValue("Convert", v) } - op := convertOp(t.common(), v.typ()) + var op func(Value, Type) Value + if kind := v.Kind(); kind == Func && kind == t.Kind() { + op = convertOp(t.common(), v.Type().common()) + } else { + op = convertOp(t.common(), v.typ()) + } if op == nil { panic("reflect.Value.Convert: value of type " + stringFor(v.typ()) + " cannot be converted to type " + t.String()) }