File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -801,6 +801,45 @@ set_union_variant_type_info :: proc(a: any, tag_ti: ^Type_Info) {
801801 panic (" expected a union to reflect.set_union_variant_type_info" )
802802}
803803
804+ set_union_value :: proc (dst: any , value: any ) -> bool {
805+ if dst == nil { return false }
806+
807+ ti := runtime.type_info_base (type_info_of (dst.id))
808+ if info, ok := ti.variant.(runtime.Type_Info_Union); ok {
809+ if value.id == nil {
810+ mem.zero (dst.data, ti.size)
811+ return true
812+ }
813+ if ti.id == runtime.typeid_base (value.id) {
814+ mem.copy (dst.data, value.data, ti.size)
815+ return true
816+ }
817+
818+ if type_info_union_is_pure_maybe (info) {
819+ if variant := info.variants[0 ]; variant.id == value.id {
820+ mem.copy (dst.data, value.data, variant.size)
821+ return true
822+ }
823+ return false
824+ }
825+
826+ for variant, i in info.variants {
827+ if variant.id == value.id {
828+ tag := i64 (i)
829+ if !info.no_nil {
830+ tag += 1
831+ }
832+ mem.copy (dst.data, value.data, variant.size)
833+ set_union_variant_raw_tag (dst, tag)
834+ return true
835+ }
836+ }
837+ return false
838+ }
839+ panic (" expected a union to reflect.set_union_variant_typeid" )
840+ }
841+
842+
804843
805844as_bool :: proc (a: any ) -> (value: bool , valid: bool ) {
806845 if a == nil { return }
You can’t perform that action at this time.
0 commit comments