Improve error message suggestion for passing enums to integers

This commit is contained in:
gingerBill
2024-06-04 16:16:27 +01:00
parent 11b1a48bf0
commit 6b386631dd
+13 -1
View File
@@ -125,6 +125,8 @@ gb_internal Entity *find_polymorphic_record_entity(GenTypesData *found_gen_types
gb_internal bool complete_soa_type(Checker *checker, Type *t, bool wait_to_finish);
gb_internal bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y);
enum LoadDirectiveResult {
LoadDirective_Success = 0,
LoadDirective_Error = 1,
@@ -2252,6 +2254,17 @@ gb_internal bool check_representable_as_constant(CheckerContext *c, ExactValue i
gb_internal bool check_integer_exceed_suggestion(CheckerContext *c, Operand *o, Type *type, i64 max_bit_size=0) {
if (is_type_integer(type) && o->value.kind == ExactValue_Integer) {
gbString b = type_to_string(type);
defer (gb_string_free(b));
if (is_type_enum(o->type)) {
if (check_is_castable_to(c, o, type)) {
gbString ot = type_to_string(o->type);
error_line("\tSuggestion: Try casting the '%s' expression to '%s'", ot, b);
gb_string_free(ot);
}
return true;
}
i64 sz = type_size_of(type);
i64 bit_size = 8*sz;
@@ -2301,7 +2314,6 @@ gb_internal bool check_integer_exceed_suggestion(CheckerContext *c, Operand *o,
}
}
gb_string_free(b);
return true;
}