diff options
| author | gingerBill <bill@gingerbill.org> | 2022-11-01 13:14:20 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-11-01 13:14:20 +0000 |
| commit | 2b7ca2bdd6be41abeb8ab5c5fa91f24657996e88 (patch) | |
| tree | cdba200a615349a1c33b68a4becf4ebda3da35ef /src/types.cpp | |
| parent | 411c0add3b2394a222ff341d88aef512c554c050 (diff) | |
Fix #2160 (deep subtyping through `using` of `_`)
Diffstat (limited to 'src/types.cpp')
| -rw-r--r-- | src/types.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/types.cpp b/src/types.cpp index fec324bf4..b9f2b375f 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -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) { |