From 06f2f4d64b63cf78a3ff77cc64dbc822123f454d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 13 Sep 2016 16:46:27 -0400 Subject: change `unreachable{}` to `@unreachable()` instead of a container init expression, it's a builtin function call. --- src/eval.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/eval.cpp') diff --git a/src/eval.cpp b/src/eval.cpp index 1e71fd262b..79d3079adc 100644 --- a/src/eval.cpp +++ b/src/eval.cpp @@ -491,13 +491,6 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue * } } else if (container_type->id == TypeTableEntryIdVoid) { return false; - } else if (container_type->id == TypeTableEntryIdUnreachable) { - ef->root->abort = true; - ErrorMsg *msg = add_node_error(ef->root->codegen, ef->root->fn->fn_def_node, - buf_sprintf("function evaluation reached unreachable expression")); - add_error_note(ef->root->codegen, msg, ef->root->call_node, buf_sprintf("called from here")); - add_error_note(ef->root->codegen, msg, node, buf_sprintf("unreachable expression here")); - return true; } else if (container_type->id == TypeTableEntryIdStruct && container_type->data.structure.is_slice && kind == ContainerInitKindArray) @@ -791,6 +784,15 @@ static bool eval_div_exact(EvalFn *ef, AstNode *node, ConstExprValue *out_val) { return false; } +static bool eval_unreachable(EvalFn *ef, AstNode *node, ConstExprValue *out_val) { + ef->root->abort = true; + ErrorMsg *msg = add_node_error(ef->root->codegen, ef->root->fn->fn_def_node, + buf_sprintf("function evaluation reached unreachable expression")); + add_error_note(ef->root->codegen, msg, ef->root->call_node, buf_sprintf("called from here")); + add_error_note(ef->root->codegen, msg, node, buf_sprintf("unreachable expression here")); + return true; +} + static bool eval_fn_with_overflow(EvalFn *ef, AstNode *node, ConstExprValue *out_val, bool (*bignum_fn)(BigNum *dest, BigNum *op1, BigNum *op2)) { @@ -851,6 +853,8 @@ static bool eval_fn_call_builtin(EvalFn *ef, AstNode *node, ConstExprValue *out_ return false; case BuiltinFnIdDivExact: return eval_div_exact(ef, node, out_val); + case BuiltinFnIdUnreachable: + return eval_unreachable(ef, node, out_val); case BuiltinFnIdMemcpy: case BuiltinFnIdMemset: case BuiltinFnIdSizeof: -- cgit v1.2.3