mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 10:50:05 +00:00
Fix issue #78 and have a better error message.
This commit is contained in:
+1
-1
@@ -417,7 +417,7 @@ __get_map_header :: proc(m: ^map[$K]$V) -> __MapHeader #cc_contextless {
|
|||||||
value: V;
|
value: V;
|
||||||
}
|
}
|
||||||
|
|
||||||
_, is_string := type_info_base(type_info(K)).(^TypeInfo.String);
|
_, is_string := type_info_base(type_info(K)).variant.(TypeInfo.String);
|
||||||
header.is_key_string = is_string;
|
header.is_key_string = is_string;
|
||||||
header.entry_size = size_of(Entry);
|
header.entry_size = size_of(Entry);
|
||||||
header.entry_align = align_of(Entry);
|
header.entry_align = align_of(Entry);
|
||||||
|
|||||||
+4
-2
@@ -6980,7 +6980,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
|||||||
if (!ok) {
|
if (!ok) {
|
||||||
gbString expr_str = expr_to_string(o->expr);
|
gbString expr_str = expr_to_string(o->expr);
|
||||||
gbString dst_type_str = type_to_string(t);
|
gbString dst_type_str = type_to_string(t);
|
||||||
error(o->expr, "Cannot type assert `%s` to `%s`", expr_str, dst_type_str);
|
error(o->expr, "Cannot type assert `%s` to `%s` as it is not a variant of that union", expr_str, dst_type_str);
|
||||||
gb_string_free(dst_type_str);
|
gb_string_free(dst_type_str);
|
||||||
gb_string_free(expr_str);
|
gb_string_free(expr_str);
|
||||||
o->mode = Addressing_Invalid;
|
o->mode = Addressing_Invalid;
|
||||||
@@ -7000,7 +7000,9 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
|||||||
add_type_info_type(c, o->type);
|
add_type_info_type(c, o->type);
|
||||||
add_type_info_type(c, t);
|
add_type_info_type(c, t);
|
||||||
} else {
|
} else {
|
||||||
error(o->expr, "Type assertions can only operate on unions and `any`");
|
gbString str = type_to_string(o->type);
|
||||||
|
error(o->expr, "Type assertions can only operate on unions and `any`, got %s", str);
|
||||||
|
gb_string_free(str);
|
||||||
o->mode = Addressing_Invalid;
|
o->mode = Addressing_Invalid;
|
||||||
o->expr = node;
|
o->expr = node;
|
||||||
return kind;
|
return kind;
|
||||||
|
|||||||
Reference in New Issue
Block a user