aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-06-29 12:40:04 +0100
committergingerBill <bill@gingerbill.org>2024-06-29 12:40:04 +0100
commitc88a1bef91c56e8b2732077965381156032805d3 (patch)
treed5c8c31277c0049eeb40cdf7ce04aad0f09253d8 /src/check_expr.cpp
parent706adb12323016999692ff6acb62d39d6dc91299 (diff)
Add another `-vet-cast` check
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 6b11a9d08..7107c5712 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -3501,21 +3501,21 @@ gb_internal bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type
// forbidden, so just skip them.
if (forbid_identical && check_vet_flags(c) & VetFlag_Cast &&
(c->curr_proc_sig == nullptr || !is_type_polymorphic(c->curr_proc_sig))) {
- bool is_runtime = false;
- if (c->pkg && (c->pkg->kind == Package_Runtime || c->pkg->kind == Package_Builtin)) {
- is_runtime = true;
- }
if (are_types_identical(src_t, dst_t)) {
- if (!is_runtime) {
- gbString oper_str = expr_to_string(o->expr);
- gbString to_type = type_to_string(dst_t);
- error(o->expr, "Unneeded transmute of '%s' to identical type '%s'", oper_str, to_type);
- gb_string_free(oper_str);
- gb_string_free(to_type);
- }
+ gbString oper_str = expr_to_string(o->expr);
+ gbString to_type = type_to_string(dst_t);
+ error(o->expr, "Unneeded transmute of '%s' to identical type '%s'", oper_str, to_type);
+ gb_string_free(oper_str);
+ gb_string_free(to_type);
} else if (is_type_internally_pointer_like(src_t) &&
is_type_internally_pointer_like(dst_t)) {
error(o->expr, "Use of 'transmute' where 'cast' would be preferred since the types are pointer-like");
+ } else if (are_types_identical(src_bt, dst_bt)) {
+ gbString oper_str = expr_to_string(o->expr);
+ gbString to_type = type_to_string(dst_t);
+ error(o->expr, "Unneeded transmute of '%s' to identical type '%s'", oper_str, to_type);
+ gb_string_free(oper_str);
+ gb_string_free(to_type);
} else if (is_type_integer(src_t) && is_type_integer(dst_t) &&
types_have_same_internal_endian(src_t, dst_t)) {
gbString oper_type = type_to_string(src_t);