mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Fix #2526
This commit is contained in:
+8
-4
@@ -43,14 +43,20 @@ gb_internal Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *o
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (operand->mode == Addressing_Type) {
|
if (operand->mode == Addressing_Type) {
|
||||||
if (e->type != nullptr && is_type_typeid(e->type)) {
|
if (e->type != nullptr && is_type_typeid(e->type) && !is_type_polymorphic(operand->type)) {
|
||||||
add_type_info_type(ctx, operand->type);
|
add_type_info_type(ctx, operand->type);
|
||||||
add_type_and_value(ctx, operand->expr, Addressing_Value, e->type, exact_value_typeid(operand->type));
|
add_type_and_value(ctx, operand->expr, Addressing_Value, e->type, exact_value_typeid(operand->type));
|
||||||
return e->type;
|
return e->type;
|
||||||
} else {
|
} else {
|
||||||
|
ERROR_BLOCK();
|
||||||
|
|
||||||
gbString t = type_to_string(operand->type);
|
gbString t = type_to_string(operand->type);
|
||||||
defer (gb_string_free(t));
|
defer (gb_string_free(t));
|
||||||
error(operand->expr, "Cannot assign a type '%s' to variable '%.*s'", t, LIT(e->token.string));
|
if (is_type_polymorphic(operand->type)) {
|
||||||
|
error(operand->expr, "Cannot assign a non-specialized polymorphic type '%s' to variable '%.*s'", t, LIT(e->token.string));
|
||||||
|
} else {
|
||||||
|
error(operand->expr, "Cannot assign a type '%s' to variable '%.*s'", t, LIT(e->token.string));
|
||||||
|
}
|
||||||
if (e->type == nullptr) {
|
if (e->type == nullptr) {
|
||||||
error_line("\tThe type of the variable '%.*s' cannot be inferred as a type does not have a default type\n", LIT(e->token.string));
|
error_line("\tThe type of the variable '%.*s' cannot be inferred as a type does not have a default type\n", LIT(e->token.string));
|
||||||
}
|
}
|
||||||
@@ -59,8 +65,6 @@ gb_internal Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *o
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (e->type == nullptr) {
|
if (e->type == nullptr) {
|
||||||
|
|
||||||
// NOTE(bill): Use the type of the operand
|
// NOTE(bill): Use the type of the operand
|
||||||
|
|||||||
@@ -402,6 +402,12 @@ gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, O
|
|||||||
|
|
||||||
Type *assignment_type = lhs->type;
|
Type *assignment_type = lhs->type;
|
||||||
|
|
||||||
|
if (rhs->mode == Addressing_Type && is_type_polymorphic(rhs->type)) {
|
||||||
|
gbString t = type_to_string(rhs->type);
|
||||||
|
error(rhs->expr, "Invalid use of a non-specialized polymorphic type '%s'", t);
|
||||||
|
gb_string_free(t);
|
||||||
|
}
|
||||||
|
|
||||||
switch (lhs->mode) {
|
switch (lhs->mode) {
|
||||||
case Addressing_Invalid:
|
case Addressing_Invalid:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user