| ... | @@ -3453,11 +3453,12 @@ TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag) { | ... | @@ -3453,11 +3453,12 @@ TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag) { |
| 3453 | } | 3453 | } |
| 3454 | | 3454 | |
| 3455 | | 3455 | |
| 3456 | static bool is_container(ZigType *type_entry) { | 3456 | bool is_container(ZigType *type_entry) { |
| 3457 | switch (type_entry->id) { | 3457 | switch (type_entry->id) { |
| 3458 | case ZigTypeIdInvalid: | 3458 | case ZigTypeIdInvalid: |
| 3459 | zig_unreachable(); | 3459 | zig_unreachable(); |
| 3460 | case ZigTypeIdStruct: | 3460 | case ZigTypeIdStruct: |
| | 3461 | return !type_entry->data.structure.is_slice; |
| 3461 | case ZigTypeIdEnum: | 3462 | case ZigTypeIdEnum: |
| 3462 | case ZigTypeIdUnion: | 3463 | case ZigTypeIdUnion: |
| 3463 | return true; | 3464 | return true; |
| ... | @@ -3498,9 +3499,9 @@ bool is_array_ref(ZigType *type_entry) { | ... | @@ -3498,9 +3499,9 @@ bool is_array_ref(ZigType *type_entry) { |
| 3498 | return array->id == ZigTypeIdArray; | 3499 | return array->id == ZigTypeIdArray; |
| 3499 | } | 3500 | } |
| 3500 | | 3501 | |
| 3501 | bool is_container_ref(ZigType *type_entry) { | 3502 | bool is_container_ref(ZigType *parent_ty) { |
| 3502 | return is_ref(type_entry) ? | 3503 | ZigType *ty = is_ref(parent_ty) ? parent_ty->data.pointer.child_type : parent_ty; |
| 3503 | is_container(type_entry->data.pointer.child_type) : is_container(type_entry); | 3504 | return is_slice(ty) || is_container(ty); |
| 3504 | } | 3505 | } |
| 3505 | | 3506 | |
| 3506 | ZigType *container_ref_type(ZigType *type_entry) { | 3507 | ZigType *container_ref_type(ZigType *type_entry) { |
| ... | @@ -3765,49 +3766,59 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { | ... | @@ -3765,49 +3766,59 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { |
| 3765 | analyze_fn_ir(g, fn_table_entry, return_type_node); | 3766 | analyze_fn_ir(g, fn_table_entry, return_type_node); |
| 3766 | } | 3767 | } |
| 3767 | | 3768 | |
| 3768 | static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *dst_use_node, ScopeDecls* decls_scope) { | 3769 | static void add_symbols_from_container(CodeGen *g, AstNode *src_use_node, AstNode *dst_use_node, ScopeDecls* decls_scope) { |
| 3769 | if (src_use_node->data.use.resolution == TldResolutionUnresolved) { | 3770 | if (src_use_node->data.use.resolution == TldResolutionUnresolved) { |
| 3770 | preview_use_decl(g, src_use_node, decls_scope); | 3771 | preview_use_decl(g, src_use_node, decls_scope); |
| 3771 | } | 3772 | } |
| 3772 | | 3773 | |
| 3773 | ConstExprValue *use_target_value = src_use_node->data.use.using_namespace_value; | 3774 | ConstExprValue *use_expr = src_use_node->data.use.using_namespace_value; |
| 3774 | if (type_is_invalid(use_target_value->type)) { | 3775 | if (type_is_invalid(use_expr->type)) { |
| 3775 | decls_scope->any_imports_failed = true; | 3776 | decls_scope->any_imports_failed = true; |
| 3776 | return; | 3777 | return; |
| 3777 | } | 3778 | } |
| 3778 | | 3779 | |
| 3779 | dst_use_node->data.use.resolution = TldResolutionOk; | 3780 | dst_use_node->data.use.resolution = TldResolutionOk; |
| 3780 | | 3781 | |
| 3781 | assert(use_target_value->special != ConstValSpecialRuntime); | 3782 | assert(use_expr->special != ConstValSpecialRuntime); |
| 3782 | | 3783 | |
| 3783 | ZigType *target_import = use_target_value->data.x_type; | 3784 | // The source struct for the imported symbols |
| 3784 | assert(target_import); | 3785 | ZigType *src_ty = use_expr->data.x_type; |
| | 3786 | assert(src_ty); |
| 3785 | | 3787 | |
| 3786 | if (target_import->id != ZigTypeIdStruct) { | 3788 | if (!is_container(src_ty)) { |
| 3787 | add_node_error(g, dst_use_node, | 3789 | add_node_error(g, dst_use_node, |
| 3788 | buf_sprintf("expected struct, found '%s'", buf_ptr(&target_import->name))); | 3790 | buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&src_ty->name))); |
| 3789 | decls_scope->any_imports_failed = true; | 3791 | decls_scope->any_imports_failed = true; |
| 3790 | return; | 3792 | return; |
| 3791 | } | 3793 | } |
| 3792 | | 3794 | |
| 3793 | if (get_container_scope(target_import)->any_imports_failed) { | 3795 | // The source scope for the imported symbols |
| | 3796 | ScopeDecls *src_scope = get_container_scope(src_ty); |
| | 3797 | // The top-level container where the symbols are defined, it's used in the |
| | 3798 | // loop below in order to exclude the ones coming from an import statement |
| | 3799 | ZigType *src_import = get_scope_import(&src_scope->base); |
| | 3800 | assert(src_import != nullptr); |
| | 3801 | |
| | 3802 | if (src_scope->any_imports_failed) { |
| 3794 | decls_scope->any_imports_failed = true; | 3803 | decls_scope->any_imports_failed = true; |
| 3795 | } | 3804 | } |
| 3796 | | 3805 | |
| 3797 | auto it = get_container_scope(target_import)->decl_table.entry_iterator(); | 3806 | auto it = src_scope->decl_table.entry_iterator(); |
| 3798 | for (;;) { | 3807 | for (;;) { |
| 3799 | auto *entry = it.next(); | 3808 | auto *entry = it.next(); |
| 3800 | if (!entry) | 3809 | if (!entry) |
| 3801 | break; | 3810 | break; |
| 3802 | | 3811 | |
| | 3812 | Buf *target_tld_name = entry->key; |
| 3803 | Tld *target_tld = entry->value; | 3813 | Tld *target_tld = entry->value; |
| 3804 | if (target_tld->import != target_import || | 3814 | |
| 3805 | target_tld->visib_mod == VisibModPrivate) | 3815 | if (target_tld->visib_mod == VisibModPrivate) { |
| 3806 | { | | |
| 3807 | continue; | 3816 | continue; |
| 3808 | } | 3817 | } |
| 3809 | | 3818 | |
| 3810 | Buf *target_tld_name = entry->key; | 3819 | if (target_tld->import != src_import) { |
| | 3820 | continue; |
| | 3821 | } |
| 3811 | | 3822 | |
| 3812 | auto existing_entry = decls_scope->decl_table.put_unique(target_tld_name, target_tld); | 3823 | auto existing_entry = decls_scope->decl_table.put_unique(target_tld_name, target_tld); |
| 3813 | if (existing_entry) { | 3824 | if (existing_entry) { |
| ... | @@ -3822,10 +3833,10 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode * | ... | @@ -3822,10 +3833,10 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode * |
| 3822 | } | 3833 | } |
| 3823 | } | 3834 | } |
| 3824 | | 3835 | |
| 3825 | for (size_t i = 0; i < get_container_scope(target_import)->use_decls.length; i += 1) { | 3836 | for (size_t i = 0; i < src_scope->use_decls.length; i += 1) { |
| 3826 | AstNode *use_decl_node = get_container_scope(target_import)->use_decls.at(i); | 3837 | AstNode *use_decl_node = src_scope->use_decls.at(i); |
| 3827 | if (use_decl_node->data.use.visib_mod != VisibModPrivate) | 3838 | if (use_decl_node->data.use.visib_mod != VisibModPrivate) |
| 3828 | add_symbols_from_import(g, use_decl_node, dst_use_node, decls_scope); | 3839 | add_symbols_from_container(g, use_decl_node, dst_use_node, decls_scope); |
| 3829 | } | 3840 | } |
| 3830 | } | 3841 | } |
| 3831 | | 3842 | |
| ... | @@ -3837,7 +3848,7 @@ void resolve_use_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) { | ... | @@ -3837,7 +3848,7 @@ void resolve_use_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) { |
| 3837 | { | 3848 | { |
| 3838 | return; | 3849 | return; |
| 3839 | } | 3850 | } |
| 3840 | add_symbols_from_import(g, node, node, decls_scope); | 3851 | add_symbols_from_container(g, node, node, decls_scope); |
| 3841 | } | 3852 | } |
| 3842 | | 3853 | |
| 3843 | void preview_use_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) { | 3854 | void preview_use_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) { |