mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-31 18:32:12 +00:00
Fix #2160 (deep subtyping through using of _)
This commit is contained in:
@@ -1952,34 +1952,33 @@ lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
|
||||
Type *dt = t;
|
||||
|
||||
GB_ASSERT(is_type_struct(st) || is_type_raw_union(st));
|
||||
String field_name = lookup_subtype_polymorphic_field(t, src_type);
|
||||
if (field_name.len > 0) {
|
||||
// NOTE(bill): It can be casted
|
||||
Selection sel = lookup_field(st, field_name, false, true);
|
||||
if (sel.entity != nullptr) {
|
||||
if (st_is_ptr) {
|
||||
lbValue res = lb_emit_deep_field_gep(p, value, sel);
|
||||
Type *rt = res.type;
|
||||
if (!are_types_identical(rt, dt) && are_types_identical(type_deref(rt), dt)) {
|
||||
res = lb_emit_load(p, res);
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
if (is_type_pointer(value.type)) {
|
||||
Type *rt = value.type;
|
||||
if (!are_types_identical(rt, dt) && are_types_identical(type_deref(rt), dt)) {
|
||||
value = lb_emit_load(p, value);
|
||||
} else {
|
||||
value = lb_emit_deep_field_gep(p, value, sel);
|
||||
return lb_emit_load(p, value);
|
||||
}
|
||||
}
|
||||
|
||||
return lb_emit_deep_field_ev(p, value, sel);
|
||||
|
||||
Selection sel = {};
|
||||
sel.index.allocator = heap_allocator();
|
||||
defer (array_free(&sel.index));
|
||||
if (lookup_subtype_polymorphic_selection(t, src_type, &sel)) {
|
||||
if (sel.entity == nullptr) {
|
||||
GB_PANIC("invalid subtype cast %s -> ", type_to_string(src_type), type_to_string(t));
|
||||
}
|
||||
if (st_is_ptr) {
|
||||
lbValue res = lb_emit_deep_field_gep(p, value, sel);
|
||||
Type *rt = res.type;
|
||||
if (!are_types_identical(rt, dt) && are_types_identical(type_deref(rt), dt)) {
|
||||
res = lb_emit_load(p, res);
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
GB_PANIC("invalid subtype cast %s.%.*s", type_to_string(src_type), LIT(field_name));
|
||||
if (is_type_pointer(value.type)) {
|
||||
Type *rt = value.type;
|
||||
if (!are_types_identical(rt, dt) && are_types_identical(type_deref(rt), dt)) {
|
||||
value = lb_emit_load(p, value);
|
||||
} else {
|
||||
value = lb_emit_deep_field_gep(p, value, sel);
|
||||
return lb_emit_load(p, value);
|
||||
}
|
||||
}
|
||||
|
||||
return lb_emit_deep_field_ev(p, value, sel);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user