authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-26 18:35:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-26 18:35:36-04:00
logbad4b040cca553ae6845b18f268313f02077f6c1
treeac91a35d13920be9cef9f35a4f655b956c2fb36e
parentca145a6d5a430cd87d0b242fb7453e8249221cd0
signature Commit is signed but in an unrecognized format.

miscellaneous fixes regarding compile errors


5 files changed, 84 insertions(+), 50 deletions(-)

src/all_types.hpp+3
...@@ -363,8 +363,10 @@ struct LazyValueFnType {...@@ -363,8 +363,10 @@ struct LazyValueFnType {
363363
364 AstNode *proto_node;364 AstNode *proto_node;
365 ConstExprValue **param_types;365 ConstExprValue **param_types;
366 AstNode **param_type_src_nodes;
366 ConstExprValue *align_val; // can be null367 ConstExprValue *align_val; // can be null
367 ConstExprValue *return_type;368 ConstExprValue *return_type;
369 AstNode *return_type_src_node;
368};370};
369371
370struct ConstExprValue {372struct ConstExprValue {
...@@ -1026,6 +1028,7 @@ struct AstNodeEnumLiteral {...@@ -1026,6 +1028,7 @@ struct AstNodeEnumLiteral {
10261028
1027struct AstNode {1029struct AstNode {
1028 enum NodeType type;1030 enum NodeType type;
1031 bool already_traced_this_node;
1029 size_t line;1032 size_t line;
1030 size_t column;1033 size_t column;
1031 ZigType *owner;1034 ZigType *owner;
src/analyze.cpp+8-6
...@@ -63,10 +63,11 @@ ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg) {...@@ -63,10 +63,11 @@ ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg) {
63 return err;63 return err;
64}64}
6565
66ErrorMsg *add_node_error(CodeGen *g, const AstNode *node, Buf *msg) {66ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
67 Token fake_token;67 Token fake_token;
68 fake_token.start_line = node->line;68 fake_token.start_line = node->line;
69 fake_token.start_column = node->column;69 fake_token.start_column = node->column;
70 node->already_traced_this_node = true;
70 return add_token_error(g, node->owner, &fake_token, msg);71 return add_token_error(g, node->owner, &fake_token, msg);
71}72}
7273
...@@ -1782,7 +1783,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -1782,7 +1783,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
1782 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {1783 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {
1783 struct_type->data.structure.resolve_status = ResolveStatusInvalid;1784 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
1784 add_node_error(g, decl_node,1785 add_node_error(g, decl_node,
1785 buf_sprintf("struct '%s' depends on its own size", buf_ptr(&struct_type->name)));1786 buf_sprintf("struct '%s' depends on itself", buf_ptr(&struct_type->name)));
1786 }1787 }
1787 return ErrorSemanticAnalyzeFail;1788 return ErrorSemanticAnalyzeFail;
1788 }1789 }
...@@ -1936,7 +1937,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {...@@ -1936,7 +1937,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
1936 if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {1937 if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {
1937 union_type->data.unionation.resolve_status = ResolveStatusInvalid;1938 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
1938 add_node_error(g, decl_node,1939 add_node_error(g, decl_node,
1939 buf_sprintf("union '%s' depends on its own alignment", buf_ptr(&union_type->name)));1940 buf_sprintf("union '%s' depends on itself", buf_ptr(&union_type->name)));
1940 }1941 }
1941 return ErrorSemanticAnalyzeFail;1942 return ErrorSemanticAnalyzeFail;
1942 }1943 }
...@@ -2047,7 +2048,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2047,7 +2048,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2047 if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {2048 if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {
2048 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2049 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2049 add_node_error(g, decl_node,2050 add_node_error(g, decl_node,
2050 buf_sprintf("union '%s' depends on its own size", buf_ptr(&union_type->name)));2051 buf_sprintf("union '%s' depends on itself", buf_ptr(&union_type->name)));
2051 }2052 }
2052 return ErrorSemanticAnalyzeFail;2053 return ErrorSemanticAnalyzeFail;
2053 }2054 }
...@@ -2452,7 +2453,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {...@@ -2452,7 +2453,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
2452 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {2453 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {
2453 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2454 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2454 add_node_error(g, decl_node,2455 add_node_error(g, decl_node,
2455 buf_sprintf("struct '%s' depends on its own alignment", buf_ptr(&struct_type->name)));2456 buf_sprintf("struct '%s' depends on itself", buf_ptr(&struct_type->name)));
2456 }2457 }
2457 return ErrorSemanticAnalyzeFail;2458 return ErrorSemanticAnalyzeFail;
2458 }2459 }
...@@ -3661,8 +3662,9 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node, bool all...@@ -3661,8 +3662,9 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node, bool all
3661 }3662 }
3662 }3663 }
36633664
3664 if (g->trace_err != nullptr && source_node != nullptr) {3665 if (g->trace_err != nullptr && source_node != nullptr && !source_node->already_traced_this_node) {
3665 g->trace_err = add_error_note(g, g->trace_err, source_node, buf_create_from_str("referenced here"));3666 g->trace_err = add_error_note(g, g->trace_err, source_node, buf_create_from_str("referenced here"));
3667 source_node->already_traced_this_node = true;
3666 }3668 }
3667}3669}
36683670
src/analyze.hpp+1-1
...@@ -11,7 +11,7 @@...@@ -11,7 +11,7 @@
11#include "all_types.hpp"11#include "all_types.hpp"
1212
13void semantic_analyze(CodeGen *g);13void semantic_analyze(CodeGen *g);
14ErrorMsg *add_node_error(CodeGen *g, const AstNode *node, Buf *msg);14ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);
15ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg);15ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg);
16ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, const AstNode *node, Buf *msg);16ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, const AstNode *node, Buf *msg);
17ZigType *new_type_table_entry(ZigTypeId id);17ZigType *new_type_table_entry(ZigTypeId id);
src/ir.cpp+35-8
...@@ -10818,6 +10818,8 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod...@@ -10818,6 +10818,8 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
10818 }10818 }
1081910819
10820 ConstExprValue *result = ir_exec_const_result(codegen, analyzed_executable);10820 ConstExprValue *result = ir_exec_const_result(codegen, analyzed_executable);
10821 if (type_is_invalid(result->type))
10822 return &codegen->invalid_instruction->value;
1082110823
10822 if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed)))10824 if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed)))
10823 return &codegen->invalid_instruction->value;10825 return &codegen->invalid_instruction->value;
...@@ -14330,6 +14332,10 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -14330,6 +14332,10 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
14330 // since it's a comptime val there are no instructions for it.14332 // since it's a comptime val there are no instructions for it.
14331 // we memcpy the init value here14333 // we memcpy the init value here
14332 IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr);14334 IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr);
14335 if (type_is_invalid(deref->value.type)) {
14336 var->var_type = ira->codegen->builtin_types.entry_invalid;
14337 return ira->codegen->invalid_instruction;
14338 }
14333 // If this assertion trips, something is wrong with the IR instructions, because14339 // If this assertion trips, something is wrong with the IR instructions, because
14334 // we expected the above deref to return a constant value, but it created a runtime14340 // we expected the above deref to return a constant value, but it created a runtime
14335 // instruction.14341 // instruction.
...@@ -21957,6 +21963,11 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -21957,6 +21963,11 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
21957 if (slice_ptr == nullptr)21963 if (slice_ptr == nullptr)
21958 return ira->codegen->invalid_instruction;21964 return ira->codegen->invalid_instruction;
2195921965
21966 if (slice_ptr->special == ConstValSpecialUndef) {
21967 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));
21968 return ira->codegen->invalid_instruction;
21969 }
21970
21960 parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index];21971 parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index];
21961 if (parent_ptr->special == ConstValSpecialUndef) {21972 if (parent_ptr->special == ConstValSpecialUndef) {
21962 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));21973 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));
...@@ -22836,6 +22847,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -22836,6 +22847,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
22836 size_t param_count = proto_node->data.fn_proto.params.length;22847 size_t param_count = proto_node->data.fn_proto.params.length;
22837 lazy_fn_type->proto_node = proto_node;22848 lazy_fn_type->proto_node = proto_node;
22838 lazy_fn_type->param_types = allocate<ConstExprValue *>(param_count);22849 lazy_fn_type->param_types = allocate<ConstExprValue *>(param_count);
22850 lazy_fn_type->param_type_src_nodes = allocate<AstNode *>(param_count);
2283922851
22840 for (size_t param_index = 0; param_index < param_count; param_index += 1) {22852 for (size_t param_index = 0; param_index < param_count; param_index += 1) {
22841 AstNode *param_node = proto_node->data.fn_proto.params.at(param_index);22853 AstNode *param_node = proto_node->data.fn_proto.params.at(param_index);
...@@ -22865,6 +22877,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -22865,6 +22877,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
22865 if (param_type_val == nullptr)22877 if (param_type_val == nullptr)
22866 return ira->codegen->invalid_instruction;22878 return ira->codegen->invalid_instruction;
22867 lazy_fn_type->param_types[param_index] = param_type_val;22879 lazy_fn_type->param_types[param_index] = param_type_val;
22880 lazy_fn_type->param_type_src_nodes[param_index] = instruction->param_types[param_index]->source_node;
22868 }22881 }
2286922882
22870 if (instruction->align_value != nullptr) {22883 if (instruction->align_value != nullptr) {
...@@ -22876,6 +22889,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -22876,6 +22889,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
22876 lazy_fn_type->return_type = ir_resolve_const(ira, instruction->return_type->child, LazyOk);22889 lazy_fn_type->return_type = ir_resolve_const(ira, instruction->return_type->child, LazyOk);
22877 if (lazy_fn_type->return_type == nullptr)22890 if (lazy_fn_type->return_type == nullptr)
22878 return ira->codegen->invalid_instruction;22891 return ira->codegen->invalid_instruction;
22892 lazy_fn_type->return_type_src_node = instruction->return_type->source_node;
2287922893
22880 return result;22894 return result;
22881}22895}
...@@ -25187,7 +25201,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -25187,7 +25201,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
25187 } else {25201 } else {
25188 new_exec->first_err_trace_msg = ira->codegen->trace_err;25202 new_exec->first_err_trace_msg = ira->codegen->trace_err;
25189 }25203 }
25190 if (new_exec->first_err_trace_msg != nullptr) {25204 if (new_exec->first_err_trace_msg != nullptr &&
25205 !old_instruction->source_node->already_traced_this_node)
25206 {
25207 old_instruction->source_node->already_traced_this_node = true;
25191 new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg,25208 new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg,
25192 old_instruction->source_node, buf_create_from_str("referenced here"));25209 old_instruction->source_node, buf_create_from_str("referenced here"));
25193 }25210 }
...@@ -25204,7 +25221,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -25204,7 +25221,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2520425221
25205 if (new_exec->first_err_trace_msg != nullptr) {25222 if (new_exec->first_err_trace_msg != nullptr) {
25206 codegen->trace_err = new_exec->first_err_trace_msg;25223 codegen->trace_err = new_exec->first_err_trace_msg;
25207 if (codegen->trace_err != nullptr) {25224 if (codegen->trace_err != nullptr && new_exec->source_node != nullptr &&
25225 !new_exec->source_node->already_traced_this_node)
25226 {
25227 new_exec->source_node->already_traced_this_node = true;
25208 codegen->trace_err = add_error_note(codegen, codegen->trace_err,25228 codegen->trace_err = add_error_note(codegen, codegen->trace_err,
25209 new_exec->source_node, buf_create_from_str("referenced here"));25229 new_exec->source_node, buf_create_from_str("referenced here"));
25210 }25230 }
...@@ -25435,14 +25455,15 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As...@@ -25435,14 +25455,15 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As
25435 param_info->type = nullptr;25455 param_info->type = nullptr;
25436 return get_generic_fn_type(codegen, &fn_type_id);25456 return get_generic_fn_type(codegen, &fn_type_id);
25437 } else {25457 } else {
25438 ZigType *param_type = ir_resolve_const_type(codegen, exec, source_node,25458 AstNode *param_src_node = lazy_fn_type->param_type_src_nodes[fn_type_id.next_param_index];
25459 ZigType *param_type = ir_resolve_const_type(codegen, exec, param_src_node,
25439 lazy_fn_type->param_types[fn_type_id.next_param_index]);25460 lazy_fn_type->param_types[fn_type_id.next_param_index]);
25440 if (type_is_invalid(param_type))25461 if (type_is_invalid(param_type))
25441 return nullptr;25462 return nullptr;
25442 switch (type_requires_comptime(codegen, param_type)) {25463 switch (type_requires_comptime(codegen, param_type)) {
25443 case ReqCompTimeYes:25464 case ReqCompTimeYes:
25444 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {25465 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
25445 exec_add_error_node(codegen, exec, source_node,25466 exec_add_error_node(codegen, exec, param_src_node,
25446 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",25467 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",
25447 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));25468 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
25448 return nullptr;25469 return nullptr;
...@@ -25459,7 +25480,7 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As...@@ -25459,7 +25480,7 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As
25459 if ((err = type_resolve(codegen, param_type, ResolveStatusZeroBitsKnown)))25480 if ((err = type_resolve(codegen, param_type, ResolveStatusZeroBitsKnown)))
25460 return nullptr;25481 return nullptr;
25461 if (!type_has_bits(param_type)) {25482 if (!type_has_bits(param_type)) {
25462 exec_add_error_node(codegen, exec, source_node,25483 exec_add_error_node(codegen, exec, param_src_node,
25463 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",25484 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
25464 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));25485 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
25465 return nullptr;25486 return nullptr;
...@@ -25474,11 +25495,13 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As...@@ -25474,11 +25495,13 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As
25474 return nullptr;25495 return nullptr;
25475 }25496 }
2547625497
25477 fn_type_id.return_type = ir_resolve_const_type(codegen, exec, source_node, lazy_fn_type->return_type);25498 fn_type_id.return_type = ir_resolve_const_type(codegen, exec, lazy_fn_type->return_type_src_node,
25499 lazy_fn_type->return_type);
25478 if (type_is_invalid(fn_type_id.return_type))25500 if (type_is_invalid(fn_type_id.return_type))
25479 return nullptr;25501 return nullptr;
25480 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {25502 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
25481 exec_add_error_node(codegen, exec, source_node, buf_create_from_str("return type cannot be opaque"));25503 exec_add_error_node(codegen, exec, lazy_fn_type->return_type_src_node,
25504 buf_create_from_str("return type cannot be opaque"));
25482 return nullptr;25505 return nullptr;
25483 }25506 }
2548425507
...@@ -25653,11 +25676,15 @@ static Error ir_resolve_lazy_raw(CodeGen *codegen, AstNode *source_node, ConstEx...@@ -25653,11 +25676,15 @@ static Error ir_resolve_lazy_raw(CodeGen *codegen, AstNode *source_node, ConstEx
25653Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val) {25676Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val) {
25654 Error err;25677 Error err;
25655 if ((err = ir_resolve_lazy_raw(codegen, source_node, val))) {25678 if ((err = ir_resolve_lazy_raw(codegen, source_node, val))) {
25656 if (codegen->trace_err != nullptr) {25679 if (codegen->trace_err != nullptr && !source_node->already_traced_this_node) {
25680 source_node->already_traced_this_node = true;
25657 codegen->trace_err = add_error_note(codegen, codegen->trace_err, source_node,25681 codegen->trace_err = add_error_note(codegen, codegen->trace_err, source_node,
25658 buf_create_from_str("referenced here"));25682 buf_create_from_str("referenced here"));
25659 }25683 }
25660 return err;25684 return err;
25661 }25685 }
25686 if (type_is_invalid(val->type)) {
25687 return ErrorSemanticAnalyzeFail;
25688 }
25662 return ErrorNone;25689 return ErrorNone;
25663}25690}
test/compile_errors.zig+37-35
...@@ -481,7 +481,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -481,7 +481,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
481 \\}481 \\}
482 ,482 ,
483 "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches",483 "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches",
484 "tmp.zig:1:29: note: called from here",484 "tmp.zig:1:29: note: referenced here",
485 "tmp.zig:5:18: note: referenced here",
485 );486 );
486487
487 cases.add(488 cases.add(
...@@ -645,7 +646,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -645,7 +646,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
645 \\const A = struct { a : A, };646 \\const A = struct { a : A, };
646 \\export fn entry() usize { return @sizeOf(A); }647 \\export fn entry() usize { return @sizeOf(A); }
647 ,648 ,
648 "tmp.zig:1:11: error: struct 'A' contains itself",649 "tmp.zig:1:11: error: struct 'A' depends on itself",
649 );650 );
650651
651 cases.add(652 cases.add(
...@@ -655,7 +656,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -655,7 +656,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
655 \\const C = struct { a : A, };656 \\const C = struct { a : A, };
656 \\export fn entry() usize { return @sizeOf(A); }657 \\export fn entry() usize { return @sizeOf(A); }
657 ,658 ,
658 "tmp.zig:1:11: error: struct 'A' contains itself",659 "tmp.zig:1:11: error: struct 'A' depends on itself",
659 );660 );
660661
661 cases.add(662 cases.add(
...@@ -670,7 +671,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -670,7 +671,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
670 \\ return @sizeOf(@typeOf(foo.x));671 \\ return @sizeOf(@typeOf(foo.x));
671 \\}672 \\}
672 ,673 ,
673 "tmp.zig:1:13: error: struct 'Foo' contains itself",674 "tmp.zig:1:13: error: struct 'Foo' depends on itself",
674 "tmp.zig:8:28: note: referenced here",675 "tmp.zig:8:28: note: referenced here",
675 );676 );
676677
...@@ -689,7 +690,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -689,7 +690,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
689 \\}690 \\}
690 ,691 ,
691 "tmp.zig:7:9: error: dependency loop detected",692 "tmp.zig:7:9: error: dependency loop detected",
692 "tmp.zig:2:19: note: called from here",693 "tmp.zig:2:19: note: referenced here",
693 "tmp.zig:10:21: note: referenced here",694 "tmp.zig:10:21: note: referenced here",
694 );695 );
695696
...@@ -703,7 +704,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -703,7 +704,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
703 \\ var s: Foo = Foo.E;704 \\ var s: Foo = Foo.E;
704 \\}705 \\}
705 ,706 ,
706 "tmp.zig:1:17: error: 'Foo' depends on itself",707 "tmp.zig:1:17: error: enum 'Foo' depends on itself",
707 );708 );
708709
709 cases.add(710 cases.add(
...@@ -866,7 +867,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -866,7 +867,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
866 break :x tc;867 break :x tc;
867 });868 });
868869
869 cases.addTest(870 cases.add(
870 "export generic function",871 "export generic function",
871 \\export fn foo(num: var) i32 {872 \\export fn foo(num: var) i32 {
872 \\ return 0;873 \\ return 0;
...@@ -875,17 +876,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -875,17 +876,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
875 "tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'ccc'",876 "tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'ccc'",
876 );877 );
877878
878 cases.addTest(879 cases.add(
879 "C pointer to c_void",880 "C pointer to c_void",
880 \\export fn a() void {881 \\export fn a() void {
881 \\ var x: *c_void = undefined;882 \\ var x: *c_void = undefined;
882 \\ var y: [*c]c_void = x;883 \\ var y: [*c]c_void = x;
883 \\}884 \\}
884 ,885 ,
885 "tmp.zig:3:12: error: C pointers cannot point opaque types",886 "tmp.zig:3:16: error: C pointers cannot point opaque types",
886 );887 );
887888
888 cases.addTest(889 cases.add(
889 "directly embedding opaque type in struct and union",890 "directly embedding opaque type in struct and union",
890 \\const O = @OpaqueType();891 \\const O = @OpaqueType();
891 \\const Foo = struct {892 \\const Foo = struct {
...@@ -906,7 +907,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -906,7 +907,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
906 "tmp.zig:7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions",907 "tmp.zig:7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions",
907 );908 );
908909
909 cases.addTest(910 cases.add(
910 "implicit cast between C pointer and Zig pointer - bad const/align/child",911 "implicit cast between C pointer and Zig pointer - bad const/align/child",
911 \\export fn a() void {912 \\export fn a() void {
912 \\ var x: [*c]u8 = undefined;913 \\ var x: [*c]u8 = undefined;
...@@ -942,7 +943,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -942,7 +943,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
942 "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'",943 "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'",
943 );944 );
944945
945 cases.addTest(946 cases.add(
946 "implicit casting null c pointer to zig pointer",947 "implicit casting null c pointer to zig pointer",
947 \\comptime {948 \\comptime {
948 \\ var c_ptr: [*c]u8 = 0;949 \\ var c_ptr: [*c]u8 = 0;
...@@ -952,7 +953,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -952,7 +953,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
952 "tmp.zig:3:24: error: null pointer casted to type '*u8'",953 "tmp.zig:3:24: error: null pointer casted to type '*u8'",
953 );954 );
954955
955 cases.addTest(956 cases.add(
956 "implicit casting undefined c pointer to zig pointer",957 "implicit casting undefined c pointer to zig pointer",
957 \\comptime {958 \\comptime {
958 \\ var c_ptr: [*c]u8 = undefined;959 \\ var c_ptr: [*c]u8 = undefined;
...@@ -962,7 +963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -962,7 +963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
962 "tmp.zig:3:24: error: use of undefined value here causes undefined behavior",963 "tmp.zig:3:24: error: use of undefined value here causes undefined behavior",
963 );964 );
964965
965 cases.addTest(966 cases.add(
966 "implicit casting C pointers which would mess up null semantics",967 "implicit casting C pointers which would mess up null semantics",
967 \\export fn entry() void {968 \\export fn entry() void {
968 \\ var slice: []const u8 = "aoeu";969 \\ var slice: []const u8 = "aoeu";
...@@ -987,7 +988,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -987,7 +988,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
987 "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'",988 "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'",
988 );989 );
989990
990 cases.addTest(991 cases.add(
991 "implicit casting too big integers to C pointers",992 "implicit casting too big integers to C pointers",
992 \\export fn a() void {993 \\export fn a() void {
993 \\ var ptr: [*c]u8 = (1 << 64) + 1;994 \\ var ptr: [*c]u8 = (1 << 64) + 1;
...@@ -1001,14 +1002,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1001,14 +1002,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1001 "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'",1002 "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'",
1002 );1003 );
10031004
1004 cases.addTest(1005 cases.add(
1005 "C pointer pointing to non C ABI compatible type or has align attr",1006 "C pointer pointing to non C ABI compatible type or has align attr",
1006 \\const Foo = struct {};1007 \\const Foo = struct {};
1007 \\export fn a() void {1008 \\export fn a() void {
1008 \\ const T = [*c]Foo;1009 \\ const T = [*c]Foo;
1009 \\}1010 \\}
1010 ,1011 ,
1011 "tmp.zig:3:15: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",1012 "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",
1012 );1013 );
10131014
1014 cases.addCase(x: {1015 cases.addCase(x: {
...@@ -1029,7 +1030,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1029,7 +1030,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1029 break :x tc;1030 break :x tc;
1030 });1031 });
10311032
1032 cases.addTest(1033 cases.add(
1033 "assign to invalid dereference",1034 "assign to invalid dereference",
1034 \\export fn entry() void {1035 \\export fn entry() void {
1035 \\ 'a'.* = 1;1036 \\ 'a'.* = 1;
...@@ -1038,7 +1039,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1038,7 +1039,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1038 "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'",1039 "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'",
1039 );1040 );
10401041
1041 cases.addTest(1042 cases.add(
1042 "take slice of invalid dereference",1043 "take slice of invalid dereference",
1043 \\export fn entry() void {1044 \\export fn entry() void {
1044 \\ const x = 'a'.*[0..];1045 \\ const x = 'a'.*[0..];
...@@ -1047,7 +1048,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1047,7 +1048,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1047 "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'",1048 "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'",
1048 );1049 );
10491050
1050 cases.addTest(1051 cases.add(
1051 "@truncate undefined value",1052 "@truncate undefined value",
1052 \\export fn entry() void {1053 \\export fn entry() void {
1053 \\ var z = @truncate(u8, u16(undefined));1054 \\ var z = @truncate(u8, u16(undefined));
...@@ -1935,7 +1936,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1935,7 +1936,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1935 "unknown length pointer to opaque",1936 "unknown length pointer to opaque",
1936 \\export const T = [*]@OpaqueType();1937 \\export const T = [*]@OpaqueType();
1937 ,1938 ,
1938 "tmp.zig:1:18: error: unknown-length pointer to opaque",1939 "tmp.zig:1:21: error: unknown-length pointer to opaque",
1939 );1940 );
19401941
1941 cases.add(1942 cases.add(
...@@ -2924,7 +2925,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2924,7 +2925,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2924 \\fn a() *noreturn {}2925 \\fn a() *noreturn {}
2925 \\export fn entry() void { _ = a(); }2926 \\export fn entry() void { _ = a(); }
2926 ,2927 ,
2927 "tmp.zig:1:8: error: pointer to noreturn not allowed",2928 "tmp.zig:1:9: error: pointer to noreturn not allowed",
2928 );2929 );
29292930
2930 cases.add(2931 cases.add(
...@@ -3606,8 +3607,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3606,8 +3607,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3606 \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }3607 \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }
3607 ,3608 ,
3608 "tmp.zig:5:25: error: unable to evaluate constant expression",3609 "tmp.zig:5:25: error: unable to evaluate constant expression",
3609 "tmp.zig:2:12: note: called from here",3610 "tmp.zig:2:12: note: referenced here",
3610 "tmp.zig:2:8: note: called from here",3611 "tmp.zig:2:8: note: referenced here",
3611 );3612 );
36123613
3613 cases.add(3614 cases.add(
...@@ -3701,7 +3702,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3701,7 +3702,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3701 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }3702 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
3702 ,3703 ,
3703 "tmp.zig:3:14: error: division by zero",3704 "tmp.zig:3:14: error: division by zero",
3704 "tmp.zig:1:14: note: called from here",3705 "tmp.zig:1:14: note: referenced here",
3705 );3706 );
37063707
3707 cases.add(3708 cases.add(
...@@ -4133,7 +4134,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4133,7 +4134,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4133 \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); }4134 \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); }
4134 ,4135 ,
4135 "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches",4136 "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches",
4136 "tmp.zig:3:21: note: called from here",4137 "tmp.zig:1:37: note: referenced here",
4138 "tmp.zig:6:50: note: referenced here",
4137 );4139 );
41384140
4139 cases.add(4141 cases.add(
...@@ -4174,7 +4176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4174,7 +4176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4174 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }4176 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
4175 ,4177 ,
4176 "tmp.zig:6:26: error: unable to evaluate constant expression",4178 "tmp.zig:6:26: error: unable to evaluate constant expression",
4177 "tmp.zig:4:17: note: called from here",4179 "tmp.zig:4:17: note: referenced here",
4178 );4180 );
41794181
4180 cases.add(4182 cases.add(
...@@ -4257,7 +4259,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4257,7 +4259,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4257 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }4259 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
4258 ,4260 ,
4259 "tmp.zig:3:12: error: negation caused overflow",4261 "tmp.zig:3:12: error: negation caused overflow",
4260 "tmp.zig:1:14: note: called from here",4262 "tmp.zig:1:14: note: referenced here",
4261 );4263 );
42624264
4263 cases.add(4265 cases.add(
...@@ -4270,7 +4272,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4270,7 +4272,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4270 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }4272 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
4271 ,4273 ,
4272 "tmp.zig:3:14: error: operation caused overflow",4274 "tmp.zig:3:14: error: operation caused overflow",
4273 "tmp.zig:1:14: note: called from here",4275 "tmp.zig:1:14: note: referenced here",
4274 );4276 );
42754277
4276 cases.add(4278 cases.add(
...@@ -4283,7 +4285,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4283,7 +4285,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4283 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }4285 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
4284 ,4286 ,
4285 "tmp.zig:3:14: error: operation caused overflow",4287 "tmp.zig:3:14: error: operation caused overflow",
4286 "tmp.zig:1:14: note: called from here",4288 "tmp.zig:1:14: note: referenced here",
4287 );4289 );
42884290
4289 cases.add(4291 cases.add(
...@@ -4296,7 +4298,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4296,7 +4298,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4296 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }4298 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
4297 ,4299 ,
4298 "tmp.zig:3:14: error: operation caused overflow",4300 "tmp.zig:3:14: error: operation caused overflow",
4299 "tmp.zig:1:14: note: called from here",4301 "tmp.zig:1:14: note: referenced here",
4300 );4302 );
43014303
4302 cases.add(4304 cases.add(
...@@ -4388,7 +4390,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4388,7 +4390,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4388 \\}4390 \\}
4389 ,4391 ,
4390 "tmp.zig:3:7: error: unable to evaluate constant expression",4392 "tmp.zig:3:7: error: unable to evaluate constant expression",
4391 "tmp.zig:16:19: note: called from here",4393 "tmp.zig:16:19: note: referenced here",
4392 );4394 );
43934395
4394 cases.add(4396 cases.add(
...@@ -4618,7 +4620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4618,7 +4620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4618 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }4620 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
4619 ,4621 ,
4620 "tmp.zig:2:26: error: index 1 outside argument list of size 1",4622 "tmp.zig:2:26: error: index 1 outside argument list of size 1",
4621 "tmp.zig:6:15: note: called from here",4623 "tmp.zig:6:15: note: referenced here",
4622 );4624 );
46234625
4624 cases.add(4626 cases.add(
...@@ -4717,7 +4719,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4717,7 +4719,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4717 \\}4719 \\}
4718 ,4720 ,
4719 "tmp.zig:10:14: error: unable to evaluate constant expression",4721 "tmp.zig:10:14: error: unable to evaluate constant expression",
4720 "tmp.zig:6:20: note: called from here",4722 "tmp.zig:6:20: note: referenced here",
4721 );4723 );
47224724
4723 cases.add(4725 cases.add(
...@@ -5864,7 +5866,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5864,7 +5866,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5864 \\}5866 \\}
5865 ,5867 ,
5866 "tmp.zig:4:25: error: aoeu",5868 "tmp.zig:4:25: error: aoeu",
5867 "tmp.zig:1:36: note: called from here",5869 "tmp.zig:1:36: note: referenced here",
5868 "tmp.zig:12:20: note: referenced here",5870 "tmp.zig:12:20: note: referenced here",
5869 );5871 );
58705872