From 49a4b1b9309de06f7a359836788dfff447003f1b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 9 Jul 2016 15:21:50 -0700 Subject: 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. --- src/eval.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/eval.cpp') diff --git a/src/eval.cpp b/src/eval.cpp index ca53388386..f7ef68467a 100644 --- a/src/eval.cpp +++ b/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; + } } } -- cgit v1.2.3