
@ignore_access

fn clone_value[T](value: T) T {
    #if is_nullable_type(T)
    if value == null : return null
    #end
    #if !is_structural_type(T)
    let result = value
    #else
    #if type_has_method(T, clone)
    return value.clone()
    #end
    // Structure types
    let result = T {
        #if type_has_vtable(T)
        _VTABLE: @vtable(T)
        #end
    #loop object value as PROP
        #if !property_name_is(PROP, _VTABLE)
        PROP: clone_value[PROP](PROP.value)
        #end
    #end
    }
    #end
    return result
}
