diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-02-13 23:02:45 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-02-13 23:02:45 -0700 |
| commit | 1141e4f5b262f7490fe554cd4334ec6b1c886c5f (patch) | |
| tree | 18d068ad0145d87c8579ddacf4fa9eea91f7e09b /src | |
| parent | 01fda6199ee0e2b5f79e58cbd862bd4882615a4b (diff) | |
| download | zig-1141e4f5b262f7490fe554cd4334ec6b1c886c5f.tar.gz zig-1141e4f5b262f7490fe554cd4334ec6b1c886c5f.zip | |
if any c imports fail, don't emit undefined identifier errors
Diffstat (limited to 'src')
| -rw-r--r-- | src/all_types.hpp | 1 | ||||
| -rw-r--r-- | src/analyze.cpp | 27 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp index 037d34ddd9..894be41b2d 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -992,6 +992,7 @@ struct ImportTableEntry { BlockContext *block_context; ZigList<ImporterInfo> importers; AstNode *c_import_node; + bool any_imports_failed; // reminder: hash tables must be initialized before use HashMap<Buf *, FnTableEntry *, buf_hash, buf_eql_buf> fn_table; diff --git a/src/analyze.cpp b/src/analyze.cpp index 44edc95e09..adab231124 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1378,6 +1378,15 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A child_import->error_table.init(8); child_import->c_import_node = node; + child_import->importers.append({parent_import, node}); + + if (node->data.c_import.visib_mod != VisibModPrivate) { + for (int i = 0; i < parent_import->importers.length; i += 1) { + ImporterInfo importer = parent_import->importers.at(i); + child_import->importers.append(importer); + } + } + ZigList<ErrorMsg *> errors = {0}; int err; @@ -1391,6 +1400,10 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A ErrorMsg *err_msg = errors.at(i); err_msg_add_note(parent_err_msg, err_msg); } + + for (int i = 0; i < child_import->importers.length; i += 1) { + child_import->importers.at(i).import->any_imports_failed = true; + } return; } @@ -1402,14 +1415,6 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A child_import->di_file = parent_import->di_file; child_import->block_context = new_block_context(child_import->root, nullptr); - child_import->importers.append({parent_import, node}); - - if (node->data.c_import.visib_mod != VisibModPrivate) { - for (int i = 0; i < parent_import->importers.length; i += 1) { - ImporterInfo importer = parent_import->importers.at(i); - child_import->importers.append(importer); - } - } detect_top_level_decl_deps(g, child_import, child_import->root); analyze_top_level_decls_root(g, child_import, child_import->root); @@ -2613,6 +2618,12 @@ static TypeTableEntry *analyze_symbol_expr(CodeGen *g, ImportTableEntry *import, return resolve_expr_const_val_as_fn(g, node, context, fn_table_entry->value); } + if (import->any_imports_failed) { + // skip the error message since we had a failing import in this file + // if an import breaks we don't need 9999 undeclared identifier errors + return g->builtin_types.entry_invalid; + } + add_node_error(g, node, buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name))); return g->builtin_types.entry_invalid; } |
