tape: canAssign now reports true for named table types

This commit is contained in:
Sasha Koshka 2025-10-12 21:27:35 -04:00
parent f10327356e
commit cbfb513933

View File

@ -355,8 +355,12 @@ func encodeAnyMap(encoder *Encoder, value any, tag Tag) (n int, err error) {
}
func canSet(destination reflect.Type, tag Tag) error {
fmt.Println("== CAN SET ====================")
fmt.Println(destination)
fmt.Println(tag)
// anything can be assigned to `any`
if isTypeAny(destination) {
fmt.Println("OK")
return nil
}
switch tag.WithoutCN() {
@ -387,12 +391,17 @@ func canSet(destination reflect.Type, tag Tag) error {
return errCantAssignf("cannot assign array to %v", destination)
}
case KTV:
if destination != reflect.TypeOf(dummyMap) {
cantAssign :=
destination.Kind() != reflect.Map ||
destination.Key().Kind() != reflect.Uint16 ||
!isTypeAny(destination.Elem())
if cantAssign {
return errCantAssignf("cannot assign table to %v", destination)
}
default:
return fmt.Errorf("unknown TN %d", tag.TN())
}
fmt.Println("OK")
return nil
}