mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 22:28:46 +00:00
Fix bug: Disallow non-specialized polymorphic in typeid assignment
This commit is contained in:
+14
-4
@@ -629,6 +629,9 @@ gb_internal i64 check_distance_between_types(CheckerContext *c, Operand *operand
|
|||||||
|
|
||||||
if (operand->mode == Addressing_Type) {
|
if (operand->mode == Addressing_Type) {
|
||||||
if (is_type_typeid(type)) {
|
if (is_type_typeid(type)) {
|
||||||
|
if (is_type_polymorphic(operand->type)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
add_type_info_type(c, operand->type);
|
add_type_info_type(c, operand->type);
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
@@ -1118,10 +1121,17 @@ gb_internal void check_assignment(CheckerContext *c, Operand *operand, Type *typ
|
|||||||
LIT(context_name));
|
LIT(context_name));
|
||||||
break;
|
break;
|
||||||
case Addressing_Type:
|
case Addressing_Type:
|
||||||
error(operand->expr,
|
if (is_type_polymorphic(operand->type)) {
|
||||||
"Cannot assign '%s' which is a type in %.*s",
|
error(operand->expr,
|
||||||
op_type_str,
|
"Cannot assign '%s' which is a polymorphic type in %.*s",
|
||||||
LIT(context_name));
|
op_type_str,
|
||||||
|
LIT(context_name));
|
||||||
|
} else {
|
||||||
|
error(operand->expr,
|
||||||
|
"Cannot assign '%s' which is a type in %.*s",
|
||||||
|
op_type_str,
|
||||||
|
LIT(context_name));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// TODO(bill): is this a good enough error message?
|
// TODO(bill): is this a good enough error message?
|
||||||
|
|||||||
+6
-1
@@ -1922,6 +1922,12 @@ gb_internal void add_type_info_type_internal(CheckerContext *c, Type *t) {
|
|||||||
for_array(i, bt->Union.variants) {
|
for_array(i, bt->Union.variants) {
|
||||||
add_type_info_type_internal(c, bt->Union.variants[i]);
|
add_type_info_type_internal(c, bt->Union.variants[i]);
|
||||||
}
|
}
|
||||||
|
if (bt->Union.scope != nullptr) {
|
||||||
|
for (auto const &entry : bt->Union.scope->elements) {
|
||||||
|
Entity *e = entry.value;
|
||||||
|
add_type_info_type_internal(c, e->type);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Type_Struct:
|
case Type_Struct:
|
||||||
@@ -2265,7 +2271,6 @@ gb_internal void add_dependency_to_set(Checker *c, Entity *entity) {
|
|||||||
if (decl == nullptr) {
|
if (decl == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Type *t : decl->type_info_deps) {
|
for (Type *t : decl->type_info_deps) {
|
||||||
add_min_dep_type_info(c, t);
|
add_min_dep_type_info(c, t);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1094,8 +1094,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo
|
|||||||
}
|
}
|
||||||
if (is_constant) {
|
if (is_constant) {
|
||||||
LLVMValueRef elem_value = lb_const_value(m, tav.type, tav.value, allow_local).value;
|
LLVMValueRef elem_value = lb_const_value(m, tav.type, tav.value, allow_local).value;
|
||||||
GB_ASSERT(LLVMIsConstant(elem_value));
|
if (LLVMIsConstant(elem_value)) {
|
||||||
values[index] = LLVMConstInsertValue(values[index], elem_value, idx_list, idx_list_len);
|
values[index] = LLVMConstInsertValue(values[index], elem_value, idx_list, idx_list_len);
|
||||||
|
} else {
|
||||||
|
is_constant = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user