aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-05-06 19:23:21 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-05-06 19:23:21 -0700
commit6131b3716322d60cf26f7aad1a654dc6c4414051 (patch)
tree4074ccc95115627bd87d319880526c5278fe7e09 /src/analyze.cpp
parent9db45ac36230c80c68af7b66827b6c73fc96c147 (diff)
downloadzig-6131b3716322d60cf26f7aad1a654dc6c4414051.tar.gz
zig-6131b3716322d60cf26f7aad1a654dc6c4414051.zip
fix eval integer wrapping and add tests
See #46
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 62938ad0fc..7b4aefc0fc 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -105,11 +105,25 @@ static AstNode *first_executing_node(AstNode *node) {
zig_unreachable();
}
+static void mark_impure_fn(BlockContext *context) {
+ if (context->fn_entry) {
+ context->fn_entry->is_pure = false;
+ }
+}
+
ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
// if this assert fails, then parseh generated code that
// failed semantic analysis, which isn't supposed to happen
assert(!node->owner->c_import_node);
+ // if an error occurs in a function then it becomes impure
+ if (node->block_context) {
+ FnTableEntry *fn_entry = node->block_context->fn_entry;
+ if (fn_entry) {
+ fn_entry->is_pure = false;
+ }
+ }
+
ErrorMsg *err = err_msg_create_with_line(node->owner->path, node->line, node->column,
node->owner->source_code, node->owner->line_offsets, msg);
@@ -2620,12 +2634,6 @@ static TypeTableEntry *analyze_slice_expr(CodeGen *g, ImportTableEntry *import,
return return_type;
}
-static void mark_impure_fn(BlockContext *context) {
- if (context->fn_entry) {
- context->fn_entry->is_pure = false;
- }
-}
-
static TypeTableEntry *analyze_array_access_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context,
AstNode *node)
{
@@ -5149,7 +5157,7 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo
}
case PrefixOpNegation:
{
- TypeTableEntry *expr_type = analyze_expression(g, import, context, expected_type, *expr_node);
+ TypeTableEntry *expr_type = analyze_expression(g, import, context, nullptr, *expr_node);
if (expr_type->id == TypeTableEntryIdInvalid) {
return expr_type;
} else if ((expr_type->id == TypeTableEntryIdInt &&
@@ -5762,6 +5770,7 @@ static TypeTableEntry *analyze_expression_pointer_only(CodeGen *g, ImportTableEn
{
assert(!expected_type || expected_type->id != TypeTableEntryIdInvalid);
TypeTableEntry *return_type = nullptr;
+ node->block_context = context;
switch (node->type) {
case NodeTypeBlock:
return_type = analyze_block_expr(g, import, context, expected_type, node);
@@ -5889,7 +5898,6 @@ static TypeTableEntry *analyze_expression_pointer_only(CodeGen *g, ImportTableEn
Expr *expr = get_resolved_expr(node);
expr->type_entry = return_type;
- node->block_context = context;
add_global_const_expr(g, node);