authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-01 17:28:21-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-02 13:28:29-07:00
log7a2e0d98109d39f06400dfbc03c12695557100c6
tree58908c6ff36a758ba8b980dbf7026882912d18af
parent41336acb0bb89dd23ef9c49b15d91a847f6796bc

AstGen: cleanups to pass more compile error test cases


9 files changed, 132 insertions(+), 118 deletions(-)

lib/std/zig/ast.zig+2
......@@ -135,6 +135,8 @@ pub const Tree = struct {
135135 const token_tags = tree.tokens.items(.tag);
136136 switch (parse_error.tag) {
137137 .asterisk_after_ptr_deref => {
138 // Note that the token will point at the `.*` but ideally the source
139 // location would point to the `*` after the `.*`.
138140 return stream.writeAll("'.*' cannot be followed by '*'. Are you missing a space?");
139141 },
140142 .decl_between_fields => {
lib/std/zig/tokenizer.zig+8-2
......@@ -708,12 +708,18 @@ pub const Tokenizer = struct {
708708 self.checkLiteralCharacter();
709709 }
710710 },
711 '\n', '\r' => break, // Look for this error later.
711 '\n' => {
712 result.tag = .invalid;
713 break;
714 },
712715 else => self.checkLiteralCharacter(),
713716 },
714717
715718 .string_literal_backslash => switch (c) {
716 '\n', '\r' => break, // Look for this error later.
719 '\n' => {
720 result.tag = .invalid;
721 break;
722 },
717723 else => {
718724 state = .string_literal;
719725 },
src/AstGen.zig+22-11
......@@ -1704,7 +1704,7 @@ fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: ast.Toke
17041704 }, &[_]u32{
17051705 try astgen.errNoteTok(
17061706 prev_label.token,
1707 "previous definition is here",
1707 "previous definition here",
17081708 .{},
17091709 ),
17101710 });
......@@ -4002,7 +4002,18 @@ fn containerDecl(
40024002 return astgen.failTok(comptime_token, "enum fields cannot be marked comptime", .{});
40034003 }
40044004 if (member.ast.type_expr != 0) {
4005 return astgen.failNode(member.ast.type_expr, "enum fields do not have types", .{});
4005 return astgen.failNodeNotes(
4006 member.ast.type_expr,
4007 "enum fields do not have types",
4008 .{},
4009 &[_]u32{
4010 try astgen.errNoteNode(
4011 node,
4012 "consider 'union(enum)' here to make it a tagged union",
4013 .{},
4014 ),
4015 },
4016 );
40064017 }
40074018 // Alignment expressions in enums are caught by the parser.
40084019 assert(member.ast.align_expr == 0);
......@@ -4520,7 +4531,7 @@ fn tryExpr(
45204531 return astgen.failNode(node, "invalid 'try' outside function scope", .{});
45214532 };
45224533
4523 if (parent_gz.in_defer) return astgen.failNode(node, "'try' is not allowed inside defer expression", .{});
4534 if (parent_gz.in_defer) return astgen.failNode(node, "'try' not allowed inside defer expression", .{});
45244535
45254536 var block_scope = parent_gz.makeSubBlock(scope);
45264537 block_scope.setBreakResultLoc(rl);
......@@ -5526,7 +5537,7 @@ fn switchExpr(
55265537 &[_]u32{
55275538 try astgen.errNoteTok(
55285539 src,
5529 "previous else prong is here",
5540 "previous else prong here",
55305541 .{},
55315542 ),
55325543 },
......@@ -5539,12 +5550,12 @@ fn switchExpr(
55395550 &[_]u32{
55405551 try astgen.errNoteTok(
55415552 case_src,
5542 "else prong is here",
5553 "else prong here",
55435554 .{},
55445555 ),
55455556 try astgen.errNoteTok(
55465557 some_underscore,
5547 "'_' prong is here",
5558 "'_' prong here",
55485559 .{},
55495560 ),
55505561 },
......@@ -5567,7 +5578,7 @@ fn switchExpr(
55675578 &[_]u32{
55685579 try astgen.errNoteTok(
55695580 src,
5570 "previous '_' prong is here",
5581 "previous '_' prong here",
55715582 .{},
55725583 ),
55735584 },
......@@ -5580,12 +5591,12 @@ fn switchExpr(
55805591 &[_]u32{
55815592 try astgen.errNoteTok(
55825593 some_else,
5583 "else prong is here",
5594 "else prong here",
55845595 .{},
55855596 ),
55865597 try astgen.errNoteTok(
55875598 case_src,
5588 "'_' prong is here",
5599 "'_' prong here",
55895600 .{},
55905601 ),
55915602 },
......@@ -9638,7 +9649,7 @@ fn detectLocalShadowing(
96389649 }, &[_]u32{
96399650 try astgen.errNoteTok(
96409651 local_val.token_src,
9641 "previously declared here",
9652 "previous declaration here",
96429653 .{},
96439654 ),
96449655 });
......@@ -9655,7 +9666,7 @@ fn detectLocalShadowing(
96559666 }, &[_]u32{
96569667 try astgen.errNoteTok(
96579668 local_ptr.token_src,
9658 "previously declared here",
9669 "previous declaration here",
96599670 .{},
96609671 ),
96619672 });
src/stage1/astgen.cpp+7-7
......@@ -3169,7 +3169,7 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
31693169 if (existing_var->var_type == nullptr || !type_is_invalid(existing_var->var_type)) {
31703170 ErrorMsg *msg = add_node_error(codegen, node,
31713171 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
3172 add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
3172 add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration here"));
31733173 }
31743174 variable_entry->var_type = codegen->builtin_types.entry_invalid;
31753175 } else {
......@@ -3191,7 +3191,7 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
31913191 if (want_err_msg) {
31923192 ErrorMsg *msg = add_node_error(codegen, node,
31933193 buf_sprintf("redefinition of '%s'", buf_ptr(name)));
3194 add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition is here"));
3194 add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition here"));
31953195 }
31963196 variable_entry->var_type = codegen->builtin_types.entry_invalid;
31973197 }
......@@ -3247,7 +3247,7 @@ static bool is_duplicate_label(CodeGen *g, Scope *scope, AstNode *node, Buf *nam
32473247 Buf *this_block_name = scope->id == ScopeIdBlock ? ((ScopeBlock *)scope)->name : ((ScopeLoop *)scope)->name;
32483248 if (this_block_name != nullptr && buf_eql_buf(name, this_block_name)) {
32493249 ErrorMsg *msg = add_node_error(g, node, buf_sprintf("redeclaration of label '%s'", buf_ptr(name)));
3250 add_error_note(g, msg, scope->source_node, buf_sprintf("previous declaration is here"));
3250 add_error_note(g, msg, scope->source_node, buf_sprintf("previous declaration here"));
32513251 return true;
32523252 }
32533253 }
......@@ -7026,7 +7026,7 @@ static IrInstSrc *astgen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no
70267026 ErrorMsg *msg = add_node_error(ag->codegen, prong_node,
70277027 buf_sprintf("multiple else prongs in switch expression"));
70287028 add_error_note(ag->codegen, msg, else_prong,
7029 buf_sprintf("previous else prong is here"));
7029 buf_sprintf("previous else prong here"));
70307030 return ag->codegen->invalid_inst_src;
70317031 }
70327032 else_prong = prong_node;
......@@ -7037,7 +7037,7 @@ static IrInstSrc *astgen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no
70377037 ErrorMsg *msg = add_node_error(ag->codegen, prong_node,
70387038 buf_sprintf("multiple '_' prongs in switch expression"));
70397039 add_error_note(ag->codegen, msg, underscore_prong,
7040 buf_sprintf("previous '_' prong is here"));
7040 buf_sprintf("previous '_' prong here"));
70417041 return ag->codegen->invalid_inst_src;
70427042 }
70437043 underscore_prong = prong_node;
......@@ -7049,10 +7049,10 @@ static IrInstSrc *astgen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no
70497049 buf_sprintf("else and '_' prong in switch expression"));
70507050 if (underscore_prong == prong_node)
70517051 add_error_note(ag->codegen, msg, else_prong,
7052 buf_sprintf("else prong is here"));
7052 buf_sprintf("else prong here"));
70537053 else
70547054 add_error_note(ag->codegen, msg, underscore_prong,
7055 buf_sprintf("'_' prong is here"));
7055 buf_sprintf("'_' prong here"));
70567056 return ag->codegen->invalid_inst_src;
70577057 }
70587058 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
src/stage1/ir.cpp+6-6
......@@ -11097,7 +11097,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1109711097 AstNode *other_export_node = entry->value->source_node;
1109811098 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
1109911099 buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name)));
11100 add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol is here"));
11100 add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol here"));
1110111101 return ira->codegen->invalid_inst_gen;
1110211102 }
1110311103
......@@ -11403,7 +11403,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
1140311403 AstNode *other_extern_node = entry->value->source_node;
1140411404 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
1140511405 buf_sprintf("extern symbol collision: '%s'", buf_ptr(symbol_name)));
11406 add_error_note(ira->codegen, msg, other_extern_node, buf_sprintf("other symbol is here"));
11406 add_error_note(ira->codegen, msg, other_extern_node, buf_sprintf("other symbol here"));
1140711407 return ira->codegen->invalid_inst_gen;
1140811408 }
1140911409
......@@ -21732,7 +21732,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2173221732 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
2173321733 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name),
2173421734 buf_ptr(enum_field->name)));
21735 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));
21735 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here"));
2173621736 }
2173721737 bigint_incr(&field_index);
2173821738 }
......@@ -21818,7 +21818,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2181821818 Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name;
2181921819 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
2182021820 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name)));
21821 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));
21821 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here"));
2182221822 }
2182321823 field_prev_uses[start_index] = start_value->base.source_node;
2182421824 }
......@@ -21880,7 +21880,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2188021880 start_value->base.source_node);
2188121881 if (prev_node != nullptr) {
2188221882 ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value"));
21883 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value is here"));
21883 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value here"));
2188421884 return ira->codegen->invalid_inst_gen;
2188521885 }
2188621886 }
......@@ -21965,7 +21965,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2196521965 auto entry = prevs.put_unique(const_expr_val->data.x_type, value);
2196621966 if(entry != nullptr) {
2196721967 ErrorMsg *msg = ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value"));
21968 add_error_note(ira->codegen, msg, entry->value->base.source_node, buf_sprintf("previous value is here"));
21968 add_error_note(ira->codegen, msg, entry->value->base.source_node, buf_sprintf("previous value here"));
2196921969 prevs.deinit();
2197021970 return ira->codegen->invalid_inst_gen;
2197121971 }
test/cases.zig+2-2
......@@ -25,7 +25,7 @@ pub fn addCases(ctx: *TestContext) !void {
2525 var case = ctx.exe("hello world with updates", linux_x64);
2626
2727 case.addError("", &[_][]const u8{
28 ":93:9: error: struct 'test_case.test_case' has no member named 'main'",
28 ":93:9: error: struct 'tmp.tmp' has no member named 'main'",
2929 });
3030
3131 // Incorrect return type
......@@ -965,7 +965,7 @@ pub fn addCases(ctx: *TestContext) !void {
965965 \\ defer return a();
966966 \\}
967967 , &[_][]const u8{
968 ":7:8: error: try is not allowed inside defer expression",
968 ":7:8: error: 'try' not allowed inside defer expression",
969969 ":10:8: error: cannot return from defer expression",
970970 });
971971
test/compile_errors.zig+78-83
......@@ -614,11 +614,11 @@ pub fn addCases(ctx: *TestContext) !void {
614614 \\}
615615 , &[_][]const u8{
616616 "tmp.zig:2:12: error: redefinition of label 'blk'",
617 "tmp.zig:2:5: note: previous definition is here",
617 "tmp.zig:2:5: note: previous definition here",
618618 "tmp.zig:5:26: error: redefinition of label 'blk'",
619 "tmp.zig:5:5: note: previous definition is here",
619 "tmp.zig:5:5: note: previous definition here",
620620 "tmp.zig:8:46: error: redefinition of label 'blk'",
621 "tmp.zig:8:5: note: previous definition is here",
621 "tmp.zig:8:5: note: previous definition here",
622622 "tmp.zig:11:5: error: unused block label",
623623 "tmp.zig:14:5: error: unused while loop label",
624624 "tmp.zig:17:5: error: unused for loop label",
......@@ -4261,7 +4261,7 @@ pub fn addCases(ctx: *TestContext) !void {
42614261 \\}
42624262 , &[_][]const u8{
42634263 "tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'",
4264 "tmp.zig:3:14: note: other value is here",
4264 "tmp.zig:3:14: note: other value here",
42654265 });
42664266
42674267 ctx.objErrStage1("invalid cast from integral type to enum",
......@@ -4932,8 +4932,8 @@ pub fn addCases(ctx: *TestContext) !void {
49324932 });
49334933
49344934 ctx.objErrStage1("wrong number of arguments",
4935 \\export fn a() void {
4936 \\ b(1);
4935 \\export fn d() void {
4936 \\ e(1);
49374937 \\}
49384938 \\fn b(a: i32, b: i32, c: i32) void { _ = a; _ = b; _ = c; }
49394939 , &[_][]const u8{
......@@ -4988,7 +4988,7 @@ pub fn addCases(ctx: *TestContext) !void {
49884988 \\}
49894989 \\export fn entry() void { f(1, 2); }
49904990 , &[_][]const u8{
4991 "tmp.zig:1:15: error: redeclaration of parameter 'a'",
4991 "tmp.zig:1:15: error: redeclaration of function parameter 'a'",
49924992 "tmp.zig:1:6: note: previous declaration here",
49934993 });
49944994
......@@ -4998,7 +4998,7 @@ pub fn addCases(ctx: *TestContext) !void {
49984998 \\ var a = 0;
49994999 \\}
50005000 , &[_][]const u8{
5001 "tmp.zig:3:9: error: redeclaration of local const 'a'",
5001 "tmp.zig:3:9: error: redeclaration of local constant 'a'",
50025002 "tmp.zig:2:11: note: previous declaration here",
50035003 });
50045004
......@@ -5008,7 +5008,7 @@ pub fn addCases(ctx: *TestContext) !void {
50085008 \\}
50095009 \\export fn entry() void { f(1); }
50105010 , &[_][]const u8{
5011 "tmp.zig:2:11: error: redeclaration of parameter 'a'",
5011 "tmp.zig:2:11: error: redeclaration of function parameter 'a'",
50125012 "tmp.zig:1:6: note: previous declaration here",
50135013 });
50145014
......@@ -5295,7 +5295,7 @@ pub fn addCases(ctx: *TestContext) !void {
52955295 \\ _ = foo;
52965296 \\}
52975297 , &[_][]const u8{
5298 "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax",
5298 "tmp.zig:1:13: error: initializing array with struct syntax",
52995299 });
53005300
53015301 ctx.objErrStage1("type variables must be constant",
......@@ -5307,23 +5307,28 @@ pub fn addCases(ctx: *TestContext) !void {
53075307 "tmp.zig:1:1: error: variable of type 'type' must be constant",
53085308 });
53095309
5310 ctx.objErrStage1("variables shadowing types",
5310 ctx.objErrStage1("parameter shadowing global",
5311 \\const Foo = struct {};
5312 \\fn f(Foo: i32) void {}
5313 \\export fn entry() void {
5314 \\ f(1234);
5315 \\}
5316 , &[_][]const u8{
5317 "tmp.zig:2:6: error: local shadows declaration of 'Foo'",
5318 "tmp.zig:1:1: note: declared here",
5319 });
5320
5321 ctx.objErrStage1("local variable shadowing global",
53115322 \\const Foo = struct {};
53125323 \\const Bar = struct {};
53135324 \\
5314 \\fn f(Foo: i32) void {
5325 \\export fn entry() void {
53155326 \\ var Bar : i32 = undefined;
53165327 \\ _ = Bar;
53175328 \\}
5318 \\
5319 \\export fn entry() void {
5320 \\ f(1234);
5321 \\}
53225329 , &[_][]const u8{
5323 "tmp.zig:4:6: error: redefinition of 'Foo'",
5324 "tmp.zig:1:1: note: previous definition is here",
5325 "tmp.zig:5:5: error: redefinition of 'Bar'",
5326 "tmp.zig:2:1: note: previous definition is here",
5330 "tmp.zig:5:9: error: local shadows declaration of 'Bar'",
5331 "tmp.zig:2:1: note: declared here",
53275332 });
53285333
53295334 ctx.objErrStage1("switch expression - missing enumeration prong",
......@@ -5366,7 +5371,7 @@ pub fn addCases(ctx: *TestContext) !void {
53665371 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
53675372 , &[_][]const u8{
53685373 "tmp.zig:13:15: error: duplicate switch value",
5369 "tmp.zig:10:15: note: other value is here",
5374 "tmp.zig:10:15: note: other value here",
53705375 });
53715376
53725377 ctx.objErrStage1("switch expression - duplicate enumeration prong when else present",
......@@ -5390,7 +5395,7 @@ pub fn addCases(ctx: *TestContext) !void {
53905395 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
53915396 , &[_][]const u8{
53925397 "tmp.zig:13:15: error: duplicate switch value",
5393 "tmp.zig:10:15: note: other value is here",
5398 "tmp.zig:10:15: note: other value here",
53945399 });
53955400
53965401 ctx.objErrStage1("switch expression - multiple else prongs",
......@@ -5431,7 +5436,7 @@ pub fn addCases(ctx: *TestContext) !void {
54315436 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
54325437 , &[_][]const u8{
54335438 "tmp.zig:6:9: error: duplicate switch value",
5434 "tmp.zig:5:14: note: previous value is here",
5439 "tmp.zig:5:14: note: previous value here",
54355440 });
54365441
54375442 ctx.objErrStage1("switch expression - duplicate type",
......@@ -5447,7 +5452,7 @@ pub fn addCases(ctx: *TestContext) !void {
54475452 \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
54485453 , &[_][]const u8{
54495454 "tmp.zig:6:9: error: duplicate switch value",
5450 "tmp.zig:4:9: note: previous value is here",
5455 "tmp.zig:4:9: note: previous value here",
54515456 });
54525457
54535458 ctx.objErrStage1("switch expression - duplicate type (struct alias)",
......@@ -5467,7 +5472,7 @@ pub fn addCases(ctx: *TestContext) !void {
54675472 \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
54685473 , &[_][]const u8{
54695474 "tmp.zig:10:9: error: duplicate switch value",
5470 "tmp.zig:8:9: note: previous value is here",
5475 "tmp.zig:8:9: note: previous value here",
54715476 });
54725477
54735478 ctx.objErrStage1("switch expression - switch on pointer type with no else",
......@@ -5662,10 +5667,9 @@ pub fn addCases(ctx: *TestContext) !void {
56625667 ctx.objErrStage1("normal string with newline",
56635668 \\const foo = "a
56645669 \\b";
5665 \\
5666 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
56675670 , &[_][]const u8{
5668 "tmp.zig:1:15: error: newline not allowed in string literal",
5671 "tmp.zig:1:13: error: expected expression, found 'invalid'",
5672 "tmp.zig:1:15: note: invalid byte here",
56695673 });
56705674
56715675 ctx.objErrStage1("invalid comparison for function pointers",
......@@ -6595,7 +6599,7 @@ pub fn addCases(ctx: *TestContext) !void {
65956599 \\
65966600 \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }
65976601 , &[_][]const u8{
6598 "tmp.zig:4:11: error: 'try' is not allowed inside defer expression",
6602 "tmp.zig:4:11: error: 'try' not allowed inside defer expression",
65996603 });
66006604
66016605 ctx.objErrStage1("assign too big number to u16",
......@@ -6976,7 +6980,7 @@ pub fn addCases(ctx: *TestContext) !void {
69766980 \\}
69776981 , &[_][]const u8{
69786982 "tmp.zig:9:17: error: redefinition of 'Self'",
6979 "tmp.zig:5:9: note: previous definition is here",
6983 "tmp.zig:5:9: note: previous definition here",
69806984 });
69816985
69826986 ctx.objErrStage1("while expected bool, got optional",
......@@ -7692,24 +7696,18 @@ pub fn addCases(ctx: *TestContext) !void {
76927696 \\ _ = x;
76937697 \\}
76947698 , &[_][]const u8{
7695 "tmp.zig:2:14: error: untagged union field assignment",
7696 "tmp.zig:1:24: note: consider 'union(enum)' here",
7699 "tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type",
7700 "tmp.zig:2:14: note: tag value specified here",
76977701 });
76987702
76997703 ctx.objErrStage1("enum with 0 fields",
77007704 \\const Foo = enum {};
7701 \\export fn entry() usize {
7702 \\ return @sizeOf(Foo);
7703 \\}
77047705 , &[_][]const u8{
7705 "tmp.zig:1:13: error: enums must have 1 or more fields",
7706 "tmp.zig:1:13: error: enum declarations must have at least one tag",
77067707 });
77077708
77087709 ctx.objErrStage1("union with 0 fields",
77097710 \\const Foo = union {};
7710 \\export fn entry() usize {
7711 \\ return @sizeOf(Foo);
7712 \\}
77137711 , &[_][]const u8{
77147712 "tmp.zig:1:13: error: union declarations must have at least one tag",
77157713 });
......@@ -7817,13 +7815,9 @@ pub fn addCases(ctx: *TestContext) !void {
78177815 \\ B,
78187816 \\ C,
78197817 \\};
7820 \\export fn entry() void {
7821 \\ var b = Letter.B;
7822 \\ _ = b;
7823 \\}
78247818 , &[_][]const u8{
7825 "tmp.zig:2:8: error: structs and unions, not enums, support field types",
7826 "tmp.zig:1:16: note: consider 'union(enum)' here",
7819 "tmp.zig:2:8: error: enum fields do not have types",
7820 "tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union",
78277821 });
78287822
78297823 ctx.objErrStage1("struct field missing type",
......@@ -8231,9 +8225,9 @@ pub fn addCases(ctx: *TestContext) !void {
82318225 \\}
82328226 , &[_][]const u8{
82338227 "tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed",
8234 "tmp.zig:7:28: error: parameter of type '(null)' not allowed",
8235 "tmp.zig:10:11: error: parameter of opaque type 'FooType' not allowed",
8236 "tmp.zig:15:11: error: parameter of type '(null)' not allowed",
8228 "tmp.zig:8:28: error: parameter of type '(null)' not allowed",
8229 "tmp.zig:12:11: error: parameter of opaque type 'FooType' not allowed",
8230 "tmp.zig:17:11: error: parameter of type '(null)' not allowed",
82378231 });
82388232
82398233 ctx.objErrStage1( // fixed bug #2032
......@@ -8268,8 +8262,8 @@ pub fn addCases(ctx: *TestContext) !void {
82688262 \\}
82698263 , &[_][]const u8{
82708264 "tmp.zig:3:19: error: use of undefined value here causes undefined behavior",
8271 "tmp.zig:8:23: error: use of undefined value here causes undefined behavior",
8272 "tmp.zig:14:23: error: use of undefined value here causes undefined behavior",
8265 "tmp.zig:9:23: error: use of undefined value here causes undefined behavior",
8266 "tmp.zig:16:23: error: use of undefined value here causes undefined behavior",
82738267 });
82748268
82758269 ctx.objErrStage1("issue #3818: bitcast from parray/slice to u16",
......@@ -8285,8 +8279,8 @@ pub fn addCases(ctx: *TestContext) !void {
82858279 \\}
82868280 , &[_][]const u8{
82878281 "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'",
8288 "tmp.zig:7:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16",
8289 "tmp.zig:7:37: note: referenced here",
8282 "tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16",
8283 "tmp.zig:8:37: note: referenced here",
82908284 });
82918285
82928286 // issue #7810
......@@ -8361,12 +8355,12 @@ pub fn addCases(ctx: *TestContext) !void {
83618355 \\}
83628356 , &[_][]const u8{
83638357 ":4:29: error: slice-sentinel is out of bounds",
8364 ":11:29: error: slice-sentinel is out of bounds",
8365 ":18:29: error: slice-sentinel is out of bounds",
8366 ":25:29: error: slice-sentinel is out of bounds",
8367 ":32:29: error: slice-sentinel is out of bounds",
8368 ":39:29: error: slice-sentinel is out of bounds",
8369 ":46:29: error: slice-sentinel is out of bounds",
8358 ":12:29: error: slice-sentinel is out of bounds",
8359 ":20:29: error: slice-sentinel is out of bounds",
8360 ":28:29: error: slice-sentinel is out of bounds",
8361 ":36:29: error: slice-sentinel is out of bounds",
8362 ":44:29: error: slice-sentinel is out of bounds",
8363 ":52:29: error: slice-sentinel is out of bounds",
83708364 });
83718365
83728366 ctx.objErrStage1("comptime slice-sentinel is out of bounds (terminated)",
......@@ -8427,12 +8421,12 @@ pub fn addCases(ctx: *TestContext) !void {
84278421 \\}
84288422 , &[_][]const u8{
84298423 ":4:29: error: out of bounds slice",
8430 ":11:29: error: out of bounds slice",
8431 ":18:29: error: out of bounds slice",
8432 ":25:29: error: out of bounds slice",
8433 ":32:29: error: out of bounds slice",
8434 ":39:29: error: out of bounds slice",
8435 ":46:29: error: out of bounds slice",
8424 ":12:29: error: out of bounds slice",
8425 ":20:29: error: out of bounds slice",
8426 ":28:29: error: out of bounds slice",
8427 ":36:29: error: out of bounds slice",
8428 ":44:29: error: out of bounds slice",
8429 ":52:29: error: out of bounds slice",
84368430 });
84378431
84388432 ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (unterminated)",
......@@ -8493,12 +8487,12 @@ pub fn addCases(ctx: *TestContext) !void {
84938487 \\}
84948488 , &[_][]const u8{
84958489 ":4:29: error: slice-sentinel does not match memory at target index",
8496 ":11:29: error: slice-sentinel does not match memory at target index",
8497 ":18:29: error: slice-sentinel does not match memory at target index",
8498 ":25:29: error: slice-sentinel does not match memory at target index",
8499 ":32:29: error: slice-sentinel does not match memory at target index",
8500 ":39:29: error: slice-sentinel does not match memory at target index",
8501 ":46:29: error: slice-sentinel does not match memory at target index",
8490 ":12:29: error: slice-sentinel does not match memory at target index",
8491 ":20:29: error: slice-sentinel does not match memory at target index",
8492 ":28:29: error: slice-sentinel does not match memory at target index",
8493 ":36:29: error: slice-sentinel does not match memory at target index",
8494 ":44:29: error: slice-sentinel does not match memory at target index",
8495 ":52:29: error: slice-sentinel does not match memory at target index",
85028496 });
85038497
85048498 ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (terminated)",
......@@ -8559,12 +8553,12 @@ pub fn addCases(ctx: *TestContext) !void {
85598553 \\}
85608554 , &[_][]const u8{
85618555 ":4:29: error: slice-sentinel does not match memory at target index",
8562 ":11:29: error: slice-sentinel does not match memory at target index",
8563 ":18:29: error: slice-sentinel does not match memory at target index",
8564 ":25:29: error: slice-sentinel does not match memory at target index",
8565 ":32:29: error: slice-sentinel does not match memory at target index",
8566 ":39:29: error: slice-sentinel does not match memory at target index",
8567 ":46:29: error: slice-sentinel does not match memory at target index",
8556 ":12:29: error: slice-sentinel does not match memory at target index",
8557 ":20:29: error: slice-sentinel does not match memory at target index",
8558 ":28:29: error: slice-sentinel does not match memory at target index",
8559 ":36:29: error: slice-sentinel does not match memory at target index",
8560 ":44:29: error: slice-sentinel does not match memory at target index",
8561 ":52:29: error: slice-sentinel does not match memory at target index",
85688562 });
85698563
85708564 ctx.objErrStage1("comptime slice-sentinel does not match target-sentinel",
......@@ -8625,12 +8619,12 @@ pub fn addCases(ctx: *TestContext) !void {
86258619 \\}
86268620 , &[_][]const u8{
86278621 ":4:29: error: slice-sentinel does not match target-sentinel",
8628 ":11:29: error: slice-sentinel does not match target-sentinel",
8629 ":18:29: error: slice-sentinel does not match target-sentinel",
8630 ":25:29: error: slice-sentinel does not match target-sentinel",
8631 ":32:29: error: slice-sentinel does not match target-sentinel",
8632 ":39:29: error: slice-sentinel does not match target-sentinel",
8633 ":46:29: error: slice-sentinel does not match target-sentinel",
8622 ":12:29: error: slice-sentinel does not match target-sentinel",
8623 ":20:29: error: slice-sentinel does not match target-sentinel",
8624 ":28:29: error: slice-sentinel does not match target-sentinel",
8625 ":36:29: error: slice-sentinel does not match target-sentinel",
8626 ":44:29: error: slice-sentinel does not match target-sentinel",
8627 ":52:29: error: slice-sentinel does not match target-sentinel",
86348628 });
86358629
86368630 ctx.objErrStage1("issue #4207: coerce from non-terminated-slice to terminated-pointer",
......@@ -8774,7 +8768,8 @@ pub fn addCases(ctx: *TestContext) !void {
87748768 \\ _ = sequence;
87758769 \\}
87768770 , &[_][]const u8{
8777 "tmp.zig:2:30: error: `.*` cannot be followed by `*`. Are you missing a space?",
8771 // Ideally this would be column 30 but it's not very important.
8772 "tmp.zig:2:28: error: `.*` cannot be followed by `*`. Are you missing a space?",
87788773 });
87798774
87808775 ctx.objErrStage1("Issue #9165: windows tcp server compilation error",
test/stage2/cbe.zig+6-6
......@@ -525,7 +525,7 @@ pub fn addCases(ctx: *TestContext) !void {
525525 \\}
526526 , &.{
527527 ":3:21: error: missing struct field: x",
528 ":1:15: note: struct 'test_case.Point' declared here",
528 ":1:15: note: struct 'tmp.Point' declared here",
529529 });
530530 case.addError(
531531 \\const Point = struct { x: i32, y: i32 };
......@@ -538,7 +538,7 @@ pub fn addCases(ctx: *TestContext) !void {
538538 \\ return p.y - p.x - p.x;
539539 \\}
540540 , &.{
541 ":6:10: error: no field named 'z' in struct 'test_case.Point'",
541 ":6:10: error: no field named 'z' in struct 'tmp.Point'",
542542 ":1:15: note: struct declared here",
543543 });
544544 case.addCompareOutput(
......@@ -716,7 +716,7 @@ pub fn addCases(ctx: *TestContext) !void {
716716 \\ _ = @intToEnum(E, 3);
717717 \\}
718718 , &.{
719 ":3:9: error: enum 'test_case.E' has no tag with value 3",
719 ":3:9: error: enum 'tmp.E' has no tag with value 3",
720720 ":1:11: note: enum declared here",
721721 });
722722
......@@ -732,7 +732,7 @@ pub fn addCases(ctx: *TestContext) !void {
732732 , &.{
733733 ":4:5: error: switch must handle all possibilities",
734734 ":4:5: note: unhandled enumeration value: 'b'",
735 ":1:11: note: enum 'test_case.E' declared here",
735 ":1:11: note: enum 'tmp.E' declared here",
736736 });
737737
738738 case.addError(
......@@ -787,7 +787,7 @@ pub fn addCases(ctx: *TestContext) !void {
787787 \\ _ = E.d;
788788 \\}
789789 , &.{
790 ":3:10: error: enum 'test_case.E' has no member named 'd'",
790 ":3:10: error: enum 'tmp.E' has no member named 'd'",
791791 ":1:11: note: enum declared here",
792792 });
793793
......@@ -798,7 +798,7 @@ pub fn addCases(ctx: *TestContext) !void {
798798 \\ _ = x;
799799 \\}
800800 , &.{
801 ":3:17: error: enum 'test_case.E' has no field named 'd'",
801 ":3:17: error: enum 'tmp.E' has no field named 'd'",
802802 ":1:11: note: enum declared here",
803803 });
804804 }
test/stage2/darwin.zig+1-1
......@@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void {
1414 {
1515 var case = ctx.exe("hello world with updates", target);
1616 case.addError("", &[_][]const u8{
17 ":93:9: error: struct 'test_case.test_case' has no member named 'main'",
17 ":93:9: error: struct 'tmp.tmp' has no member named 'main'",
1818 });
1919
2020 // Incorrect return type