diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-07-01 17:28:21 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-07-02 13:28:29 -0700 |
| commit | 7a2e0d98109d39f06400dfbc03c12695557100c6 (patch) | |
| tree | 58908c6ff36a758ba8b980dbf7026882912d18af /src | |
| parent | 41336acb0bb89dd23ef9c49b15d91a847f6796bc (diff) | |
| download | zig-7a2e0d98109d39f06400dfbc03c12695557100c6.tar.gz zig-7a2e0d98109d39f06400dfbc03c12695557100c6.zip | |
AstGen: cleanups to pass more compile error test cases
Diffstat (limited to 'src')
| -rw-r--r-- | src/AstGen.zig | 33 | ||||
| -rw-r--r-- | src/stage1/astgen.cpp | 14 | ||||
| -rw-r--r-- | src/stage1/ir.cpp | 12 |
3 files changed, 35 insertions, 24 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index c38ba755e7..4e3473629b 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -1704,7 +1704,7 @@ fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: ast.Toke }, &[_]u32{ try astgen.errNoteTok( prev_label.token, - "previous definition is here", + "previous definition here", .{}, ), }); @@ -4002,7 +4002,18 @@ fn containerDecl( return astgen.failTok(comptime_token, "enum fields cannot be marked comptime", .{}); } if (member.ast.type_expr != 0) { - return astgen.failNode(member.ast.type_expr, "enum fields do not have types", .{}); + return astgen.failNodeNotes( + member.ast.type_expr, + "enum fields do not have types", + .{}, + &[_]u32{ + try astgen.errNoteNode( + node, + "consider 'union(enum)' here to make it a tagged union", + .{}, + ), + }, + ); } // Alignment expressions in enums are caught by the parser. assert(member.ast.align_expr == 0); @@ -4520,7 +4531,7 @@ fn tryExpr( return astgen.failNode(node, "invalid 'try' outside function scope", .{}); }; - if (parent_gz.in_defer) return astgen.failNode(node, "'try' is not allowed inside defer expression", .{}); + if (parent_gz.in_defer) return astgen.failNode(node, "'try' not allowed inside defer expression", .{}); var block_scope = parent_gz.makeSubBlock(scope); block_scope.setBreakResultLoc(rl); @@ -5526,7 +5537,7 @@ fn switchExpr( &[_]u32{ try astgen.errNoteTok( src, - "previous else prong is here", + "previous else prong here", .{}, ), }, @@ -5539,12 +5550,12 @@ fn switchExpr( &[_]u32{ try astgen.errNoteTok( case_src, - "else prong is here", + "else prong here", .{}, ), try astgen.errNoteTok( some_underscore, - "'_' prong is here", + "'_' prong here", .{}, ), }, @@ -5567,7 +5578,7 @@ fn switchExpr( &[_]u32{ try astgen.errNoteTok( src, - "previous '_' prong is here", + "previous '_' prong here", .{}, ), }, @@ -5580,12 +5591,12 @@ fn switchExpr( &[_]u32{ try astgen.errNoteTok( some_else, - "else prong is here", + "else prong here", .{}, ), try astgen.errNoteTok( case_src, - "'_' prong is here", + "'_' prong here", .{}, ), }, @@ -9638,7 +9649,7 @@ fn detectLocalShadowing( }, &[_]u32{ try astgen.errNoteTok( local_val.token_src, - "previously declared here", + "previous declaration here", .{}, ), }); @@ -9655,7 +9666,7 @@ fn detectLocalShadowing( }, &[_]u32{ try astgen.errNoteTok( local_ptr.token_src, - "previously declared here", + "previous declaration here", .{}, ), }); diff --git a/src/stage1/astgen.cpp b/src/stage1/astgen.cpp index a95d0af9de..5cad78d120 100644 --- a/src/stage1/astgen.cpp +++ b/src/stage1/astgen.cpp @@ -3169,7 +3169,7 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, if (existing_var->var_type == nullptr || !type_is_invalid(existing_var->var_type)) { ErrorMsg *msg = add_node_error(codegen, node, buf_sprintf("redeclaration of variable '%s'", buf_ptr(name))); - add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here")); + add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration here")); } variable_entry->var_type = codegen->builtin_types.entry_invalid; } else { @@ -3191,7 +3191,7 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, if (want_err_msg) { ErrorMsg *msg = add_node_error(codegen, node, buf_sprintf("redefinition of '%s'", buf_ptr(name))); - add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition is here")); + add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition here")); } variable_entry->var_type = codegen->builtin_types.entry_invalid; } @@ -3247,7 +3247,7 @@ static bool is_duplicate_label(CodeGen *g, Scope *scope, AstNode *node, Buf *nam Buf *this_block_name = scope->id == ScopeIdBlock ? ((ScopeBlock *)scope)->name : ((ScopeLoop *)scope)->name; if (this_block_name != nullptr && buf_eql_buf(name, this_block_name)) { ErrorMsg *msg = add_node_error(g, node, buf_sprintf("redeclaration of label '%s'", buf_ptr(name))); - add_error_note(g, msg, scope->source_node, buf_sprintf("previous declaration is here")); + add_error_note(g, msg, scope->source_node, buf_sprintf("previous declaration here")); return true; } } @@ -7026,7 +7026,7 @@ static IrInstSrc *astgen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no ErrorMsg *msg = add_node_error(ag->codegen, prong_node, buf_sprintf("multiple else prongs in switch expression")); add_error_note(ag->codegen, msg, else_prong, - buf_sprintf("previous else prong is here")); + buf_sprintf("previous else prong here")); return ag->codegen->invalid_inst_src; } else_prong = prong_node; @@ -7037,7 +7037,7 @@ static IrInstSrc *astgen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no ErrorMsg *msg = add_node_error(ag->codegen, prong_node, buf_sprintf("multiple '_' prongs in switch expression")); add_error_note(ag->codegen, msg, underscore_prong, - buf_sprintf("previous '_' prong is here")); + buf_sprintf("previous '_' prong here")); return ag->codegen->invalid_inst_src; } underscore_prong = prong_node; @@ -7049,10 +7049,10 @@ static IrInstSrc *astgen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no buf_sprintf("else and '_' prong in switch expression")); if (underscore_prong == prong_node) add_error_note(ag->codegen, msg, else_prong, - buf_sprintf("else prong is here")); + buf_sprintf("else prong here")); else add_error_note(ag->codegen, msg, underscore_prong, - buf_sprintf("'_' prong is here")); + buf_sprintf("'_' prong here")); return ag->codegen->invalid_inst_src; } ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index 0c915f5c35..accc1c43f8 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -11097,7 +11097,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport AstNode *other_export_node = entry->value->source_node; ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name))); - add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol is here")); + add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol here")); return ira->codegen->invalid_inst_gen; } @@ -11403,7 +11403,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern AstNode *other_extern_node = entry->value->source_node; ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, buf_sprintf("extern symbol collision: '%s'", buf_ptr(symbol_name))); - add_error_note(ira->codegen, msg, other_extern_node, buf_sprintf("other symbol is here")); + add_error_note(ira->codegen, msg, other_extern_node, buf_sprintf("other symbol here")); return ira->codegen->invalid_inst_gen; } @@ -21732,7 +21732,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(enum_field->name))); - add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here")); + add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here")); } bigint_incr(&field_index); } @@ -21818,7 +21818,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name; ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name))); - add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here")); + add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here")); } field_prev_uses[start_index] = start_value->base.source_node; } @@ -21880,7 +21880,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, start_value->base.source_node); if (prev_node != nullptr) { ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value")); - add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value is here")); + add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value here")); return ira->codegen->invalid_inst_gen; } } @@ -21965,7 +21965,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, auto entry = prevs.put_unique(const_expr_val->data.x_type, value); if(entry != nullptr) { ErrorMsg *msg = ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value")); - add_error_note(ira->codegen, msg, entry->value->base.source_node, buf_sprintf("previous value is here")); + add_error_note(ira->codegen, msg, entry->value->base.source_node, buf_sprintf("previous value here")); prevs.deinit(); return ira->codegen->invalid_inst_gen; } |
