From 11c7dbbee481c30c330b3ef39475011519dce5f3 Mon Sep 17 00:00:00 2001 From: shivasurya Date: Sat, 1 Nov 2025 18:38:26 -0400 Subject: [PATCH] fix(callgraph): Add fallback stdlib check for direct module imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves issue where stdlib calls like os.path.join were not being resolved when modules were imported directly (import os.path). **Problem:** - Code like `import os.path; os.path.join()` was not resolving - importMap.Resolve("os") fails because import is "os.path", not "os" - Target "os.path.join" never reached stdlib validation logic - Result: 310+ stdlib calls marked as unresolved "external_framework" **Solution:** - Add fallback stdlib check before giving up on resolution - Check if target itself is a stdlib call (e.g., os.path.join) - Uses existing validateStdlibFQN() with os.path -> posixpath aliasing **Impact:** - Resolution improved: 66.3% -> 72.1% (+310 calls, +5.8%) - os.* unresolved: 311 -> 1 (99.7% reduction) - os.path.join no longer in top 20 unresolved patterns **Test Results:** - All tests passing (gradle testGo) - Zero lint issues (gradle lintGo) - Validated on pre-commit codebase (5,367 calls) **Remaining Unresolved Stdlib Calls:** Analysis shows ~135 stdlib calls still unresolved, all requiring type inference: - f.read/f.write (62 calls) - need to infer file object type - parser.add_argument (22 calls) - need function param annotations - logger.warning (18 calls) - need assignment type inference - cfg.read/write (33 calls) - need configparser type inference These require Phase 3 type inference enhancements (not in PR #2 scope). Related: PR #2 (stdlib registry loader) Next: PR #3 (remote registry hosting) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- sourcecode-parser/graph/callgraph/builder.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sourcecode-parser/graph/callgraph/builder.go b/sourcecode-parser/graph/callgraph/builder.go index 178da275..ca83f73b 100644 --- a/sourcecode-parser/graph/callgraph/builder.go +++ b/sourcecode-parser/graph/callgraph/builder.go @@ -735,6 +735,14 @@ func resolveCallTarget(target string, importMap *ImportMap, registry *ModuleRegi return ormFQN, true, nil } + // PR #2: Last resort - check if target is a stdlib call (e.g., os.path.join) + // This handles cases where stdlib modules are imported directly (import os.path) + if typeEngine != nil && typeEngine.StdlibRegistry != nil { + if validateStdlibFQN(target, typeEngine.StdlibRegistry) { + return target, true, nil + } + } + // Can't resolve - return as-is return target, false, nil }