aboutsummaryrefslogtreecommitdiff
path: root/src/stage1/ir.cpp
diff options
context:
space:
mode:
authorfrmdstryr <frmdstryr@protonmail.com>2020-10-16 13:16:09 -0400
committerVeikka Tuominen <git@vexu.eu>2020-11-18 13:33:45 +0200
commita39d3155b45cf2a1d5c91c7c82089c6f4ed7213c (patch)
tree440d851281a606c20294409a26ddbd18692b306e /src/stage1/ir.cpp
parent129ccad43443f26f00584816b18425c9a3a7b080 (diff)
downloadzig-a39d3155b45cf2a1d5c91c7c82089c6f4ed7213c.tar.gz
zig-a39d3155b45cf2a1d5c91c7c82089c6f4ed7213c.zip
Change error when runtime value passed to comptime arg
Diffstat (limited to 'src/stage1/ir.cpp')
-rw-r--r--src/stage1/ir.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp
index 1be9507480..738ef3c65d 100644
--- a/src/stage1/ir.cpp
+++ b/src/stage1/ir.cpp
@@ -6362,7 +6362,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
BuiltinFnEntry *builtin_fn = entry->value;
size_t actual_param_count = node->data.fn_call_expr.params.length;
- if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) {
+ if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) {
add_node_error(irb->codegen, node,
buf_sprintf("expected %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize,
builtin_fn->param_count, actual_param_count));
@@ -8576,7 +8576,7 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod
if (is_duplicate_label(irb->codegen, child_scope, node, node->data.for_expr.name))
return irb->codegen->invalid_inst_src;
-
+
ZigList<IrInstSrc *> incoming_values = {0};
ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
@@ -20068,6 +20068,11 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
ZigValue *arg_val;
+ if (comptime_arg && !instr_is_comptime(casted_arg)) {
+ ir_add_error(ira, &casted_arg->base,
+ buf_sprintf("runtime value cannot be passed to comptime arg"));
+ return false;
+ }
if (comptime_arg) {
arg_part_of_generic_id = true;
arg_val = ir_resolve_const(ira, casted_arg, UndefBad);
@@ -20854,7 +20859,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
expected_return_type->id != ZigTypeIdErrorUnion && expected_return_type->id != ZigTypeIdErrorSet)
{
if (call_result_loc->id == ResultLocIdReturn) {
- add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg,
+ add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg,
ira->explicit_return_type_source_node, buf_sprintf("function cannot return an error"));
} else {
add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, result_loc->base.source_node,
@@ -29490,7 +29495,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
}
}
} else if(!switch_type->data.enumeration.non_exhaustive && switch_type->data.enumeration.src_field_count == instruction->range_count) {
- ir_add_error_node(ira, instruction->else_prong,
+ ir_add_error_node(ira, instruction->else_prong,
buf_sprintf("unreachable else prong, all cases already handled"));
return ira->codegen->invalid_inst_gen;
}
@@ -29611,7 +29616,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
return ira->codegen->invalid_inst_gen;
} else if(handles_all_cases && instruction->else_prong != nullptr) {
- ir_add_error_node(ira, instruction->else_prong,
+ ir_add_error_node(ira, instruction->else_prong,
buf_sprintf("unreachable else prong, all cases already handled"));
return ira->codegen->invalid_inst_gen;
}
@@ -29650,7 +29655,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
}
if(seenTrue == 1 && seenFalse == 1 && instruction->else_prong != nullptr) {
- ir_add_error_node(ira, instruction->else_prong,
+ ir_add_error_node(ira, instruction->else_prong,
buf_sprintf("unreachable else prong, all cases already handled"));
return ira->codegen->invalid_inst_gen;
}
@@ -29688,7 +29693,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
}
}
prevs.deinit();
- }
+ }
return ir_const_void(ira, &instruction->base.base);
}