authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-13 23:02:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-13 23:02:45-07:00
log1141e4f5b262f7490fe554cd4334ec6b1c886c5f
tree18d068ad0145d87c8579ddacf4fa9eea91f7e09b
parent01fda6199ee0e2b5f79e58cbd862bd4882615a4b

if any c imports fail, don't emit undefined identifier errors


2 files changed, 20 insertions(+), 8 deletions(-)

src/all_types.hpp+1
......@@ -992,6 +992,7 @@ struct ImportTableEntry {
992992 BlockContext *block_context;
993993 ZigList<ImporterInfo> importers;
994994 AstNode *c_import_node;
995 bool any_imports_failed;
995996
996997 // reminder: hash tables must be initialized before use
997998 HashMap<Buf *, FnTableEntry *, buf_hash, buf_eql_buf> fn_table;
src/analyze.cpp+19-8
......@@ -1378,6 +1378,15 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A
13781378 child_import->error_table.init(8);
13791379 child_import->c_import_node = node;
13801380
1381 child_import->importers.append({parent_import, node});
1382
1383 if (node->data.c_import.visib_mod != VisibModPrivate) {
1384 for (int i = 0; i < parent_import->importers.length; i += 1) {
1385 ImporterInfo importer = parent_import->importers.at(i);
1386 child_import->importers.append(importer);
1387 }
1388 }
1389
13811390 ZigList<ErrorMsg *> errors = {0};
13821391
13831392 int err;
......@@ -1391,6 +1400,10 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A
13911400 ErrorMsg *err_msg = errors.at(i);
13921401 err_msg_add_note(parent_err_msg, err_msg);
13931402 }
1403
1404 for (int i = 0; i < child_import->importers.length; i += 1) {
1405 child_import->importers.at(i).import->any_imports_failed = true;
1406 }
13941407 return;
13951408 }
13961409
......@@ -1402,14 +1415,6 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A
14021415
14031416 child_import->di_file = parent_import->di_file;
14041417 child_import->block_context = new_block_context(child_import->root, nullptr);
1405 child_import->importers.append({parent_import, node});
1406
1407 if (node->data.c_import.visib_mod != VisibModPrivate) {
1408 for (int i = 0; i < parent_import->importers.length; i += 1) {
1409 ImporterInfo importer = parent_import->importers.at(i);
1410 child_import->importers.append(importer);
1411 }
1412 }
14131418
14141419 detect_top_level_decl_deps(g, child_import, child_import->root);
14151420 analyze_top_level_decls_root(g, child_import, child_import->root);
......@@ -2613,6 +2618,12 @@ static TypeTableEntry *analyze_symbol_expr(CodeGen *g, ImportTableEntry *import,
26132618 return resolve_expr_const_val_as_fn(g, node, context, fn_table_entry->value);
26142619 }
26152620
2621 if (import->any_imports_failed) {
2622 // skip the error message since we had a failing import in this file
2623 // if an import breaks we don't need 9999 undeclared identifier errors
2624 return g->builtin_types.entry_invalid;
2625 }
2626
26162627 add_node_error(g, node, buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name)));
26172628 return g->builtin_types.entry_invalid;
26182629}