ability to cast explicitly from int to enum
This commit also fixes a bug where pure functions are marked with the read-only attribute in debug mode. This resulted in incorrect codegen because calls to read-only functions with unused values were not generated. For example, a call to assert() would not be generated if assert is marked with read-only. Which it *is* marked with in release mode.
This commit is contained in:
10
src/eval.cpp
10
src/eval.cpp
@@ -657,6 +657,16 @@ void eval_const_expr_implicit_cast(CastOp cast_op,
|
||||
bignum_init_unsigned(&const_val->data.x_bignum, other_val->data.x_bool ? 1 : 0);
|
||||
const_val->ok = true;
|
||||
break;
|
||||
case CastOpIntToEnum:
|
||||
{
|
||||
uint64_t value = other_val->data.x_bignum.data.x_uint;
|
||||
assert(new_type->id == TypeTableEntryIdEnum);
|
||||
assert(value < new_type->data.enumeration.field_count);
|
||||
const_val->data.x_enum.tag = value;
|
||||
const_val->data.x_enum.payload = NULL;
|
||||
const_val->ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user