Update error message on casting between distinct types.

This commit is contained in:
Christoffer Lerno
2025-02-04 11:24:08 +01:00
parent c54c400291
commit 7a6df10b39

View File

@@ -685,6 +685,16 @@ static bool report_cast_error(CastContext *cc, bool may_cast_explicit)
}
if (may_cast_explicit)
{
if (expr->type->canonical->type_kind == TYPE_DISTINCT
&& type_no_optional(to)->canonical->type_kind == TYPE_DISTINCT)
{
RETURN_CAST_ERROR(expr,
"Implicitly casting %s to %s is not permitted. It's possible to do an explicit cast by placing '(%s)' before the expression. However, usually explicit casts between distinct types are not intended and are not safe.",
type_quoted_error_string(type_no_optional(expr->type)),
type_quoted_error_string(to),
type_to_error_string(type_no_optional(to)));
}
RETURN_CAST_ERROR(expr,
"Implicitly casting %s to %s is not permitted, but you may do an explicit cast by placing '(%s)' before the expression.",
type_quoted_error_string(type_no_optional(expr->type)),