mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Improve error message suggestion for passing enums to integers
This commit is contained in:
+13
-1
@@ -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 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 {
|
enum LoadDirectiveResult {
|
||||||
LoadDirective_Success = 0,
|
LoadDirective_Success = 0,
|
||||||
LoadDirective_Error = 1,
|
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) {
|
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) {
|
if (is_type_integer(type) && o->value.kind == ExactValue_Integer) {
|
||||||
gbString b = type_to_string(type);
|
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 sz = type_size_of(type);
|
||||||
i64 bit_size = 8*sz;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user