Skip to content

Commit

Permalink
Fix #3555
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerBill committed May 9, 2024
1 parent 97e9c50 commit d85c8f0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/check_decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,17 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
if (e->kind != Entity_Variable) {
continue;
}
if (is_type_polymorphic(e->type)) {
gbString s = type_to_string(e->type);
char const *msg = "Unspecialized polymorphic types are not allowed in procedure parameters, got %s";
if (e->Variable.type_expr) {
error(e->Variable.type_expr, msg, s);
} else {
error(e->token, msg, s);
}
gb_string_free(s);
}

if (!(e->flags & EntityFlag_Using)) {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/check_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,7 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
param = alloc_entity_param(scope, name->Ident.token, type, is_using, true);
param->Variable.param_value = param_value;
param->Variable.field_group_index = field_group_index;
param->Variable.type_expr = type_expr;
}
}
if (p->flags&FieldFlag_no_alias) {
Expand Down
1 change: 1 addition & 0 deletions src/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ struct Entity {
CommentGroup *comment;
} Constant;
struct {
Ast *type_expr; // only used for some variables within procedure bodies
Ast *init_expr; // only used for some variables within procedure bodies
i32 field_index;
i32 field_group_index;
Expand Down
4 changes: 4 additions & 0 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3267,6 +3267,10 @@ gb_internal Selection lookup_field_with_selection(Type *type_, String field_name
}
}

if (is_type_polymorphic(type)) {
// NOTE(bill): A polymorphic struct has no fields, this only hits in the case of an error
return sel;
}
wait_signal_until_available(&type->Struct.fields_wait_signal);
isize field_count = type->Struct.fields.count;
if (field_count != 0) for_array(i, type->Struct.fields) {
Expand Down

0 comments on commit d85c8f0

Please sign in to comment.