gingerBill 1 year ago
parent
commit
d85c8f0b2c
4 changed files with 17 additions and 0 deletions
  1. 11 0
      src/check_decl.cpp
  2. 1 0
      src/check_type.cpp
  3. 1 0
      src/entity.cpp
  4. 4 0
      src/types.cpp

+ 11 - 0
src/check_decl.cpp

@@ -1619,6 +1619,17 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
 				if (e->kind != Entity_Variable) {
 				if (e->kind != Entity_Variable) {
 					continue;
 					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)) {
 				if (!(e->flags & EntityFlag_Using)) {
 					continue;
 					continue;
 				}
 				}

+ 1 - 0
src/check_type.cpp

@@ -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 = alloc_entity_param(scope, name->Ident.token, type, is_using, true);
 					param->Variable.param_value = param_value;
 					param->Variable.param_value = param_value;
 					param->Variable.field_group_index = field_group_index;
 					param->Variable.field_group_index = field_group_index;
+					param->Variable.type_expr = type_expr;
 				}
 				}
 			}
 			}
 			if (p->flags&FieldFlag_no_alias) {
 			if (p->flags&FieldFlag_no_alias) {

+ 1 - 0
src/entity.cpp

@@ -210,6 +210,7 @@ struct Entity {
 			CommentGroup *comment;
 			CommentGroup *comment;
 		} Constant;
 		} Constant;
 		struct {
 		struct {
+			Ast *type_expr; // only used for some variables within procedure bodies
 			Ast *init_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_index;
 			i32  field_group_index;
 			i32  field_group_index;

+ 4 - 0
src/types.cpp

@@ -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);
 		wait_signal_until_available(&type->Struct.fields_wait_signal);
 		isize field_count = type->Struct.fields.count;
 		isize field_count = type->Struct.fields.count;
 		if (field_count != 0) for_array(i, type->Struct.fields) {
 		if (field_count != 0) for_array(i, type->Struct.fields) {