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/analyze.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 26c85ea68f..8e3ce507f8 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4428,6 +4428,14 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B } } + // explicit cast from integer to enum type with no payload + if (actual_type->id == TypeTableEntryIdInt && + wanted_type->id == TypeTableEntryIdEnum && + wanted_type->data.enumeration.gen_field_count == 0) + { + return resolve_cast(g, context, node, expr_node, wanted_type, CastOpIntToEnum, false); + } + add_node_error(g, node, buf_sprintf("invalid cast from type '%s' to '%s'", buf_ptr(&actual_type->name), -- cgit v1.2.3