diff --git a/self_hosted/typecheck.jou b/self_hosted/typecheck.jou index 368f6b64..2b9d18f5 100644 --- a/self_hosted/typecheck.jou +++ b/self_hosted/typecheck.jou @@ -43,8 +43,9 @@ def can_cast_implicitly(from: Type*, to: Type*) -> bool: ) def can_cast_explicitly(from: Type*, to: Type*) -> bool: - return from != to and ( - (from->kind == TypeKind::Array and to->kind == TypeKind::Pointer and from->array.item_type == to->value_type) + return ( + from == to + or (from->kind == TypeKind::Array and to->kind == TypeKind::Pointer and from->array.item_type == to->value_type) or (from->is_pointer_type() and to->is_pointer_type()) or (from->is_number_type() and to->is_number_type()) or (from->is_integer_type() and to->kind == TypeKind::Enum) @@ -177,10 +178,7 @@ class ExpressionTypes: from = self->original_type if not can_cast_explicitly(from, to): message: byte[500] - if from == to: - snprintf(message, sizeof message, "unnecessary cast from %s to %s", from->name, to->name) - else: - snprintf(message, sizeof message, "cannot cast from type %s to %s", from->name, to->name) + snprintf(&message[0], sizeof message, "cannot cast from type %s to %s", from->name, to->name) fail(error_location, message) if from->kind == TypeKind::Array and to->is_pointer_type():