authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-01-23 22:40:12+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-01-23 22:40:12+01:00
log8d9b8ab930d8633b9e9e77a80a36fa08a5e7f3f5
tree19606bbd361440098d445c7781f7fa0a9cbb39ef
parent357f42da6c2f158fff2afa28a56b7e0e7a8a5963

More error checking for unresolved TLDs

Closes #4274

2 files changed, 34 insertions(+), 16 deletions(-)

src/ir.cpp+28-16
......@@ -264,6 +264,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
264264 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
265265static ResultLoc *no_result_loc(void);
266266static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value);
267static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr);
267268
268269static void destroy_instruction(IrInstruction *inst) {
269270#ifdef ZIG_ENABLE_MEM_PROFILE
......@@ -20022,8 +20023,13 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
2002220023 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
2002320024 if (tld->resolution == TldResolutionInvalid)
2002420025 return ira->codegen->invalid_instruction;
20026 if (tld->resolution == TldResolutionResolving)
20027 return ir_error_dependency_loop(ira, source_instr);
20028
2002520029 TldFn *tld_fn = (TldFn *)tld;
2002620030 ZigFn *fn_entry = tld_fn->fn_entry;
20031 assert(fn_entry != nullptr);
20032
2002720033 if (type_is_invalid(fn_entry->type_entry))
2002820034 return ira->codegen->invalid_instruction;
2002920035
......@@ -20034,8 +20040,13 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
2003420040 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
2003520041 if (tld->resolution == TldResolutionInvalid)
2003620042 return ira->codegen->invalid_instruction;
20043 if (tld->resolution == TldResolutionResolving)
20044 return ir_error_dependency_loop(ira, source_instr);
20045
2003720046 TldVar *tld_var = (TldVar *)tld;
2003820047 ZigVar *var = tld_var->var;
20048 assert(var != nullptr);
20049
2003920050 if (type_is_invalid(var->var_type))
2004020051 return ira->codegen->invalid_instruction;
2004120052
......@@ -20369,9 +20380,10 @@ static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *so
2036920380
2037020381static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
2037120382 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true);
20372 if (tld->resolution == TldResolutionInvalid) {
20383 if (tld->resolution == TldResolutionInvalid)
2037320384 return ira->codegen->invalid_instruction;
20374 }
20385 if (tld->resolution == TldResolutionResolving)
20386 return ir_error_dependency_loop(ira, source_instruction);
2037520387
2037620388 switch (tld->id) {
2037720389 case TldIdContainer:
......@@ -20381,9 +20393,8 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_
2038120393 case TldIdVar: {
2038220394 TldVar *tld_var = (TldVar *)tld;
2038320395 ZigVar *var = tld_var->var;
20384 if (var == nullptr) {
20385 return ir_error_dependency_loop(ira, source_instruction);
20386 }
20396 assert(var != nullptr);
20397
2038720398 if (tld_var->extern_lib_name != nullptr) {
2038820399 add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name),
2038920400 source_instruction->source_node);
......@@ -20394,7 +20405,7 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_
2039420405 case TldIdFn: {
2039520406 TldFn *tld_fn = (TldFn *)tld;
2039620407 ZigFn *fn_entry = tld_fn->fn_entry;
20397 assert(fn_entry->type_entry);
20408 assert(fn_entry->type_entry != nullptr);
2039820409
2039920410 if (type_is_invalid(fn_entry->type_entry))
2040020411 return ira->codegen->invalid_instruction;
......@@ -22628,11 +22639,14 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2262822639
2262922640 while ((curr_entry = decl_it.next()) != nullptr) {
2263022641 // If the declaration is unresolved, force it to be resolved again.
22631 if (curr_entry->value->resolution == TldResolutionUnresolved) {
22632 resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node, false);
22633 if (curr_entry->value->resolution != TldResolutionOk) {
22634 return ErrorSemanticAnalyzeFail;
22635 }
22642 resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node, false);
22643 if (curr_entry->value->resolution == TldResolutionInvalid) {
22644 return ErrorSemanticAnalyzeFail;
22645 }
22646
22647 if (curr_entry->value->resolution == TldResolutionResolving) {
22648 ir_error_dependency_loop(ira, source_instr);
22649 return ErrorSemanticAnalyzeFail;
2263622650 }
2263722651
2263822652 // Skip comptime blocks and test functions.
......@@ -22689,6 +22703,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2268922703 case TldIdVar:
2269022704 {
2269122705 ZigVar *var = ((TldVar *)curr_entry->value)->var;
22706 assert(var != nullptr);
22707
2269222708 if ((err = type_resolve(ira->codegen, var->const_value->type, ResolveStatusSizeKnown)))
2269322709 return ErrorSemanticAnalyzeFail;
2269422710
......@@ -22719,11 +22735,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2271922735
2272022736 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
2272122737 assert(!fn_entry->is_test);
22722
22723 if (fn_entry->type_entry == nullptr) {
22724 ir_error_dependency_loop(ira, source_instr);
22725 return ErrorSemanticAnalyzeFail;
22726 }
22738 assert(fn_entry->type_entry != nullptr);
2272722739
2272822740 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;
2272922741
test/compile_errors.zig+6
......@@ -2,6 +2,12 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.addTest("dependency loop in top-level decl with @TypeInfo",
6 \\export const foo = @typeInfo(@This());
7 , &[_][]const u8{
8 "tmp.zig:1:20: error: dependency loop detected",
9 });
10
511 cases.addTest("non-exhaustive enums",
612 \\const A = enum {
713 \\ a,