Updated error messages on failed binary arithmetic promotion.

This commit is contained in:
Christoffer Lerno
2021-07-14 23:48:43 +02:00
parent 150e205f13
commit a18f668fc4
5 changed files with 14 additions and 14 deletions

View File

@@ -265,9 +265,9 @@ static ExprFailableStatus expr_is_failable(Expr *expr)
static inline bool sema_type_error_on_binop(Expr *expr)
{
const char *c = token_type_to_string(binaryop_to_token(expr->binary_expr.operator));
SEMA_ERROR(expr, "%s is not defined in the expression '%s' %s '%s'.",
c, type_to_error_string(expr->binary_expr.left->type),
c, type_to_error_string(expr->binary_expr.right->type));
SEMA_ERROR(expr, "%s is not defined in the expression %s %s %s.",
c, type_quoted_error_string(expr->binary_expr.left->type),
c, type_quoted_error_string(expr->binary_expr.right->type));
return false;
}
@@ -3560,7 +3560,7 @@ static bool binary_arithmetic_promotion(Context *context, Expr *left, Expr *righ
{
return sema_type_error_on_binop(parent);
}
SEMA_ERROR(parent, error_message, type_to_error_string(left_type), type_to_error_string(right_type));
SEMA_ERROR(parent, error_message, type_quoted_error_string(left->type), type_quoted_error_string(right->type));
return false;
}
return cast_implicit(left, max) & cast_implicit(right, max);
@@ -3656,7 +3656,7 @@ static bool sema_expr_analyse_sub(Context *context, Type *to, Expr *expr, Expr *
}
// 7. Attempt arithmetic promotion, to promote both to a common type.
if (!binary_arithmetic_promotion(context, left, right, left_type, right_type, expr, "There is no implicit conversion available for '%s' - '%s'."))
if (!binary_arithmetic_promotion(context, left, right, left_type, right_type, expr, "The subtraction %s - %s is not possible."))
{
return false;
}
@@ -3741,7 +3741,7 @@ static bool sema_expr_analyse_add(Context *context, Type *to, Expr *expr, Expr *
}
// 4. Do an binary arithmetic promotion
if (!binary_arithmetic_promotion(context, left, right, left_type, right_type, expr, "Cannot add '%s' to '%s'"))
if (!binary_arithmetic_promotion(context, left, right, left_type, right_type, expr, "Cannot do the addition %s + %s."))
{
return false;
}
@@ -3790,7 +3790,7 @@ static bool sema_expr_analyse_mult(Context *context, Type *to, Expr *expr, Expr
Type *right_type = right->type->canonical;
// 2. Perform promotion to a common type.
if (!binary_arithmetic_promotion(context, left, right, left_type, right_type, expr, "Cannot multiply '%s' by '%s'"))
if (!binary_arithmetic_promotion(context, left, right, left_type, right_type, expr, "Cannot multiply %s by %s"))
{
return false;
}
@@ -3833,7 +3833,7 @@ static bool sema_expr_analyse_div(Context *context, Type *to, Expr *expr, Expr *
Type *right_type = right->type->canonical;
// 2. Perform promotion to a common type.
if (!binary_arithmetic_promotion(context, left, right, left_type, right_type, expr, "Cannot divide '%s' by '%s'."))
if (!binary_arithmetic_promotion(context, left, right, left_type, right_type, expr, "Cannot divide %s by %s."))
{
return false;
}
@@ -3894,7 +3894,7 @@ static bool sema_expr_analyse_mod(Context *context, Type *to, Expr *expr, Expr *
Type *right_type = right->type->canonical;
// 2. Perform promotion to a common type.
if (!binary_arithmetic_promotion(context, left, right, left_type, right_type, expr, "Cannot divide '%s' by '%s'."))
if (!binary_arithmetic_promotion(context, left, right, left_type, right_type, expr, "Cannot divide %s by %s."))
{
return false;
}
@@ -3902,7 +3902,7 @@ static bool sema_expr_analyse_mod(Context *context, Type *to, Expr *expr, Expr *
// 3. a % 0 is not valid, so detect it.
if (is_const(right) && bigint_cmp_zero(&right->const_expr.i) == CMP_EQ)
{
SEMA_ERROR(expr->binary_expr.right, "Cannot perform % with a constant zero.");
SEMA_ERROR(expr->binary_expr.right, "Cannot perform %% with a constant zero.");
return false;
}

View File

@@ -142,7 +142,7 @@ const char *type_to_error_string(Type *type)
asprintf(&buffer, "%s*", type_to_error_string(type->pointer));
return buffer;
case TYPE_STRLIT:
return "compile time string";
return "string literal";
case TYPE_ARRAY:
asprintf(&buffer, "%s[%llu]", type_to_error_string(type->array.base), (unsigned long long)type->array.len);
return buffer;

View File

@@ -5,6 +5,6 @@ func int main()
{
int a = 0;
Foo f;
f - a; // #error: There is no implicit conversion available for 'Foo' - 'int'
f - a; // #error: The subtraction 'Foo' - 'int' is not possible
return 1;
}

View File

@@ -125,7 +125,7 @@ func void test16()
func void test17()
{
int a = "test"; // #error: cast 'compile time string' to 'int'
int a = "test"; // #error: cast 'string literal' to 'int'
}
func void test18()

View File

@@ -12,6 +12,6 @@ func int foo()
enum State
{
A = foo(), // #error: Expected a constant expression for enum
B = "hello", // #error: Cannot implicitly cast 'compile time string' to 'int'
B = "hello", // #error: Cannot implicitly cast 'string literal' to 'int'
C = true, // #error: Cannot implicitly cast 'bool' to 'int'
}