mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-31 02:12:04 +00:00
Fix #2160 (deep subtyping through using of _)
This commit is contained in:
@@ -2526,6 +2526,44 @@ String lookup_subtype_polymorphic_field(Type *dst, Type *src) {
|
||||
return str_lit("");
|
||||
}
|
||||
|
||||
bool lookup_subtype_polymorphic_selection(Type *dst, Type *src, Selection *sel) {
|
||||
Type *prev_src = src;
|
||||
// Type *prev_dst = dst;
|
||||
src = base_type(type_deref(src));
|
||||
// dst = base_type(type_deref(dst));
|
||||
bool src_is_ptr = src != prev_src;
|
||||
// bool dst_is_ptr = dst != prev_dst;
|
||||
|
||||
GB_ASSERT(is_type_struct(src) || is_type_union(src));
|
||||
for_array(i, src->Struct.fields) {
|
||||
Entity *f = src->Struct.fields[i];
|
||||
if (f->kind == Entity_Variable && f->flags & EntityFlags_IsSubtype) {
|
||||
if (are_types_identical(dst, f->type)) {
|
||||
array_add(&sel->index, cast(i32)i);
|
||||
sel->entity = f;
|
||||
return true;
|
||||
}
|
||||
if (src_is_ptr && is_type_pointer(dst)) {
|
||||
if (are_types_identical(type_deref(dst), f->type)) {
|
||||
array_add(&sel->index, cast(i32)i);
|
||||
sel->indirect = true;
|
||||
sel->entity = f;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ((f->flags & EntityFlag_Using) != 0 && is_type_struct(f->type)) {
|
||||
String name = lookup_subtype_polymorphic_field(dst, f->type);
|
||||
if (name.len > 0) {
|
||||
array_add(&sel->index, cast(i32)i);
|
||||
return lookup_subtype_polymorphic_selection(dst, f->type, sel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Type *strip_type_aliasing(Type *x) {
|
||||
|
||||
Reference in New Issue
Block a user