diff --git a/stage0/sema.c b/stage0/sema.c index 97c2a5a910..f602073ae5 100644 --- a/stage0/sema.c +++ b/stage0/sema.c @@ -11403,12 +11403,33 @@ static bool analyzeBodyInner( } } } - } else if (sema->source_dir && decl_name_idx != 0) { - // Non-comptime: just load import side effects. + } else if (decl_name_idx != 0 && sema->file_idx != UINT32_MAX) { + // Non-comptime: resolve imports and local declarations. + // Import values are needed for field_val/call chains + // (e.g. common.fneg(a) in function bodies). + const char* decl_name + = (const char*)&sema->code.string_bytes[decl_name_idx]; const char* import_path = findDeclImportPath(sema, decl_name_idx); - if (import_path) { - (void)doImport(sema->source_dir, import_path); + if (import_path && sema->source_dir) { + uint32_t fid = doImport(sema->source_dir, import_path); + if (fid != UINT32_MAX) + resolved = s_file_root_type[fid]; + } else if (!import_path) { + // Local declaration: look up in file namespace. + uint32_t ns_idx = s_file_namespace[sema->file_idx]; + uint32_t nav = findNavInNamespace(ns_idx, decl_name); + if (nav != UINT32_MAX) { + if (s_in_main_analysis) { + InternPoolIndex val = ensureNavValUpToDate(nav); + if (val != IP_INDEX_NONE) + resolved = val; + } else { + const Nav* n = ipGetNav(nav); + if (n->resolved_type != IP_INDEX_NONE) + resolved = n->resolved_type; + } + } } }