aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-11-25 10:35:49 +0000
committergingerBill <bill@gingerbill.org>2018-11-25 10:35:49 +0000
commit0a4b88f9a682b08a11f9569c88549855793f0be8 (patch)
treefd0e2c51efd7fa997e193491e14bd4f9d158ec40 /src/check_expr.cpp
parent4c2f03b1f26bf9d9ec986bb2284e4daa9b4a95aa (diff)
Fix Issue with referencing a polymorphic struct in another package referencing itself #283
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 943b1972d..cb54f6b7a 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -27,7 +27,7 @@ struct CallArgumentData {
};
struct PolyProcData {
- Entity * gen_entity;
+ Entity * gen_entity;
ProcInfo proc_info;
};
@@ -4818,7 +4818,6 @@ CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *oper
ast_node(ce, CallExpr, call);
Type *original_type = operand->type;
- Type *struct_type = base_type(operand->type);
GB_ASSERT(is_type_polymorphic_record(original_type));
bool show_error = true;
@@ -4983,6 +4982,11 @@ CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *oper
String generated_name = make_string_c(expr_to_string(call));
+ CheckerContext ctx = *c;
+ // NOTE(bill): We need to make sure the lookup scope for the record is the same as where it was created
+ ctx.scope = polymorphic_record_parent_scope(original_type);
+ GB_ASSERT(ctx.scope != nullptr);
+
Type *named_type = alloc_type_named(generated_name, nullptr, nullptr);
Type *bt = base_type(original_type);
if (bt->kind == Type_Struct) {
@@ -4992,9 +4996,9 @@ CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *oper
struct_type->Struct.polymorphic_parent = original_type;
set_base_type(named_type, struct_type);
- check_open_scope(c, node);
- check_struct_type(c, struct_type, node, &ordered_operands, named_type, original_type);
- check_close_scope(c);
+ check_open_scope(&ctx, node);
+ check_struct_type(&ctx, struct_type, node, &ordered_operands, named_type, original_type);
+ check_close_scope(&ctx);
} else if (bt->kind == Type_Union) {
Ast *node = clone_ast(bt->Union.node);
Type *union_type = alloc_type_union();
@@ -5002,9 +5006,9 @@ CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *oper
union_type->Union.polymorphic_parent = original_type;
set_base_type(named_type, union_type);
- check_open_scope(c, node);
- check_union_type(c, union_type, node, &ordered_operands, named_type, original_type);
- check_close_scope(c);
+ check_open_scope(&ctx, node);
+ check_union_type(&ctx, union_type, node, &ordered_operands, named_type, original_type);
+ check_close_scope(&ctx);
} else {
GB_PANIC("Unsupported parametric polymorphic record type");
}