feat: Append 方法支持 R 接口包装的指针类型

增强 setValue 函数,支持将 R 接口包装的指针值追加到非指针类型的切片中。当源值是指针但目标不是指针时,自动解引用后再赋值,使得 New(&item) 可以追加到 []Item 类型的切片。同时统一使用 Raw() 方法替代 Value() 方法名。
This commit is contained in:
2025-12-08 17:24:45 +08:00
parent f5f261e541
commit bacec92841
4 changed files with 264 additions and 6 deletions

View File

@@ -332,7 +332,7 @@ func normalizeInputValue(v any) (reflect.Value, bool, error) {
if vv, ok := v.(R); ok {
isPtr = true
rv = vv.Value()
rv = vv.Raw()
} else if vv, ok := v.([]R); ok {
// 支持直接传入 []R,自动转换为底层切片
var elemType reflect.Type
@@ -340,7 +340,7 @@ func normalizeInputValue(v any) (reflect.Value, bool, error) {
if it == nil {
continue
}
val := it.Value()
val := it.Raw()
if val.IsValid() {
elemType = val.Type()
break
@@ -358,7 +358,7 @@ func normalizeInputValue(v any) (reflect.Value, bool, error) {
if it == nil {
continue
}
val := it.Value()
val := it.Raw()
if !val.IsValid() {
continue
}