Fix bugs related to distinct types.

This commit is contained in:
Christoffer Lerno
2022-12-18 00:21:02 +01:00
parent b88e5a8079
commit 2ee2bc3129
4 changed files with 14 additions and 7 deletions

View File

@@ -1898,14 +1898,14 @@ void cast_to_max_bit_size(SemaContext *context, Expr *left, Expr *right, Type *l
Type *to = left->type->type_kind < TYPE_U8
? type_int_signed_by_bitsize(bit_size_right)
: type_int_unsigned_by_bitsize(bit_size_right);
bool success = cast_implicit(context, left, to);
bool success = cast(left, to);
assert(success);
return;
}
Type *to = right->type->type_kind < TYPE_U8
? type_int_signed_by_bitsize(bit_size_left)
: type_int_unsigned_by_bitsize(bit_size_left);
bool success = cast_implicit(context, right, to);
bool success = cast(right, to);
assert(success);
}

View File

@@ -4083,16 +4083,17 @@ static bool sema_expr_analyse_op_assign(SemaContext *context, Expr *expr, Expr *
if (!sema_expr_check_assign(context, left)) return false;
Type *no_fail = type_no_optional(left->type);
Type *flat = type_flatten_distinct(no_fail);
// 3. If this is only defined for ints (*%, ^= |= &= %=) verify that this is an int.
if (int_only && !type_is_integer(no_fail))
if (int_only && !type_is_integer(flat))
{
SEMA_ERROR(left, "Expected an integer here.");
return false;
}
// 4. In any case, these ops are only defined on numbers.
if (!type_underlying_is_numeric(no_fail))
if (!type_underlying_is_numeric(flat))
{
SEMA_ERROR(left, "Expected a numeric type here.");
return false;
@@ -5005,7 +5006,10 @@ static bool sema_expr_analyse_comp(SemaContext *context, Expr *expr, Expr *left,
}
// 6. Do the implicit cast.
bool success = cast_implicit(context, left, max) && cast_implicit(context, right, max);
bool success = true;
if (!cast_implicit(context, left, max)) success = cast(left, max);
if (!cast_implicit(context, right, max)) success = success && cast(right, max);
assert(success);
DONE:

View File

@@ -1538,6 +1538,7 @@ static inline bool sema_analyse_if_stmt(SemaContext *context, Ast *statement)
SCOPE_END;
}
if (!success) goto END;
else_jump = false;
if (statement->if_stmt.else_body)
{
@@ -1549,9 +1550,11 @@ static inline bool sema_analyse_if_stmt(SemaContext *context, Ast *statement)
SCOPE_END;
}
END:
context_pop_defers_and_replace_ast(context, statement);
SCOPE_OUTER_END;
if (!success) return false;
if (then_jump)
{
sema_unwrappable_from_catch_in_else(context, cond);
@@ -1560,7 +1563,7 @@ static inline bool sema_analyse_if_stmt(SemaContext *context, Ast *statement)
{
context->active_scope.jump_end = true;
}
return success;
return true;
}
static bool sema_analyse_asm_string_stmt(SemaContext *context, Ast *stmt)

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.3.121"
#define COMPILER_VERSION "0.3.122"