authorgravatar for kris.tate+github@gmail.comkristopher tate <kris.tate+github@gmail.com> 2019-01-26 05:10:40+09:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-01-25 21:10:40+01:00
log5bf9ffdc5be02e67b57fe9398ad9d13147bfb0c8
treef8c68dbdabe3534f80134f755ec4b1ff007bdc22
parent3bec3b9f9ba49bbc2e7244737c50bdbaa12a6b14

Hint at use of and/or when &&/|| is improperly used (#1886)


6 files changed, 226 insertions(+), 196 deletions(-)

doc/langref.html.in+1-1
...@@ -6024,7 +6024,7 @@ fn add(a: i32, b: i32) i32 {...@@ -6024,7 +6024,7 @@ fn add(a: i32, b: i32) i32 {
6024 This is typically used for type safety when interacting with C code that does not expose struct details.6024 This is typically used for type safety when interacting with C code that does not expose struct details.
6025 Example:6025 Example:
6026 </p>6026 </p>
6027 {#code_begin|test_err|expected type '*Derp', found '*Wat'#}6027 {#code_begin|test_err|expected '*Derp' type, found '*Wat'#}
6028const Derp = @OpaqueType();6028const Derp = @OpaqueType();
6029const Wat = @OpaqueType();6029const Wat = @OpaqueType();
60306030
src/ir.cpp+95-132
...@@ -9771,13 +9771,19 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node...@@ -9771,13 +9771,19 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
9771 return ir_exec_const_result(codegen, analyzed_executable);9771 return ir_exec_const_result(codegen, analyzed_executable);
9772}9772}
97739773
9774static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {9774static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value, ZigTypeId wanted_type) {
9775 if (type_is_invalid(type_value->value.type))9775 if (type_is_invalid(type_value->value.type))
9776 return ira->codegen->builtin_types.entry_invalid;9776 return ira->codegen->builtin_types.entry_invalid;
97779777
9778 const char *expected_type_str = type_id_name(ZigTypeIdMetaType);
9779
9780 if (wanted_type != ZigTypeIdInvalid) {
9781 expected_type_str = type_id_name(wanted_type);
9782 }
9783
9778 if (type_value->value.type->id != ZigTypeIdMetaType) {9784 if (type_value->value.type->id != ZigTypeIdMetaType) {
9779 ir_add_error(ira, type_value,9785 ir_add_error( ira, type_value,
9780 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name)));9786 buf_sprintf("expected %s type, found '%s'", expected_type_str, buf_ptr(&type_value->value.type->name)));
9781 return ira->codegen->builtin_types.entry_invalid;9787 return ira->codegen->builtin_types.entry_invalid;
9782 }9788 }
97839789
...@@ -9786,7 +9792,16 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {...@@ -9786,7 +9792,16 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
9786 return ira->codegen->builtin_types.entry_invalid;9792 return ira->codegen->builtin_types.entry_invalid;
97879793
9788 assert(const_val->data.x_type != nullptr);9794 assert(const_val->data.x_type != nullptr);
9789 return const_val->data.x_type;9795
9796 ZigType *out_type = const_val->data.x_type;
9797
9798 if (wanted_type != ZigTypeIdInvalid && out_type->id != wanted_type) {
9799 ir_add_error(ira, type_value,
9800 buf_sprintf( "expected %s type, found '%s'", expected_type_str, buf_ptr(&out_type->name)));
9801 return ira->codegen->builtin_types.entry_invalid;
9802 }
9803
9804 return out_type;
9790}9805}
97919806
9792static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {9807static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
...@@ -10986,7 +11001,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10986,7 +11001,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10986 }11001 }
1098711002
10988 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,11003 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
10989 buf_sprintf("expected type '%s', found '%s'",11004 buf_sprintf("expected '%s' type, found '%s'",
10990 buf_ptr(&wanted_type->name),11005 buf_ptr(&wanted_type->name),
10991 buf_ptr(&actual_type->name)));11006 buf_ptr(&actual_type->name)));
10992 report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg);11007 report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg);
...@@ -12214,7 +12229,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -12214,7 +12229,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
12214 size_t op2_array_end;12229 size_t op2_array_end;
12215 if (op2_type->id == ZigTypeIdArray) {12230 if (op2_type->id == ZigTypeIdArray) {
12216 if (op2_type->data.array.child_type != child_type) {12231 if (op2_type->data.array.child_type != child_type) {
12217 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",12232 ir_add_error(ira, op2, buf_sprintf("expected array of '%s' type, found '%s'",
12218 buf_ptr(&child_type->name),12233 buf_ptr(&child_type->name),
12219 buf_ptr(&op2->value.type->name)));12234 buf_ptr(&op2->value.type->name)));
12220 return ira->codegen->invalid_instruction;12235 return ira->codegen->invalid_instruction;
...@@ -12228,7 +12243,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -12228,7 +12243,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
12228 op2_val->data.x_ptr.data.base_array.is_cstr)12243 op2_val->data.x_ptr.data.base_array.is_cstr)
12229 {12244 {
12230 if (child_type != ira->codegen->builtin_types.entry_u8) {12245 if (child_type != ira->codegen->builtin_types.entry_u8) {
12231 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",12246 ir_add_error(ira, op2, buf_sprintf("expected array of '%s' type, found '%s'",
12232 buf_ptr(&child_type->name),12247 buf_ptr(&child_type->name),
12233 buf_ptr(&op2->value.type->name)));12248 buf_ptr(&op2->value.type->name)));
12234 return ira->codegen->invalid_instruction;12249 return ira->codegen->invalid_instruction;
...@@ -12239,7 +12254,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -12239,7 +12254,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
12239 } else if (is_slice(op2_type)) {12254 } else if (is_slice(op2_type)) {
12240 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;12255 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;
12241 if (ptr_type->data.pointer.child_type != child_type) {12256 if (ptr_type->data.pointer.child_type != child_type) {
12242 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",12257 ir_add_error(ira, op2, buf_sprintf("expected array of '%s' type, found '%s'",
12243 buf_ptr(&child_type->name),12258 buf_ptr(&child_type->name),
12244 buf_ptr(&op2->value.type->name)));12259 buf_ptr(&op2->value.type->name)));
12245 return ira->codegen->invalid_instruction;12260 return ira->codegen->invalid_instruction;
...@@ -12253,7 +12268,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -12253,7 +12268,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
12253 op2_array_end = bigint_as_unsigned(&len_val->data.x_bigint);12268 op2_array_end = bigint_as_unsigned(&len_val->data.x_bigint);
12254 } else {12269 } else {
12255 ir_add_error(ira, op2,12270 ir_add_error(ira, op2,
12256 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name)));12271 buf_sprintf("expected array or C string literal type, found '%s'", buf_ptr(&op2->value.type->name)));
12257 return ira->codegen->invalid_instruction;12272 return ira->codegen->invalid_instruction;
12258 }12273 }
1225912274
...@@ -12388,26 +12403,22 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -12388,26 +12403,22 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
12388}12403}
1238912404
12390static IrInstruction *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) {12405static IrInstruction *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) {
12391 ZigType *op1_type = ir_resolve_type(ira, instruction->op1->child);12406 ZigType *op1_type = ir_resolve_type(ira, instruction->op1->child, ZigTypeIdErrorSet);
12392 if (type_is_invalid(op1_type))12407 if (type_is_invalid(op1_type)) {
12393 return ira->codegen->invalid_instruction;12408 if (ira->codegen->errors.length != 0) {
1239412409 add_error_note( ira->codegen
12395 if (op1_type->id != ZigTypeIdErrorSet) {12410 , ira->codegen->errors.last()
12396 ir_add_error(ira, instruction->op1,12411 , instruction->base.source_node
12397 buf_sprintf("expected error set type, found '%s'", buf_ptr(&op1_type->name)));12412 , buf_sprintf("did you mean to use `or`?")
12413 );
12414 }
12398 return ira->codegen->invalid_instruction;12415 return ira->codegen->invalid_instruction;
12399 }12416 }
1240012417
12401 ZigType *op2_type = ir_resolve_type(ira, instruction->op2->child);12418 ZigType *op2_type = ir_resolve_type(ira, instruction->op2->child, ZigTypeIdErrorSet);
12402 if (type_is_invalid(op2_type))12419 if (type_is_invalid(op2_type))
12403 return ira->codegen->invalid_instruction;12420 return ira->codegen->invalid_instruction;
1240412421
12405 if (op2_type->id != ZigTypeIdErrorSet) {
12406 ir_add_error(ira, instruction->op2,
12407 buf_sprintf("expected error set type, found '%s'", buf_ptr(&op2_type->name)));
12408 return ira->codegen->invalid_instruction;
12409 }
12410
12411 if (type_is_global_error_set(op1_type) ||12422 if (type_is_global_error_set(op1_type) ||
12412 type_is_global_error_set(op2_type))12423 type_is_global_error_set(op2_type))
12413 {12424 {
...@@ -12495,7 +12506,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruct...@@ -12495,7 +12506,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruct
12495 IrInstruction *var_type = nullptr;12506 IrInstruction *var_type = nullptr;
12496 if (decl_var_instruction->var_type != nullptr) {12507 if (decl_var_instruction->var_type != nullptr) {
12497 var_type = decl_var_instruction->var_type->child;12508 var_type = decl_var_instruction->var_type->child;
12498 ZigType *proposed_type = ir_resolve_type(ira, var_type);12509 ZigType *proposed_type = ir_resolve_type(ira, var_type, ZigTypeIdInvalid);
12499 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);12510 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);
12500 if (type_is_invalid(explicit_type)) {12511 if (type_is_invalid(explicit_type)) {
12501 var->value->type = ira->codegen->builtin_types.entry_invalid;12512 var->value->type = ira->codegen->builtin_types.entry_invalid;
...@@ -12824,21 +12835,14 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,...@@ -12824,21 +12835,14 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
12824{12835{
12825 Error err;12836 Error err;
1282612837
12827 ZigType *err_set_type = ir_resolve_type(ira, instruction->err_set->child);12838 ZigType *err_set_type = ir_resolve_type(ira, instruction->err_set->child, ZigTypeIdErrorSet);
12828 if (type_is_invalid(err_set_type))12839 if (type_is_invalid(err_set_type))
12829 return ira->codegen->invalid_instruction;12840 return ira->codegen->invalid_instruction;
1283012841
12831 ZigType *payload_type = ir_resolve_type(ira, instruction->payload->child);12842 ZigType *payload_type = ir_resolve_type(ira, instruction->payload->child, ZigTypeIdInvalid);
12832 if (type_is_invalid(payload_type))12843 if (type_is_invalid(payload_type))
12833 return ira->codegen->invalid_instruction;12844 return ira->codegen->invalid_instruction;
1283412845
12835 if (err_set_type->id != ZigTypeIdErrorSet) {
12836 ir_add_error(ira, instruction->err_set->child,
12837 buf_sprintf("expected error set type, found type '%s'",
12838 buf_ptr(&err_set_type->name)));
12839 return ira->codegen->invalid_instruction;
12840 }
12841
12842 if ((err = type_resolve(ira->codegen, payload_type, ResolveStatusSizeKnown)))12846 if ((err = type_resolve(ira->codegen, payload_type, ResolveStatusSizeKnown)))
12843 return ira->codegen->invalid_instruction;12847 return ira->codegen->invalid_instruction;
12844 ZigType *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type);12848 ZigType *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type);
...@@ -12900,7 +12904,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c...@@ -12900,7 +12904,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c
12900 ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;12904 ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;
12901 if (alloc_fn_type->id != ZigTypeIdFn) {12905 if (alloc_fn_type->id != ZigTypeIdFn) {
12902 ir_add_error(ira, &call_instruction->base,12906 ir_add_error(ira, &call_instruction->base,
12903 buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name)));12907 buf_sprintf("expected allocation function type, found '%s'", buf_ptr(&alloc_fn_type->name)));
12904 return ira->codegen->invalid_instruction;12908 return ira->codegen->invalid_instruction;
12905 }12909 }
1290612910
...@@ -13692,7 +13696,7 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC...@@ -13692,7 +13696,7 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1369213696
13693 if (is_comptime || instr_is_comptime(fn_ref)) {13697 if (is_comptime || instr_is_comptime(fn_ref)) {
13694 if (fn_ref->value.type->id == ZigTypeIdMetaType) {13698 if (fn_ref->value.type->id == ZigTypeIdMetaType) {
13695 ZigType *dest_type = ir_resolve_type(ira, fn_ref);13699 ZigType *dest_type = ir_resolve_type(ira, fn_ref, ZigTypeIdInvalid);
13696 if (type_is_invalid(dest_type))13700 if (type_is_invalid(dest_type))
13697 return ira->codegen->invalid_instruction;13701 return ira->codegen->invalid_instruction;
1369813702
...@@ -13817,7 +13821,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -13817,7 +13821,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
13817static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {13821static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
13818 Error err;13822 Error err;
13819 IrInstruction *value = un_op_instruction->value->child;13823 IrInstruction *value = un_op_instruction->value->child;
13820 ZigType *type_entry = ir_resolve_type(ira, value);13824 ZigType *type_entry = ir_resolve_type(ira, value, ZigTypeIdInvalid);
13821 if (type_is_invalid(type_entry))13825 if (type_is_invalid(type_entry))
13822 return ira->codegen->invalid_instruction;13826 return ira->codegen->invalid_instruction;
13823 if ((err = ensure_complete_type(ira->codegen, type_entry)))13827 if ((err = ensure_complete_type(ira->codegen, type_entry)))
...@@ -15300,16 +15304,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,...@@ -15300,16 +15304,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
15300 IrInstructionPtrTypeChild *ptr_type_child_instruction)15304 IrInstructionPtrTypeChild *ptr_type_child_instruction)
15301{15305{
15302 IrInstruction *type_value = ptr_type_child_instruction->value->child;15306 IrInstruction *type_value = ptr_type_child_instruction->value->child;
15303 ZigType *type_entry = ir_resolve_type(ira, type_value);15307 ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdPointer);
15304 if (type_is_invalid(type_entry))15308 if (type_is_invalid(type_entry))
15305 return ira->codegen->invalid_instruction;15309 return ira->codegen->invalid_instruction;
1530615310
15307 if (type_entry->id != ZigTypeIdPointer) {
15308 ir_add_error_node(ira, ptr_type_child_instruction->base.source_node,
15309 buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));
15310 return ira->codegen->invalid_instruction;
15311 }
15312
15313 return ir_const_type(ira, &ptr_type_child_instruction->base, type_entry->data.pointer.child_type);15311 return ir_const_type(ira, &ptr_type_child_instruction->base, type_entry->data.pointer.child_type);
15314}15312}
1531515313
...@@ -15462,7 +15460,7 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -15462,7 +15460,7 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
15462 return ira->codegen->invalid_instruction;15460 return ira->codegen->invalid_instruction;
15463 }15461 }
1546415462
15465 ZigType *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->child);15463 ZigType *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->child, ZigTypeIdInvalid);
15466 if (type_is_invalid(child_type))15464 if (type_is_invalid(child_type))
15467 return ira->codegen->invalid_instruction;15465 return ira->codegen->invalid_instruction;
1546815466
...@@ -15545,7 +15543,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs...@@ -15545,7 +15543,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
15545 AsmOutput *asm_output = asm_expr->output_list.at(i);15543 AsmOutput *asm_output = asm_expr->output_list.at(i);
15546 if (asm_output->return_type) {15544 if (asm_output->return_type) {
15547 output_types[i] = asm_instruction->output_types[i]->child;15545 output_types[i] = asm_instruction->output_types[i]->child;
15548 return_type = ir_resolve_type(ira, output_types[i]);15546 return_type = ir_resolve_type(ira, output_types[i], ZigTypeIdInvalid);
15549 if (type_is_invalid(return_type))15547 if (type_is_invalid(return_type))
15550 return ira->codegen->invalid_instruction;15548 return ira->codegen->invalid_instruction;
15551 }15549 }
...@@ -15560,7 +15558,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs...@@ -15560,7 +15558,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
15560 (input_value->value.type->id == ZigTypeIdComptimeInt ||15558 (input_value->value.type->id == ZigTypeIdComptimeInt ||
15561 input_value->value.type->id == ZigTypeIdComptimeFloat)) {15559 input_value->value.type->id == ZigTypeIdComptimeFloat)) {
15562 ir_add_error_node(ira, input_value->source_node,15560 ir_add_error_node(ira, input_value->source_node,
15563 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value.type->name)));15561 buf_sprintf("expected sized integer or sized float type, found %s", buf_ptr(&input_value->value.type->name)));
15564 return ira->codegen->invalid_instruction;15562 return ira->codegen->invalid_instruction;
15565 }15563 }
1556615564
...@@ -15586,7 +15584,7 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -15586,7 +15584,7 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
15586 return ira->codegen->invalid_instruction;15584 return ira->codegen->invalid_instruction;
1558715585
15588 IrInstruction *child_type_value = array_type_instruction->child_type->child;15586 IrInstruction *child_type_value = array_type_instruction->child_type->child;
15589 ZigType *child_type = ir_resolve_type(ira, child_type_value);15587 ZigType *child_type = ir_resolve_type(ira, child_type_value, ZigTypeIdInvalid);
15590 if (type_is_invalid(child_type))15588 if (type_is_invalid(child_type))
15591 return ira->codegen->invalid_instruction;15589 return ira->codegen->invalid_instruction;
15592 switch (child_type->id) {15590 switch (child_type->id) {
...@@ -15635,7 +15633,7 @@ static IrInstruction *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInst...@@ -15635,7 +15633,7 @@ static IrInstruction *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInst
15635 if (instruction->payload_type == nullptr) {15633 if (instruction->payload_type == nullptr) {
15636 promise_type = ira->codegen->builtin_types.entry_promise;15634 promise_type = ira->codegen->builtin_types.entry_promise;
15637 } else {15635 } else {
15638 ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->child);15636 ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->child, ZigTypeIdInvalid);
15639 if (type_is_invalid(payload_type))15637 if (type_is_invalid(payload_type))
15640 return ira->codegen->invalid_instruction;15638 return ira->codegen->invalid_instruction;
1564115639
...@@ -15650,7 +15648,7 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,...@@ -15650,7 +15648,7 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,
15650{15648{
15651 Error err;15649 Error err;
15652 IrInstruction *type_value = size_of_instruction->type_value->child;15650 IrInstruction *type_value = size_of_instruction->type_value->child;
15653 ZigType *type_entry = ir_resolve_type(ira, type_value);15651 ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdInvalid);
1565415652
15655 if ((err = ensure_complete_type(ira->codegen, type_entry)))15653 if ((err = ensure_complete_type(ira->codegen, type_entry)))
15656 return ira->codegen->invalid_instruction;15654 return ira->codegen->invalid_instruction;
...@@ -16485,7 +16483,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16485,7 +16483,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1648516483
16486 size_t elem_count = instruction->item_count;16484 size_t elem_count = instruction->item_count;
16487 if (container_type_value->value.type->id == ZigTypeIdMetaType) {16485 if (container_type_value->value.type->id == ZigTypeIdMetaType) {
16488 ZigType *container_type = ir_resolve_type(ira, container_type_value);16486 ZigType *container_type = ir_resolve_type(ira, container_type_value, ZigTypeIdInvalid);
16489 if (type_is_invalid(container_type))16487 if (type_is_invalid(container_type))
16490 return ira->codegen->invalid_instruction;16488 return ira->codegen->invalid_instruction;
1649116489
...@@ -16601,7 +16599,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16601,7 +16599,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1660116599
16602static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) {16600static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) {
16603 IrInstruction *container_type_value = instruction->container_type->child;16601 IrInstruction *container_type_value = instruction->container_type->child;
16604 ZigType *container_type = ir_resolve_type(ira, container_type_value);16602 ZigType *container_type = ir_resolve_type(ira, container_type_value, ZigTypeIdInvalid);
16605 if (type_is_invalid(container_type))16603 if (type_is_invalid(container_type))
16606 return ira->codegen->invalid_instruction;16604 return ira->codegen->invalid_instruction;
1660716605
...@@ -16719,7 +16717,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16719,7 +16717,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16719{16717{
16720 Error err;16718 Error err;
16721 IrInstruction *type_value = instruction->type_value->child;16719 IrInstruction *type_value = instruction->type_value->child;
16722 ZigType *container_type = ir_resolve_type(ira, type_value);16720 ZigType *container_type = ir_resolve_type(ira, type_value, ZigTypeIdStruct);
16723 if (type_is_invalid(container_type))16721 if (type_is_invalid(container_type))
16724 return ira->codegen->invalid_instruction;16722 return ira->codegen->invalid_instruction;
1672516723
...@@ -16732,12 +16730,6 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16732,12 +16730,6 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16732 if (type_is_invalid(field_ptr->value.type))16730 if (type_is_invalid(field_ptr->value.type))
16733 return ira->codegen->invalid_instruction;16731 return ira->codegen->invalid_instruction;
1673416732
16735 if (container_type->id != ZigTypeIdStruct) {
16736 ir_add_error(ira, type_value,
16737 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
16738 return ira->codegen->invalid_instruction;
16739 }
16740
16741 if ((err = ensure_complete_type(ira->codegen, container_type)))16733 if ((err = ensure_complete_type(ira->codegen, container_type)))
16742 return ira->codegen->invalid_instruction;16734 return ira->codegen->invalid_instruction;
1674316735
...@@ -16751,7 +16743,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16751,7 +16743,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1675116743
16752 if (field_ptr->value.type->id != ZigTypeIdPointer) {16744 if (field_ptr->value.type->id != ZigTypeIdPointer) {
16753 ir_add_error(ira, field_ptr,16745 ir_add_error(ira, field_ptr,
16754 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name)));16746 buf_sprintf("expected Pointer type, found '%s'", buf_ptr(&field_ptr->value.type->name)));
16755 return ira->codegen->invalid_instruction;16747 return ira->codegen->invalid_instruction;
16756 }16748 }
1675716749
...@@ -16810,9 +16802,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16810,9 +16802,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16810static TypeStructField *validate_byte_offset(IrAnalyze *ira,16802static TypeStructField *validate_byte_offset(IrAnalyze *ira,
16811 IrInstruction *type_value,16803 IrInstruction *type_value,
16812 IrInstruction *field_name_value,16804 IrInstruction *field_name_value,
16813 size_t *byte_offset) 16805 size_t *byte_offset)
16814{16806{
16815 ZigType *container_type = ir_resolve_type(ira, type_value);16807 ZigType *container_type = ir_resolve_type(ira, type_value, ZigTypeIdStruct);
16816 if (type_is_invalid(container_type))16808 if (type_is_invalid(container_type))
16817 return nullptr;16809 return nullptr;
1681816810
...@@ -16824,12 +16816,6 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,...@@ -16824,12 +16816,6 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
16824 if (!field_name)16816 if (!field_name)
16825 return nullptr;16817 return nullptr;
1682616818
16827 if (container_type->id != ZigTypeIdStruct) {
16828 ir_add_error(ira, type_value,
16829 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
16830 return nullptr;
16831 }
16832
16833 TypeStructField *field = find_struct_type_field(container_type, field_name);16819 TypeStructField *field = find_struct_type_field(container_type, field_name);
16834 if (field == nullptr) {16820 if (field == nullptr) {
16835 ir_add_error(ira, field_name_value,16821 ir_add_error(ira, field_name_value,
...@@ -17807,7 +17793,7 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -17807,7 +17793,7 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
17807{17793{
17808 Error err;17794 Error err;
17809 IrInstruction *type_value = instruction->type_value->child;17795 IrInstruction *type_value = instruction->type_value->child;
17810 ZigType *type_entry = ir_resolve_type(ira, type_value);17796 ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdInvalid);
17811 if (type_is_invalid(type_entry))17797 if (type_is_invalid(type_entry))
17812 return ira->codegen->invalid_instruction;17798 return ira->codegen->invalid_instruction;
1781317799
...@@ -17835,7 +17821,7 @@ static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,...@@ -17835,7 +17821,7 @@ static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,
17835 IrInstructionTypeId *instruction)17821 IrInstructionTypeId *instruction)
17836{17822{
17837 IrInstruction *type_value = instruction->type_value->child;17823 IrInstruction *type_value = instruction->type_value->child;
17838 ZigType *type_entry = ir_resolve_type(ira, type_value);17824 ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdInvalid);
17839 if (type_is_invalid(type_entry))17825 if (type_is_invalid(type_entry))
17840 return ira->codegen->invalid_instruction;17826 return ira->codegen->invalid_instruction;
1784117827
...@@ -17870,7 +17856,7 @@ static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ir...@@ -17870,7 +17856,7 @@ static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ir
1787017856
17871static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {17857static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
17872 IrInstruction *type_value = instruction->type_value->child;17858 IrInstruction *type_value = instruction->type_value->child;
17873 ZigType *type_entry = ir_resolve_type(ira, type_value);17859 ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdInvalid);
17874 if (type_is_invalid(type_entry))17860 if (type_is_invalid(type_entry))
17875 return ira->codegen->invalid_instruction;17861 return ira->codegen->invalid_instruction;
1787617862
...@@ -18147,7 +18133,7 @@ static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstruction...@@ -18147,7 +18133,7 @@ static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstruction
1814718133
18148static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {18134static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {
18149 IrInstruction *dest_type_value = instruction->dest_type->child;18135 IrInstruction *dest_type_value = instruction->dest_type->child;
18150 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);18136 ZigType *dest_type = ir_resolve_type(ira, dest_type_value, ZigTypeIdInvalid);
18151 if (type_is_invalid(dest_type))18137 if (type_is_invalid(dest_type))
18152 return ira->codegen->invalid_instruction;18138 return ira->codegen->invalid_instruction;
1815318139
...@@ -18200,7 +18186,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct...@@ -18200,7 +18186,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
18200}18186}
1820118187
18202static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {18188static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {
18203 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);18189 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child, ZigTypeIdInvalid);
18204 if (type_is_invalid(dest_type))18190 if (type_is_invalid(dest_type))
18205 return ira->codegen->invalid_instruction;18191 return ira->codegen->invalid_instruction;
1820618192
...@@ -18233,7 +18219,7 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct...@@ -18233,7 +18219,7 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct
18233}18219}
1823418220
18235static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {18221static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {
18236 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);18222 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child, ZigTypeIdInvalid);
18237 if (type_is_invalid(dest_type))18223 if (type_is_invalid(dest_type))
18238 return ira->codegen->invalid_instruction;18224 return ira->codegen->invalid_instruction;
1823918225
...@@ -18273,16 +18259,10 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru...@@ -18273,16 +18259,10 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
18273}18259}
1827418260
18275static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {18261static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {
18276 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);18262 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child, ZigTypeIdErrorSet);
18277 if (type_is_invalid(dest_type))18263 if (type_is_invalid(dest_type))
18278 return ira->codegen->invalid_instruction;18264 return ira->codegen->invalid_instruction;
1827918265
18280 if (dest_type->id != ZigTypeIdErrorSet) {
18281 ir_add_error(ira, instruction->dest_type,
18282 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
18283 return ira->codegen->invalid_instruction;
18284 }
18285
18286 IrInstruction *target = instruction->target->child;18266 IrInstruction *target = instruction->target->child;
18287 if (type_is_invalid(target->value.type))18267 if (type_is_invalid(target->value.type))
18288 return ira->codegen->invalid_instruction;18268 return ira->codegen->invalid_instruction;
...@@ -18311,7 +18291,7 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali...@@ -18311,7 +18291,7 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali
18311static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {18291static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {
18312 Error err;18292 Error err;
1831318293
18314 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child);18294 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child, ZigTypeIdInvalid);
18315 if (type_is_invalid(dest_child_type))18295 if (type_is_invalid(dest_child_type))
18316 return ira->codegen->invalid_instruction;18296 return ira->codegen->invalid_instruction;
1831718297
...@@ -18408,7 +18388,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct...@@ -18408,7 +18388,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
1840818388
18409 if (!is_slice(target->value.type)) {18389 if (!is_slice(target->value.type)) {
18410 ir_add_error(ira, instruction->target,18390 ir_add_error(ira, instruction->target,
18411 buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value.type->name)));18391 buf_sprintf("expected slice type, found '%s'", buf_ptr(&target->value.type->name)));
18412 return ira->codegen->invalid_instruction;18392 return ira->codegen->invalid_instruction;
18413 }18393 }
1841418394
...@@ -18427,7 +18407,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct...@@ -18427,7 +18407,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
18427}18407}
1842818408
18429static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {18409static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {
18430 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);18410 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child, ZigTypeIdInvalid);
18431 if (type_is_invalid(dest_type))18411 if (type_is_invalid(dest_type))
18432 return ira->codegen->invalid_instruction;18412 return ira->codegen->invalid_instruction;
1843318413
...@@ -18445,7 +18425,7 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst...@@ -18445,7 +18425,7 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst
18445}18425}
1844618426
18447static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {18427static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
18448 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);18428 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child, ZigTypeIdInvalid);
18449 if (type_is_invalid(dest_type))18429 if (type_is_invalid(dest_type))
18450 return ira->codegen->invalid_instruction;18430 return ira->codegen->invalid_instruction;
1845118431
...@@ -18501,7 +18481,7 @@ static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstr...@@ -18501,7 +18481,7 @@ static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstr
18501 return ira->codegen->invalid_instruction;18481 return ira->codegen->invalid_instruction;
1850218482
18503 if (target->value.type->id != ZigTypeIdBool) {18483 if (target->value.type->id != ZigTypeIdBool) {
18504 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",18484 ir_add_error(ira, instruction->target, buf_sprintf("expected bool type, found '%s'",
18505 buf_ptr(&target->value.type->name)));18485 buf_ptr(&target->value.type->name)));
18506 return ira->codegen->invalid_instruction;18486 return ira->codegen->invalid_instruction;
18507 }18487 }
...@@ -19082,7 +19062,7 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst...@@ -19082,7 +19062,7 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst
19082 IrInstruction *container = instruction->container->child;19062 IrInstruction *container = instruction->container->child;
19083 if (type_is_invalid(container->value.type))19063 if (type_is_invalid(container->value.type))
19084 return ira->codegen->invalid_instruction;19064 return ira->codegen->invalid_instruction;
19085 ZigType *container_type = ir_resolve_type(ira, container);19065 ZigType *container_type = ir_resolve_type(ira, container, ZigTypeIdInvalid);
1908619066
19087 if ((err = ensure_complete_type(ira->codegen, container_type)))19067 if ((err = ensure_complete_type(ira->codegen, container_type)))
19088 return ira->codegen->invalid_instruction;19068 return ira->codegen->invalid_instruction;
...@@ -19116,7 +19096,7 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst...@@ -19116,7 +19096,7 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst
19116static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {19096static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {
19117 Error err;19097 Error err;
19118 IrInstruction *container_type_value = instruction->container_type->child;19098 IrInstruction *container_type_value = instruction->container_type->child;
19119 ZigType *container_type = ir_resolve_type(ira, container_type_value);19099 ZigType *container_type = ir_resolve_type(ira, container_type_value, ZigTypeIdInvalid);
19120 if (type_is_invalid(container_type))19100 if (type_is_invalid(container_type))
19121 return ira->codegen->invalid_instruction;19101 return ira->codegen->invalid_instruction;
1912219102
...@@ -19159,7 +19139,7 @@ static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstr...@@ -19159,7 +19139,7 @@ static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstr
19159static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {19139static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {
19160 Error err;19140 Error err;
19161 IrInstruction *container_type_value = instruction->container_type->child;19141 IrInstruction *container_type_value = instruction->container_type->child;
19162 ZigType *container_type = ir_resolve_type(ira, container_type_value);19142 ZigType *container_type = ir_resolve_type(ira, container_type_value, ZigTypeIdInvalid);
19163 if (type_is_invalid(container_type))19143 if (type_is_invalid(container_type))
19164 return ira->codegen->invalid_instruction;19144 return ira->codegen->invalid_instruction;
1916519145
...@@ -19252,7 +19232,7 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct...@@ -19252,7 +19232,7 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
19252 IrInstruction *type_value = instruction->type_value->child;19232 IrInstruction *type_value = instruction->type_value->child;
19253 if (type_is_invalid(type_value->value.type))19233 if (type_is_invalid(type_value->value.type))
19254 return ira->codegen->invalid_instruction;19234 return ira->codegen->invalid_instruction;
19255 ZigType *type_entry = ir_resolve_type(ira, type_value);19235 ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdInvalid);
1925619236
19257 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusAlignmentKnown)))19237 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusAlignmentKnown)))
19258 return ira->codegen->invalid_instruction;19238 return ira->codegen->invalid_instruction;
...@@ -19302,16 +19282,10 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -19302,16 +19282,10 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
19302 if (type_is_invalid(type_value->value.type))19282 if (type_is_invalid(type_value->value.type))
19303 return ira->codegen->invalid_instruction;19283 return ira->codegen->invalid_instruction;
1930419284
19305 ZigType *dest_type = ir_resolve_type(ira, type_value);19285 ZigType *dest_type = ir_resolve_type(ira, type_value, ZigTypeIdInt);
19306 if (type_is_invalid(dest_type))19286 if (type_is_invalid(dest_type))
19307 return ira->codegen->invalid_instruction;19287 return ira->codegen->invalid_instruction;
1930819288
19309 if (dest_type->id != ZigTypeIdInt) {
19310 ir_add_error(ira, type_value,
19311 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
19312 return ira->codegen->invalid_instruction;
19313 }
19314
19315 IrInstruction *op1 = instruction->op1->child;19289 IrInstruction *op1 = instruction->op1->child;
19316 if (type_is_invalid(op1->value.type))19290 if (type_is_invalid(op1->value.type))
19317 return ira->codegen->invalid_instruction;19291 return ira->codegen->invalid_instruction;
...@@ -19581,7 +19555,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -19581,7 +19555,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
19581 IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->child;19555 IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->child;
19582 if (type_is_invalid(param_type_value->value.type))19556 if (type_is_invalid(param_type_value->value.type))
19583 return ira->codegen->invalid_instruction;19557 return ira->codegen->invalid_instruction;
19584 ZigType *param_type = ir_resolve_type(ira, param_type_value);19558 ZigType *param_type = ir_resolve_type(ira, param_type_value, ZigTypeIdInvalid);
19585 switch (type_requires_comptime(ira->codegen, param_type)) {19559 switch (type_requires_comptime(ira->codegen, param_type)) {
19586 case ReqCompTimeYes:19560 case ReqCompTimeYes:
19587 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {19561 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
...@@ -19615,7 +19589,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -19615,7 +19589,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
19615 }19589 }
1961619590
19617 IrInstruction *return_type_value = instruction->return_type->child;19591 IrInstruction *return_type_value = instruction->return_type->child;
19618 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);19592 fn_type_id.return_type = ir_resolve_type(ira, return_type_value, ZigTypeIdInvalid);
19619 if (type_is_invalid(fn_type_id.return_type))19593 if (type_is_invalid(fn_type_id.return_type))
19620 return ira->codegen->invalid_instruction;19594 return ira->codegen->invalid_instruction;
19621 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {19595 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
...@@ -19631,7 +19605,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -19631,7 +19605,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
19631 return ira->codegen->invalid_instruction;19605 return ira->codegen->invalid_instruction;
19632 }19606 }
19633 IrInstruction *async_allocator_type_value = instruction->async_allocator_type_value->child;19607 IrInstruction *async_allocator_type_value = instruction->async_allocator_type_value->child;
19634 fn_type_id.async_allocator_type = ir_resolve_type(ira, async_allocator_type_value);19608 fn_type_id.async_allocator_type = ir_resolve_type(ira, async_allocator_type_value, ZigTypeIdInvalid);
19635 if (type_is_invalid(fn_type_id.async_allocator_type))19609 if (type_is_invalid(fn_type_id.async_allocator_type))
19636 return ira->codegen->invalid_instruction;19610 return ira->codegen->invalid_instruction;
19637 }19611 }
...@@ -19939,7 +19913,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -19939,7 +19913,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
19939 result_type = get_slice_type(ira->codegen, result_ptr_type);19913 result_type = get_slice_type(ira->codegen, result_ptr_type);
19940 } else {19914 } else {
19941 ir_add_error(ira, target,19915 ir_add_error(ira, target,
19942 buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name)));19916 buf_sprintf("expected pointer or slice type, found '%s'", buf_ptr(&target_type->name)));
19943 return ira->codegen->invalid_instruction;19917 return ira->codegen->invalid_instruction;
19944 }19918 }
1994519919
...@@ -19985,13 +19959,13 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -19985,13 +19959,13 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
19985 // validate src_type and dest_type.19959 // validate src_type and dest_type.
1998619960
19987 if (get_src_ptr_type(src_type) == nullptr) {19961 if (get_src_ptr_type(src_type) == nullptr) {
19988 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));19962 ir_add_error(ira, ptr, buf_sprintf("expected Pointer type, found '%s'", buf_ptr(&src_type->name)));
19989 return ira->codegen->invalid_instruction;19963 return ira->codegen->invalid_instruction;
19990 }19964 }
1999119965
19992 if (get_src_ptr_type(dest_type) == nullptr) {19966 if (get_src_ptr_type(dest_type) == nullptr) {
19993 ir_add_error(ira, dest_type_src,19967 ir_add_error(ira, dest_type_src,
19994 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));19968 buf_sprintf("expected Pointer type, found '%s'", buf_ptr(&dest_type->name)));
19995 return ira->codegen->invalid_instruction;19969 return ira->codegen->invalid_instruction;
19996 }19970 }
1999719971
...@@ -20059,7 +20033,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -20059,7 +20033,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2005920033
20060static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) {20034static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) {
20061 IrInstruction *dest_type_value = instruction->dest_type->child;20035 IrInstruction *dest_type_value = instruction->dest_type->child;
20062 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);20036 ZigType *dest_type = ir_resolve_type(ira, dest_type_value, ZigTypeIdInvalid);
20063 if (type_is_invalid(dest_type))20037 if (type_is_invalid(dest_type))
20064 return ira->codegen->invalid_instruction;20038 return ira->codegen->invalid_instruction;
2006520039
...@@ -20255,7 +20229,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -20255,7 +20229,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
20255static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) {20229static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) {
20256 Error err;20230 Error err;
20257 IrInstruction *dest_type_value = instruction->dest_type->child;20231 IrInstruction *dest_type_value = instruction->dest_type->child;
20258 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);20232 ZigType *dest_type = ir_resolve_type(ira, dest_type_value, ZigTypeIdInvalid);
20259 if (type_is_invalid(dest_type))20233 if (type_is_invalid(dest_type))
20260 return ira->codegen->invalid_instruction;20234 return ira->codegen->invalid_instruction;
2026120235
...@@ -20352,13 +20326,13 @@ static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruct...@@ -20352,13 +20326,13 @@ static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruct
20352static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) {20326static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) {
20353 Error err;20327 Error err;
20354 IrInstruction *dest_type_value = instruction->dest_type->child;20328 IrInstruction *dest_type_value = instruction->dest_type->child;
20355 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);20329 ZigType *dest_type = ir_resolve_type(ira, dest_type_value, ZigTypeIdInvalid);
20356 if (type_is_invalid(dest_type))20330 if (type_is_invalid(dest_type))
20357 return ira->codegen->invalid_instruction;20331 return ira->codegen->invalid_instruction;
2035820332
20359 // We explicitly check for the size, so we can use get_src_ptr_type20333 // We explicitly check for the size, so we can use get_src_ptr_type
20360 if (get_src_ptr_type(dest_type) == nullptr) {20334 if (get_src_ptr_type(dest_type) == nullptr) {
20361 ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));20335 ir_add_error(ira, dest_type_value, buf_sprintf("expected Pointer type, found '%s'", buf_ptr(&dest_type->name)));
20362 return ira->codegen->invalid_instruction;20336 return ira->codegen->invalid_instruction;
20363 }20337 }
2036420338
...@@ -20461,7 +20435,7 @@ static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstru...@@ -20461,7 +20435,7 @@ static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstru
20461 // We check size explicitly so we can use get_src_ptr_type here.20435 // We check size explicitly so we can use get_src_ptr_type here.
20462 if (get_src_ptr_type(target->value.type) == nullptr) {20436 if (get_src_ptr_type(target->value.type) == nullptr) {
20463 ir_add_error(ira, target,20437 ir_add_error(ira, target,
20464 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name)));20438 buf_sprintf("expected Pointer type, found '%s'", buf_ptr(&target->value.type->name)));
20465 return ira->codegen->invalid_instruction;20439 return ira->codegen->invalid_instruction;
20466 }20440 }
2046720441
...@@ -20492,7 +20466,7 @@ static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstru...@@ -20492,7 +20466,7 @@ static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstru
2049220466
20493static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {20467static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
20494 Error err;20468 Error err;
20495 ZigType *child_type = ir_resolve_type(ira, instruction->child_type->child);20469 ZigType *child_type = ir_resolve_type(ira, instruction->child_type->child, ZigTypeIdInvalid);
20496 if (type_is_invalid(child_type))20470 if (type_is_invalid(child_type))
20497 return ira->codegen->invalid_instruction;20471 return ira->codegen->invalid_instruction;
2049820472
...@@ -20591,7 +20565,7 @@ static IrInstruction *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrI...@@ -20591,7 +20565,7 @@ static IrInstruction *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrI
2059120565
20592static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {20566static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {
20593 IrInstruction *fn_type_inst = instruction->fn_type->child;20567 IrInstruction *fn_type_inst = instruction->fn_type->child;
20594 ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);20568 ZigType *fn_type = ir_resolve_type(ira, fn_type_inst, ZigTypeIdFn);
20595 if (type_is_invalid(fn_type))20569 if (type_is_invalid(fn_type))
20596 return ira->codegen->invalid_instruction;20570 return ira->codegen->invalid_instruction;
2059720571
...@@ -20600,11 +20574,6 @@ static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruct...@@ -20600,11 +20574,6 @@ static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruct
20600 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))20574 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
20601 return ira->codegen->invalid_instruction;20575 return ira->codegen->invalid_instruction;
2060220576
20603 if (fn_type->id != ZigTypeIdFn) {
20604 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
20605 return ira->codegen->invalid_instruction;
20606 }
20607
20608 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;20577 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
20609 if (arg_index >= fn_type_id->param_count) {20578 if (arg_index >= fn_type_id->param_count) {
20610 ir_add_error(ira, arg_index_inst,20579 ir_add_error(ira, arg_index_inst,
...@@ -20629,7 +20598,7 @@ static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruct...@@ -20629,7 +20598,7 @@ static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruct
20629static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {20598static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {
20630 Error err;20599 Error err;
20631 IrInstruction *target_inst = instruction->target->child;20600 IrInstruction *target_inst = instruction->target->child;
20632 ZigType *enum_type = ir_resolve_type(ira, target_inst);20601 ZigType *enum_type = ir_resolve_type(ira, target_inst, ZigTypeIdInvalid);
20633 if (type_is_invalid(enum_type))20602 if (type_is_invalid(enum_type))
20634 return ira->codegen->invalid_instruction;20603 return ira->codegen->invalid_instruction;
2063520604
...@@ -20654,7 +20623,7 @@ static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruct...@@ -20654,7 +20623,7 @@ static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruct
20654 return ira->codegen->invalid_instruction;20623 return ira->codegen->invalid_instruction;
20655 }20624 }
20656 } else {20625 } else {
20657 ir_add_error(ira, target_inst, buf_sprintf("expected enum or union, found '%s'",20626 ir_add_error(ira, target_inst, buf_sprintf("expected enum or union type, found '%s'",
20658 buf_ptr(&enum_type->name)));20627 buf_ptr(&enum_type->name)));
20659 return ira->codegen->invalid_instruction;20628 return ira->codegen->invalid_instruction;
20660 }20629 }
...@@ -20808,7 +20777,7 @@ static IrInstruction *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInst...@@ -20808,7 +20777,7 @@ static IrInstruction *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInst
20808 if (coro_handle->value.type->id != ZigTypeIdPromise ||20777 if (coro_handle->value.type->id != ZigTypeIdPromise ||
20809 coro_handle->value.type->data.promise.result_type == nullptr)20778 coro_handle->value.type->data.promise.result_type == nullptr)
20810 {20779 {
20811 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",20780 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T type, found '%s'",
20812 buf_ptr(&coro_handle->value.type->name)));20781 buf_ptr(&coro_handle->value.type->name)));
20813 return ira->codegen->invalid_instruction;20782 return ira->codegen->invalid_instruction;
20814 }20783 }
...@@ -20839,7 +20808,7 @@ static IrInstruction *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, I...@@ -20839,7 +20808,7 @@ static IrInstruction *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, I
20839}20808}
2084020809
20841static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {20810static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
20842 ZigType *operand_type = ir_resolve_type(ira, op);20811 ZigType *operand_type = ir_resolve_type(ira, op, ZigTypeIdInvalid);
20843 if (type_is_invalid(operand_type))20812 if (type_is_invalid(operand_type))
20844 return ira->codegen->builtin_types.entry_invalid;20813 return ira->codegen->builtin_types.entry_invalid;
2084520814
...@@ -20969,12 +20938,12 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr...@@ -20969,12 +20938,12 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
20969}20938}
2097020939
20971static IrInstruction *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) {20940static IrInstruction *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) {
20972 ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->child);20941 ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->child, ZigTypeIdInvalid);
20973 if (type_is_invalid(promise_type))20942 if (type_is_invalid(promise_type))
20974 return ira->codegen->invalid_instruction;20943 return ira->codegen->invalid_instruction;
2097520944
20976 if (promise_type->id != ZigTypeIdPromise || promise_type->data.promise.result_type == nullptr) {20945 if (promise_type->id != ZigTypeIdPromise || promise_type->data.promise.result_type == nullptr) {
20977 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",20946 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T type, found '%s'",
20978 buf_ptr(&promise_type->name)));20947 buf_ptr(&promise_type->name)));
20979 return ira->codegen->invalid_instruction;20948 return ira->codegen->invalid_instruction;
20980 }20949 }
...@@ -20983,7 +20952,7 @@ static IrInstruction *ir_analyze_instruction_promise_result_type(IrAnalyze *ira,...@@ -20983,7 +20952,7 @@ static IrInstruction *ir_analyze_instruction_promise_result_type(IrAnalyze *ira,
20983}20952}
2098420953
20985static IrInstruction *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) {20954static IrInstruction *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) {
20986 ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->child);20955 ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->child, ZigTypeIdInvalid);
20987 if (type_is_invalid(promise_result_type))20956 if (type_is_invalid(promise_result_type))
20988 return ira->codegen->invalid_instruction;20957 return ira->codegen->invalid_instruction;
2098920958
...@@ -21046,7 +21015,7 @@ static IrInstruction *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *i...@@ -21046,7 +21015,7 @@ static IrInstruction *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *i
21046}21015}
2104721016
21048static IrInstruction *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) {21017static IrInstruction *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) {
21049 ZigType *float_type = ir_resolve_type(ira, instruction->type->child);21018 ZigType *float_type = ir_resolve_type(ira, instruction->type->child, ZigTypeIdInvalid);
21050 if (type_is_invalid(float_type))21019 if (type_is_invalid(float_type))
21051 return ira->codegen->invalid_instruction;21020 return ira->codegen->invalid_instruction;
2105221021
...@@ -21113,7 +21082,7 @@ static IrInstruction *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionS...@@ -21113,7 +21082,7 @@ static IrInstruction *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionS
21113}21082}
2111421083
21115static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstructionBswap *instruction) {21084static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstructionBswap *instruction) {
21116 ZigType *int_type = ir_resolve_type(ira, instruction->type->child);21085 ZigType *int_type = ir_resolve_type(ira, instruction->type->child, ZigTypeIdInvalid);
21117 if (type_is_invalid(int_type))21086 if (type_is_invalid(int_type))
21118 return ira->codegen->invalid_instruction;21087 return ira->codegen->invalid_instruction;
2111921088
...@@ -21169,7 +21138,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -21169,7 +21138,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
21169}21138}
2117021139
21171static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstructionBitReverse *instruction) {21140static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstructionBitReverse *instruction) {
21172 ZigType *int_type = ir_resolve_type(ira, instruction->type->child);21141 ZigType *int_type = ir_resolve_type(ira, instruction->type->child, ZigTypeIdInvalid);
21173 if (type_is_invalid(int_type))21142 if (type_is_invalid(int_type))
21174 return ira->codegen->invalid_instruction;21143 return ira->codegen->invalid_instruction;
2117521144
...@@ -21240,7 +21209,7 @@ static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstr...@@ -21240,7 +21209,7 @@ static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstr
2124021209
21241 if (target->value.type->id != ZigTypeIdEnum) {21210 if (target->value.type->id != ZigTypeIdEnum) {
21242 ir_add_error(ira, instruction->target,21211 ir_add_error(ira, instruction->target,
21243 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name)));21212 buf_sprintf("expected enum type, found '%s'", buf_ptr(&target->value.type->name)));
21244 return ira->codegen->invalid_instruction;21213 return ira->codegen->invalid_instruction;
21245 }21214 }
2124621215
...@@ -21255,16 +21224,10 @@ static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstr...@@ -21255,16 +21224,10 @@ static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstr
21255static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {21224static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {
21256 Error err;21225 Error err;
21257 IrInstruction *dest_type_value = instruction->dest_type->child;21226 IrInstruction *dest_type_value = instruction->dest_type->child;
21258 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);21227 ZigType *dest_type = ir_resolve_type(ira, dest_type_value, ZigTypeIdEnum);
21259 if (type_is_invalid(dest_type))21228 if (type_is_invalid(dest_type))
21260 return ira->codegen->invalid_instruction;21229 return ira->codegen->invalid_instruction;
2126121230
21262 if (dest_type->id != ZigTypeIdEnum) {
21263 ir_add_error(ira, instruction->dest_type,
21264 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
21265 return ira->codegen->invalid_instruction;
21266 }
21267
21268 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))21231 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
21269 return ira->codegen->invalid_instruction;21232 return ira->codegen->invalid_instruction;
2127021233
src/parser.cpp+29-6
...@@ -122,19 +122,37 @@ static AstNode *ast_parse_container_decl_type(ParseContext *pc);...@@ -122,19 +122,37 @@ static AstNode *ast_parse_container_decl_type(ParseContext *pc);
122static AstNode *ast_parse_byte_align(ParseContext *pc);122static AstNode *ast_parse_byte_align(ParseContext *pc);
123123
124ATTRIBUTE_PRINTF(3, 4)124ATTRIBUTE_PRINTF(3, 4)
125ATTRIBUTE_NORETURN125static ErrorMsg *ast_error(ParseContext *pc, Token *token, const char *format, ...) {
126static void ast_error(ParseContext *pc, Token *token, const char *format, ...) {
127 va_list ap;126 va_list ap;
128 va_start(ap, format);127 va_start(ap, format);
129 Buf *msg = buf_vprintf(format, ap);128 Buf *msg = buf_vprintf(format, ap);
130 va_end(ap);129 va_end(ap);
131130
131 ErrorMsg *err = err_msg_create_with_line(pc->owner->path, token->start_line, token->start_column,
132 pc->owner->source_code, pc->owner->line_offsets, msg);
133 err->line_start = token->start_line;
134 err->column_start = token->start_column;
135
136 return err;
137}
138
139ATTRIBUTE_PRINTF(4, 5)
140ATTRIBUTE_NORETURN
141static void ast_error_exit(ParseContext *pc, Token *token, ErrorMsg *note, const char *format, ...) {
142 va_list ap;
143 va_start(ap, format);
144 Buf *msg = buf_vprintf(format, ap);
145 va_end(ap);
132146
133 ErrorMsg *err = err_msg_create_with_line(pc->owner->path, token->start_line, token->start_column,147 ErrorMsg *err = err_msg_create_with_line(pc->owner->path, token->start_line, token->start_column,
134 pc->owner->source_code, pc->owner->line_offsets, msg);148 pc->owner->source_code, pc->owner->line_offsets, msg);
135 err->line_start = token->start_line;149 err->line_start = token->start_line;
136 err->column_start = token->start_column;150 err->column_start = token->start_column;
137151
152 if (note) {
153 err->notes.append(note);
154 }
155
138 print_err_msg(err, pc->err_color);156 print_err_msg(err, pc->err_color);
139 exit(EXIT_FAILURE);157 exit(EXIT_FAILURE);
140}158}
...@@ -164,7 +182,7 @@ static Buf ast_token_str(Buf *input, Token *token) {...@@ -164,7 +182,7 @@ static Buf ast_token_str(Buf *input, Token *token) {
164ATTRIBUTE_NORETURN182ATTRIBUTE_NORETURN
165static void ast_invalid_token_error(ParseContext *pc, Token *token) {183static void ast_invalid_token_error(ParseContext *pc, Token *token) {
166 Buf token_value = ast_token_str(pc->buf, token);184 Buf token_value = ast_token_str(pc->buf, token);
167 ast_error(pc, token, "invalid token: '%s'", buf_ptr(&token_value));185 ast_error_exit(pc, token, NULL, "invalid token: '%s'", buf_ptr(&token_value));
168}186}
169187
170static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {188static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {
...@@ -214,8 +232,13 @@ static Token *eat_token_if(ParseContext *pc, TokenId id) {...@@ -214,8 +232,13 @@ static Token *eat_token_if(ParseContext *pc, TokenId id) {
214232
215static Token *expect_token(ParseContext *pc, TokenId id) {233static Token *expect_token(ParseContext *pc, TokenId id) {
216 Token *res = eat_token(pc);234 Token *res = eat_token(pc);
217 if (res->id != id)235 if (res->id != id) {
218 ast_error(pc, res, "expected token '%s', found '%s'", token_name(id), token_name(res->id));236 ErrorMsg *note = NULL;
237 if (res->id == TokenIdAmpersandAmpersand) {
238 note = ast_error(pc, res, "did you mean to use `and`?");
239 }
240 ast_error_exit(pc, res, note, "expected token '%s', found '%s'", token_name(id), token_name(res->id));
241 }
219242
220 return res;243 return res;
221}244}
...@@ -837,7 +860,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {...@@ -837,7 +860,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {
837 if (param_decl->data.param_decl.is_var_args)860 if (param_decl->data.param_decl.is_var_args)
838 res->data.fn_proto.is_var_args = true;861 res->data.fn_proto.is_var_args = true;
839 if (i != params.length - 1 && res->data.fn_proto.is_var_args)862 if (i != params.length - 1 && res->data.fn_proto.is_var_args)
840 ast_error(pc, first, "Function prototype have varargs as a none last paramter.");863 ast_error_exit(pc, first, NULL, "Function prototype have varargs as a none last paramter.");
841 }864 }
842 return res;865 return res;
843}866}
src/tokenizer.cpp+12
...@@ -199,6 +199,7 @@ enum TokenizeState {...@@ -199,6 +199,7 @@ enum TokenizeState {
199 TokenizeStateSawDash,199 TokenizeStateSawDash,
200 TokenizeStateSawMinusPercent,200 TokenizeStateSawMinusPercent,
201 TokenizeStateSawAmpersand,201 TokenizeStateSawAmpersand,
202 TokenizeStateSawAmpersandAmpersand,
202 TokenizeStateSawCaret,203 TokenizeStateSawCaret,
203 TokenizeStateSawBar,204 TokenizeStateSawBar,
204 TokenizeStateSawBarBar,205 TokenizeStateSawBarBar,
...@@ -891,6 +892,10 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -891,6 +892,10 @@ void tokenize(Buf *buf, Tokenization *out) {
891 end_token(&t);892 end_token(&t);
892 t.state = TokenizeStateStart;893 t.state = TokenizeStateStart;
893 break;894 break;
895 case '&':
896 set_token_id(&t, t.cur_tok, TokenIdAmpersandAmpersand);
897 t.state = TokenizeStateSawAmpersandAmpersand;
898 break;
894 default:899 default:
895 t.pos -= 1;900 t.pos -= 1;
896 end_token(&t);901 end_token(&t);
...@@ -898,6 +903,11 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -898,6 +903,11 @@ void tokenize(Buf *buf, Tokenization *out) {
898 continue;903 continue;
899 }904 }
900 break;905 break;
906 case TokenizeStateSawAmpersandAmpersand:
907 t.pos -= 1;
908 end_token(&t);
909 t.state = TokenizeStateStart;
910 continue;
901 case TokenizeStateSawCaret:911 case TokenizeStateSawCaret:
902 switch (c) {912 switch (c) {
903 case '=':913 case '=':
...@@ -1468,6 +1478,7 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -1468,6 +1478,7 @@ void tokenize(Buf *buf, Tokenization *out) {
1468 case TokenizeStateSawPlus:1478 case TokenizeStateSawPlus:
1469 case TokenizeStateSawDash:1479 case TokenizeStateSawDash:
1470 case TokenizeStateSawAmpersand:1480 case TokenizeStateSawAmpersand:
1481 case TokenizeStateSawAmpersandAmpersand:
1471 case TokenizeStateSawCaret:1482 case TokenizeStateSawCaret:
1472 case TokenizeStateSawBar:1483 case TokenizeStateSawBar:
1473 case TokenizeStateSawEq:1484 case TokenizeStateSawEq:
...@@ -1515,6 +1526,7 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -1515,6 +1526,7 @@ void tokenize(Buf *buf, Tokenization *out) {
1515const char * token_name(TokenId id) {1526const char * token_name(TokenId id) {
1516 switch (id) {1527 switch (id) {
1517 case TokenIdAmpersand: return "&";1528 case TokenIdAmpersand: return "&";
1529 case TokenIdAmpersandAmpersand: return "&&";
1518 case TokenIdArrow: return "->";1530 case TokenIdArrow: return "->";
1519 case TokenIdAtSign: return "@";1531 case TokenIdAtSign: return "@";
1520 case TokenIdBang: return "!";1532 case TokenIdBang: return "!";
src/tokenizer.hpp+1
...@@ -14,6 +14,7 @@...@@ -14,6 +14,7 @@
1414
15enum TokenId {15enum TokenId {
16 TokenIdAmpersand,16 TokenIdAmpersand,
17 TokenIdAmpersandAmpersand,
17 TokenIdArrow,18 TokenIdArrow,
18 TokenIdAtSign,19 TokenIdAtSign,
19 TokenIdBang,20 TokenIdBang,
test/compile_errors.zig+88-57
...@@ -1,6 +1,36 @@...@@ -1,6 +1,36 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "Use of && in place of `and`",
6 \\export fn entry() void {
7 \\ if (true && false) return;
8 \\}
9 ,
10 ".tmp_source.zig:2:14: error: expected token ')', found '&&'",
11 ".tmp_source.zig:2:14: note: did you mean to use `and`?",
12 );
13
14 cases.add(
15 "Use of || in place of `or` (using comptime_int)",
16 \\export fn entry() void {
17 \\ if (1 || 0) return;
18 \\}
19 ,
20 ".tmp_source.zig:2:9: error: expected ErrorSet type, found 'comptime_int'",
21 ".tmp_source.zig:2:11: note: did you mean to use `or`?",
22 );
23
24 cases.add(
25 "Use of || in place of `or` (using booleans)",
26 \\export fn entry() void {
27 \\ if (true || false) return;
28 \\}
29 ,
30 ".tmp_source.zig:2:9: error: expected ErrorSet type, found 'bool'",
31 ".tmp_source.zig:2:14: note: did you mean to use `or`?",
32 );
33
4 cases.add(34 cases.add(
5 "compile log a pointer to an opaque value",35 "compile log a pointer to an opaque value",
6 \\export fn entry() void {36 \\export fn entry() void {
...@@ -68,7 +98,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -68,7 +98,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
68 \\ do_the_thing(bar);98 \\ do_the_thing(bar);
69 \\}99 \\}
70 ,100 ,
71 ".tmp_source.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void",101 ".tmp_source.zig:4:18: error: expected 'fn(i32) void' type, found 'fn(bool) void",
72 ".tmp_source.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'",102 ".tmp_source.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'",
73 );103 );
74104
...@@ -104,7 +134,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -104,7 +134,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
104 ,134 ,
105 ".tmp_source.zig:3:31: error: integer value 300 cannot be implicitly casted to type 'u8'",135 ".tmp_source.zig:3:31: error: integer value 300 cannot be implicitly casted to type 'u8'",
106 ".tmp_source.zig:7:22: error: integer value 300 cannot be implicitly casted to type 'u8'",136 ".tmp_source.zig:7:22: error: integer value 300 cannot be implicitly casted to type 'u8'",
107 ".tmp_source.zig:11:20: error: expected type 'u8', found 'u16'",137 ".tmp_source.zig:11:20: error: expected 'u8' type, found 'u16'",
108 );138 );
109139
110 cases.add(140 cases.add(
...@@ -124,7 +154,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -124,7 +154,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
124 \\154 \\
125 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }155 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
126 ,156 ,
127 ".tmp_source.zig:2:14: error: expected type 'f32', found 'f64'",157 ".tmp_source.zig:2:14: error: expected 'f32' type, found 'f64'",
128 );158 );
129159
130 cases.add(160 cases.add(
...@@ -172,7 +202,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -172,7 +202,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
172 \\ var ptr2: *c_void = &b;202 \\ var ptr2: *c_void = &b;
173 \\}203 \\}
174 ,204 ,
175 ".tmp_source.zig:5:26: error: expected type '*c_void', found '**u32'",205 ".tmp_source.zig:5:26: error: expected '*c_void' type, found '**u32'",
176 );206 );
177207
178 cases.add(208 cases.add(
...@@ -222,7 +252,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -222,7 +252,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
222 \\ const sliceA: []u8 = &buffer;252 \\ const sliceA: []u8 = &buffer;
223 \\}253 \\}
224 ,254 ,
225 ".tmp_source.zig:3:27: error: expected type '[]u8', found '*const [1]u8'",255 ".tmp_source.zig:3:27: error: expected '[]u8' type, found '*const [1]u8'",
226 );256 );
227257
228 cases.add(258 cases.add(
...@@ -267,8 +297,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -267,8 +297,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
267 \\ const Errors = error{} || u16;297 \\ const Errors = error{} || u16;
268 \\}298 \\}
269 ,299 ,
270 ".tmp_source.zig:2:20: error: expected error set type, found 'u8'",300 ".tmp_source.zig:2:20: error: expected ErrorSet type, found 'u8'",
271 ".tmp_source.zig:5:31: error: expected error set type, found 'u16'",301 ".tmp_source.zig:2:23: note: did you mean to use `or`?",
302 ".tmp_source.zig:5:31: error: expected ErrorSet type, found 'u16'",
272 );303 );
273304
274 cases.add(305 cases.add(
...@@ -763,7 +794,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -763,7 +794,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
763 \\794 \\
764 \\fn bar(x: *b.Foo) void {}795 \\fn bar(x: *b.Foo) void {}
765 ,796 ,
766 ".tmp_source.zig:6:10: error: expected type '*Foo', found '*Foo'",797 ".tmp_source.zig:6:10: error: expected '*Foo' type, found '*Foo'",
767 ".tmp_source.zig:6:10: note: pointer type child 'Foo' cannot cast into pointer type child 'Foo'",798 ".tmp_source.zig:6:10: note: pointer type child 'Foo' cannot cast into pointer type child 'Foo'",
768 "a.zig:1:17: note: Foo declared here",799 "a.zig:1:17: note: Foo declared here",
769 "b.zig:1:17: note: Foo declared here",800 "b.zig:1:17: note: Foo declared here",
...@@ -833,7 +864,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -833,7 +864,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
833 \\ var y = p.*;864 \\ var y = p.*;
834 \\}865 \\}
835 ,866 ,
836 ".tmp_source.zig:4:23: error: expected type '*?*i32', found '**i32'",867 ".tmp_source.zig:4:23: error: expected '*?*i32' type, found '**i32'",
837 );868 );
838869
839 cases.add(870 cases.add(
...@@ -842,7 +873,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -842,7 +873,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
842 \\ const x: [*]const bool = true;873 \\ const x: [*]const bool = true;
843 \\}874 \\}
844 ,875 ,
845 ".tmp_source.zig:2:30: error: expected type '[*]const bool', found 'bool'",876 ".tmp_source.zig:2:30: error: expected '[*]const bool' type, found 'bool'",
846 );877 );
847878
848 cases.add(879 cases.add(
...@@ -887,7 +918,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -887,7 +918,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
887 \\ var rule_set = try Foo.init();918 \\ var rule_set = try Foo.init();
888 \\}919 \\}
889 ,920 ,
890 ".tmp_source.zig:2:13: error: expected type 'i32', found 'type'",921 ".tmp_source.zig:2:13: error: expected 'i32' type, found 'type'",
891 );922 );
892923
893 cases.add(924 cases.add(
...@@ -921,7 +952,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -921,7 +952,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
921 \\ return null;952 \\ return null;
922 \\}953 \\}
923 ,954 ,
924 ".tmp_source.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'",955 ".tmp_source.zig:5:34: error: expected '?NextError!i32' type, found '?OtherError!i32'",
925 ".tmp_source.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'",956 ".tmp_source.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'",
926 ".tmp_source.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'",957 ".tmp_source.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'",
927 ".tmp_source.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set",958 ".tmp_source.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set",
...@@ -991,7 +1022,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -991,7 +1022,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
991 \\ @panic(e);1022 \\ @panic(e);
992 \\}1023 \\}
993 ,1024 ,
994 ".tmp_source.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'",1025 ".tmp_source.zig:3:12: error: expected '[]const u8' type, found 'error{Foo}'",
995 );1026 );
9961027
997 cases.add(1028 cases.add(
...@@ -1019,7 +1050,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1019,7 +1050,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1019 \\ return error.ShouldBeCompileError;1050 \\ return error.ShouldBeCompileError;
1020 \\}1051 \\}
1021 ,1052 ,
1022 ".tmp_source.zig:6:17: error: expected type 'void', found 'error{ShouldBeCompileError}'",1053 ".tmp_source.zig:6:17: error: expected 'void' type, found 'error{ShouldBeCompileError}'",
1023 );1054 );
10241055
1025 cases.add(1056 cases.add(
...@@ -1062,7 +1093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1062,7 +1093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1062 \\ a(c);1093 \\ a(c);
1063 \\}1094 \\}
1064 ,1095 ,
1065 ".tmp_source.zig:8:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",1096 ".tmp_source.zig:8:7: error: expected 'fn(*const u8) void' type, found 'fn(u8) void'",
1066 );1097 );
10671098
1068 cases.add(1099 cases.add(
...@@ -1144,7 +1175,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1144,7 +1175,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1144 \\ E.One => {},1175 \\ E.One => {},
1145 \\ }1176 \\ }
1146 \\}1177 \\}
1147 , ".tmp_source.zig:9:10: error: expected type 'usize', found 'E'");1178 , ".tmp_source.zig:9:10: error: expected 'usize' type, found 'E'");
11481179
1149 cases.add(1180 cases.add(
1150 "range operator in switch used on error set",1181 "range operator in switch used on error set",
...@@ -1190,7 +1221,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1190,7 +1221,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1190 \\ const z = i32!i32;1221 \\ const z = i32!i32;
1191 \\}1222 \\}
1192 ,1223 ,
1193 ".tmp_source.zig:2:15: error: expected error set type, found type 'i32'",1224 ".tmp_source.zig:2:15: error: expected ErrorSet type, found 'i32'",
1194 );1225 );
11951226
1196 cases.add(1227 cases.add(
...@@ -1240,7 +1271,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1240,7 +1271,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1240 \\ return error.B;1271 \\ return error.B;
1241 \\}1272 \\}
1242 ,1273 ,
1243 ".tmp_source.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'",1274 ".tmp_source.zig:3:35: error: expected 'SmallErrorSet!i32' type, found 'anyerror!i32'",
1244 ".tmp_source.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'",1275 ".tmp_source.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'",
1245 ".tmp_source.zig:3:35: note: cannot cast global error set into smaller set",1276 ".tmp_source.zig:3:35: note: cannot cast global error set into smaller set",
1246 );1277 );
...@@ -1255,7 +1286,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1255,7 +1286,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1255 \\ return error.B;1286 \\ return error.B;
1256 \\}1287 \\}
1257 ,1288 ,
1258 ".tmp_source.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'",1289 ".tmp_source.zig:3:31: error: expected 'SmallErrorSet' type, found 'anyerror'",
1259 ".tmp_source.zig:3:31: note: cannot cast global error set into smaller set",1290 ".tmp_source.zig:3:31: note: cannot cast global error set into smaller set",
1260 );1291 );
12611292
...@@ -1282,7 +1313,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1282,7 +1313,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1282 \\ var x: Set2 = set1;1313 \\ var x: Set2 = set1;
1283 \\}1314 \\}
1284 ,1315 ,
1285 ".tmp_source.zig:7:19: error: expected type 'Set2', found 'Set1'",1316 ".tmp_source.zig:7:19: error: expected 'Set2' type, found 'Set1'",
1286 ".tmp_source.zig:1:23: note: 'error.B' not a member of destination error set",1317 ".tmp_source.zig:1:23: note: 'error.B' not a member of destination error set",
1287 );1318 );
12881319
...@@ -1822,7 +1853,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1822,7 +1853,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1822 \\fn a() noreturn {return;}1853 \\fn a() noreturn {return;}
1823 \\export fn entry() void { a(); }1854 \\export fn entry() void { a(); }
1824 ,1855 ,
1825 ".tmp_source.zig:1:18: error: expected type 'noreturn', found 'void'",1856 ".tmp_source.zig:1:18: error: expected 'noreturn' type, found 'void'",
1826 );1857 );
18271858
1828 cases.add(1859 cases.add(
...@@ -1830,7 +1861,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1830,7 +1861,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1830 \\fn a() i32 {}1861 \\fn a() i32 {}
1831 \\export fn entry() void { _ = a(); }1862 \\export fn entry() void { _ = a(); }
1832 ,1863 ,
1833 ".tmp_source.zig:1:12: error: expected type 'i32', found 'void'",1864 ".tmp_source.zig:1:12: error: expected 'i32' type, found 'void'",
1834 );1865 );
18351866
1836 cases.add(1867 cases.add(
...@@ -1936,7 +1967,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1936,7 +1967,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1936 \\ return a;1967 \\ return a;
1937 \\}1968 \\}
1938 ,1969 ,
1939 ".tmp_source.zig:3:12: error: expected type 'i32', found '[*]const u8'",1970 ".tmp_source.zig:3:12: error: expected 'i32' type, found '[*]const u8'",
1940 );1971 );
19411972
1942 cases.add(1973 cases.add(
...@@ -1945,7 +1976,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1945,7 +1976,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1945 \\ if (0) {}1976 \\ if (0) {}
1946 \\}1977 \\}
1947 ,1978 ,
1948 ".tmp_source.zig:2:9: error: expected type 'bool', found 'comptime_int'",1979 ".tmp_source.zig:2:9: error: expected 'bool' type, found 'comptime_int'",
1949 );1980 );
19501981
1951 cases.add(1982 cases.add(
...@@ -2040,8 +2071,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2040,8 +2071,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2040 \\ array[bad] = array[bad];2071 \\ array[bad] = array[bad];
2041 \\}2072 \\}
2042 ,2073 ,
2043 ".tmp_source.zig:4:11: error: expected type 'usize', found 'bool'",2074 ".tmp_source.zig:4:11: error: expected 'usize' type, found 'bool'",
2044 ".tmp_source.zig:4:24: error: expected type 'usize', found 'bool'",2075 ".tmp_source.zig:4:24: error: expected 'usize' type, found 'bool'",
2045 );2076 );
20462077
2047 cases.add(2078 cases.add(
...@@ -2455,7 +2486,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2455,7 +2486,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2455 \\fn foo() *const i32 { return y; }2486 \\fn foo() *const i32 { return y; }
2456 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }2487 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2457 ,2488 ,
2458 ".tmp_source.zig:3:30: error: expected type '*const i32', found '*const comptime_int'",2489 ".tmp_source.zig:3:30: error: expected '*const i32' type, found '*const comptime_int'",
2459 );2490 );
24602491
2461 cases.add(2492 cases.add(
...@@ -2533,7 +2564,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2533,7 +2564,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2533 \\fn c() i32 {return 2;}2564 \\fn c() i32 {return 2;}
2534 \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }2565 \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
2535 ,2566 ,
2536 ".tmp_source.zig:1:27: error: expected type 'fn() void', found 'fn() i32'",2567 ".tmp_source.zig:1:27: error: expected 'fn() void' type, found 'fn() i32'",
2537 );2568 );
25382569
2539 cases.add(2570 cases.add(
...@@ -2545,7 +2576,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2545,7 +2576,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2545 \\2576 \\
2546 \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }2577 \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
2547 ,2578 ,
2548 ".tmp_source.zig:1:36: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'",2579 ".tmp_source.zig:1:36: error: expected 'fn(i32) i32' type, found 'extern fn(i32) i32'",
2549 );2580 );
25502581
2551 cases.add(2582 cases.add(
...@@ -2649,7 +2680,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2649,7 +2680,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2649 \\2680 \\
2650 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }2681 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
2651 ,2682 ,
2652 ".tmp_source.zig:1:16: error: expected type '*u8', found '(null)'",2683 ".tmp_source.zig:1:16: error: expected '*u8' type, found '(null)'",
2653 );2684 );
26542685
2655 cases.add(2686 cases.add(
...@@ -3289,7 +3320,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3289,7 +3320,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3289 \\}3320 \\}
3290 \\fn something() anyerror!void { }3321 \\fn something() anyerror!void { }
3291 ,3322 ,
3292 ".tmp_source.zig:2:5: error: expected type 'void', found 'anyerror'",3323 ".tmp_source.zig:2:5: error: expected 'void' type, found 'anyerror'",
3293 ".tmp_source.zig:1:15: note: return type declared here",3324 ".tmp_source.zig:1:15: note: return type declared here",
3294 );3325 );
32953326
...@@ -3468,7 +3499,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3468,7 +3499,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3468 \\ derp.init();3499 \\ derp.init();
3469 \\}3500 \\}
3470 ,3501 ,
3471 ".tmp_source.zig:14:5: error: expected type 'i32', found 'Foo'",3502 ".tmp_source.zig:14:5: error: expected 'i32' type, found 'Foo'",
3472 );3503 );
34733504
3474 cases.add(3505 cases.add(
...@@ -3498,7 +3529,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3498,7 +3529,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3498 \\ x.init();3529 \\ x.init();
3499 \\}3530 \\}
3500 ,3531 ,
3501 ".tmp_source.zig:23:5: error: expected type '*Allocator', found '*List'",3532 ".tmp_source.zig:23:5: error: expected '*Allocator' type, found '*List'",
3502 );3533 );
35033534
3504 cases.add(3535 cases.add(
...@@ -3670,7 +3701,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3670,7 +3701,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3670 \\3701 \\
3671 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }3702 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
3672 ,3703 ,
3673 ".tmp_source.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'",3704 ".tmp_source.zig:8:26: error: expected '*const u3' type, found '*align(:3:1) const u3'",
3674 );3705 );
36753706
3676 cases.add(3707 cases.add(
...@@ -3799,7 +3830,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3799,7 +3830,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3799 \\3830 \\
3800 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }3831 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
3801 ,3832 ,
3802 ".tmp_source.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'",3833 ".tmp_source.zig:4:19: error: expected '*[]const u8' type, found '*const []const u8'",
3803 );3834 );
38043835
3805 cases.addCase(x: {3836 cases.addCase(x: {
...@@ -3831,7 +3862,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3831,7 +3862,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3831 \\ foo(global_array);3862 \\ foo(global_array);
3832 \\}3863 \\}
3833 ,3864 ,
3834 ".tmp_source.zig:4:9: error: expected type '[]i32', found '[10]i32'",3865 ".tmp_source.zig:4:9: error: expected '[]i32' type, found '[10]i32'",
3835 );3866 );
38363867
3837 cases.add(3868 cases.add(
...@@ -3840,7 +3871,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3840,7 +3871,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3840 \\ return @ptrCast(usize, a);3871 \\ return @ptrCast(usize, a);
3841 \\}3872 \\}
3842 ,3873 ,
3843 ".tmp_source.zig:2:21: error: expected pointer, found 'usize'",3874 ".tmp_source.zig:2:21: error: expected Pointer type, found 'usize'",
3844 );3875 );
38453876
3846 cases.add(3877 cases.add(
...@@ -3887,7 +3918,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3887,7 +3918,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3887 \\ return @fieldParentPtr(Foo, "a", a);3918 \\ return @fieldParentPtr(Foo, "a", a);
3888 \\}3919 \\}
3889 ,3920 ,
3890 ".tmp_source.zig:3:28: error: expected struct type, found 'i32'",3921 ".tmp_source.zig:3:28: error: expected Struct type, found 'i32'",
3891 );3922 );
38923923
3893 cases.add(3924 cases.add(
...@@ -3911,7 +3942,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3911,7 +3942,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3911 \\ return @fieldParentPtr(Foo, "a", a);3942 \\ return @fieldParentPtr(Foo, "a", a);
3912 \\}3943 \\}
3913 ,3944 ,
3914 ".tmp_source.zig:5:38: error: expected pointer, found 'i32'",3945 ".tmp_source.zig:5:38: error: expected Pointer type, found 'i32'",
3915 );3946 );
39163947
3917 cases.add(3948 cases.add(
...@@ -3952,7 +3983,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3952,7 +3983,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3952 \\ return @byteOffsetOf(Foo, "a",);3983 \\ return @byteOffsetOf(Foo, "a",);
3953 \\}3984 \\}
3954 ,3985 ,
3955 ".tmp_source.zig:3:26: error: expected struct type, found 'i32'",3986 ".tmp_source.zig:3:26: error: expected Struct type, found 'i32'",
3956 );3987 );
39573988
3958 cases.add(3989 cases.add(
...@@ -4066,7 +4097,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4066,7 +4097,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4066 \\}4097 \\}
4067 \\fn bar() ?i32 { return 1; }4098 \\fn bar() ?i32 { return 1; }
4068 ,4099 ,
4069 ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'",4100 ".tmp_source.zig:2:15: error: expected 'bool' type, found '?i32'",
4070 );4101 );
40714102
4072 cases.add(4103 cases.add(
...@@ -4076,7 +4107,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4076,7 +4107,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4076 \\}4107 \\}
4077 \\fn bar() anyerror!i32 { return 1; }4108 \\fn bar() anyerror!i32 { return 1; }
4078 ,4109 ,
4079 ".tmp_source.zig:2:15: error: expected type 'bool', found 'anyerror!i32'",4110 ".tmp_source.zig:2:15: error: expected 'bool' type, found 'anyerror!i32'",
4080 );4111 );
40814112
4082 cases.add(4113 cases.add(
...@@ -4337,7 +4368,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4337,7 +4368,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4337 \\ return @ptrToInt(x);4368 \\ return @ptrToInt(x);
4338 \\}4369 \\}
4339 ,4370 ,
4340 ".tmp_source.zig:2:22: error: expected pointer, found 'i32'",4371 ".tmp_source.zig:2:22: error: expected Pointer type, found 'i32'",
4341 );4372 );
43424373
4343 cases.add(4374 cases.add(
...@@ -4373,7 +4404,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4373,7 +4404,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4373 \\ return x << y;4404 \\ return x << y;
4374 \\}4405 \\}
4375 ,4406 ,
4376 ".tmp_source.zig:2:17: error: expected type 'u3', found 'u8'",4407 ".tmp_source.zig:2:17: error: expected 'u3' type, found 'u8'",
4377 );4408 );
43784409
4379 cases.add(4410 cases.add(
...@@ -4402,7 +4433,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4402,7 +4433,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4402 \\ x.* += 1;4433 \\ x.* += 1;
4403 \\}4434 \\}
4404 ,4435 ,
4405 ".tmp_source.zig:8:13: error: expected type '*u32', found '*align(1) u32'",4436 ".tmp_source.zig:8:13: error: expected '*u32' type, found '*align(1) u32'",
4406 );4437 );
44074438
4408 cases.add(4439 cases.add(
...@@ -4446,7 +4477,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4446,7 +4477,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4446 \\ @alignCast(4, u32(3));4477 \\ @alignCast(4, u32(3));
4447 \\}4478 \\}
4448 ,4479 ,
4449 ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'",4480 ".tmp_source.zig:2:22: error: expected pointer or slice type, found 'u32'",
4450 );4481 );
44514482
4452 cases.add(4483 cases.add(
...@@ -4459,7 +4490,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4459,7 +4490,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4459 \\}4490 \\}
4460 \\fn alignedSmall() align(4) i32 { return 1234; }4491 \\fn alignedSmall() align(4) i32 { return 1234; }
4461 ,4492 ,
4462 ".tmp_source.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'",4493 ".tmp_source.zig:2:35: error: expected 'fn() align(8) i32' type, found 'fn() align(4) i32'",
4463 );4494 );
44644495
4465 cases.add(4496 cases.add(
...@@ -4471,7 +4502,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4471,7 +4502,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4471 \\ return x == 5678;4502 \\ return x == 5678;
4472 \\}4503 \\}
4473 ,4504 ,
4474 ".tmp_source.zig:4:32: error: expected type '*i32', found '*align(1) i32'",4505 ".tmp_source.zig:4:32: error: expected '*i32' type, found '*align(1) i32'",
4475 );4506 );
44764507
4477 cases.add(4508 cases.add(
...@@ -4506,7 +4537,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4506,7 +4537,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4506 \\ bar(@ptrCast(*c_void, &x));4537 \\ bar(@ptrCast(*c_void, &x));
4507 \\}4538 \\}
4508 ,4539 ,
4509 ".tmp_source.zig:5:9: error: expected type '*Derp', found '*c_void'",4540 ".tmp_source.zig:5:9: error: expected '*Derp' type, found '*c_void'",
4510 );4541 );
45114542
4512 cases.add(4543 cases.add(
...@@ -4552,7 +4583,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4552,7 +4583,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4552 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, u32(1234), u32(1234))) {}4583 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, u32(1234), u32(1234))) {}
4553 \\}4584 \\}
4554 ,4585 ,
4555 ".tmp_source.zig:3:50: error: expected type 'AtomicOrder', found 'u32'",4586 ".tmp_source.zig:3:50: error: expected 'AtomicOrder' type, found 'u32'",
4556 );4587 );
45574588
4558 cases.add(4589 cases.add(
...@@ -4562,7 +4593,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4562,7 +4593,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4562 \\ @export("entry", entry, u32(1234));4593 \\ @export("entry", entry, u32(1234));
4563 \\}4594 \\}
4564 ,4595 ,
4565 ".tmp_source.zig:3:32: error: expected type 'GlobalLinkage', found 'u32'",4596 ".tmp_source.zig:3:32: error: expected 'GlobalLinkage' type, found 'u32'",
4566 );4597 );
45674598
4568 cases.add(4599 cases.add(
...@@ -4739,7 +4770,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4739,7 +4770,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4739 \\ _ = @ArgType(i32, 3);4770 \\ _ = @ArgType(i32, 3);
4740 \\}4771 \\}
4741 ,4772 ,
4742 ".tmp_source.zig:2:18: error: expected function, found 'i32'",4773 ".tmp_source.zig:2:18: error: expected Fn type, found 'i32'",
4743 );4774 );
47444775
4745 cases.add(4776 cases.add(
...@@ -4837,7 +4868,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4837,7 +4868,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4837 \\}4868 \\}
4838 \\pub extern fn foo(format: *const u8, ...) void;4869 \\pub extern fn foo(format: *const u8, ...) void;
4839 ,4870 ,
4840 ".tmp_source.zig:2:9: error: expected type '*const u8', found '[5]u8'",4871 ".tmp_source.zig:2:9: error: expected '*const u8' type, found '[5]u8'",
4841 );4872 );
48424873
4843 cases.add(4874 cases.add(
...@@ -4906,7 +4937,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4906,7 +4937,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4906 \\ var x: u2 = Small.Two;4937 \\ var x: u2 = Small.Two;
4907 \\}4938 \\}
4908 ,4939 ,
4909 ".tmp_source.zig:9:22: error: expected type 'u2', found 'Small'",4940 ".tmp_source.zig:9:22: error: expected 'u2' type, found 'Small'",
4910 );4941 );
49114942
4912 cases.add(4943 cases.add(
...@@ -4923,7 +4954,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4923,7 +4954,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4923 \\ var x = @intToEnum(Small, y);4954 \\ var x = @intToEnum(Small, y);
4924 \\}4955 \\}
4925 ,4956 ,
4926 ".tmp_source.zig:10:31: error: expected type 'u2', found 'u3'",4957 ".tmp_source.zig:10:31: error: expected 'u2' type, found 'u3'",
4927 );4958 );
49284959
4929 cases.add(4960 cases.add(
...@@ -5320,7 +5351,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5320,7 +5351,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5320 \\ asm volatile ("" : : [bar]"r"(3) : "");5351 \\ asm volatile ("" : : [bar]"r"(3) : "");
5321 \\}5352 \\}
5322 ,5353 ,
5323 ".tmp_source.zig:2:35: error: expected sized integer or sized float, found comptime_int",5354 ".tmp_source.zig:2:35: error: expected sized integer or sized float type, found comptime_int",
5324 );5355 );
53255356
5326 cases.add(5357 cases.add(
...@@ -5329,6 +5360,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5329,6 +5360,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5329 \\ asm volatile ("" : : [bar]"r"(3.17) : "");5360 \\ asm volatile ("" : : [bar]"r"(3.17) : "");
5330 \\}5361 \\}
5331 ,5362 ,
5332 ".tmp_source.zig:2:35: error: expected sized integer or sized float, found comptime_float",5363 ".tmp_source.zig:2:35: error: expected sized integer or sized float type, found comptime_float",
5333 );5364 );
5334}5365}