Summary
For C++, a method call obj.method() is resolved by a global method-name lookup.
When two files each define a class with the same name and method, every caller
collapses onto the first matching definition, and the other file's method
receives no incoming calls edge. With distinct class names the same code
resolves precisely, so this only affects same-named classes across files.
Reproduction
Two files, each defining class Logger { void log(); } and a caller:
// a/svc.cpp
class Logger { public: void log() { int a = 1; } };
void useA() { Logger lg; lg.log(); }
// b/svc.cpp
class Logger { public: void log() { int b = 2; } };
void useB() { Logger lg; lg.log(); }
codegraph init
sqlite3 .codegraph/codegraph.db \
"SELECT s.name, t.name, t.file_path FROM edges e
JOIN nodes s ON e.source=s.id JOIN nodes t ON e.target=t.id
WHERE e.kind='calls' AND s.language='cpp' ORDER BY s.name;"
Output — useB lives in b/svc.cpp but its call resolves to a/svc.cpp:
useA|log|a/svc.cpp
useB|log|a/svc.cpp
b/svc.cpp's Logger::log has no incoming calls edge.
Control: distinct class names resolve correctly
With class LoggerA in a/svc.cpp and class LoggerB in b/svc.cpp (callers
unchanged), the same query gives:
useA|log|a/svc.cpp
useB|log|b/svc.cpp
Expected
useB constructs a local Logger and calls .log(), so the call would resolve
to b/svc.cpp's Logger::log (each caller to its own file's definition).
Likely cause
In src/resolution/name-matcher.ts, resolveMethodOnType() looks up the method
by name globally (getNodesByName); when several definitions match
Logger::log, disambiguation by file path appears to be gated on preferredFqn,
which seems to be populated only for Java/Kotlin (from import hints). C++ call
sites have no such hint, so resolution falls through to the first match
(matches[0]).
Environment
- codegraph 1.1.0
- macOS (Darwin arm64)
Summary
For C++, a method call
obj.method()is resolved by a global method-name lookup.When two files each define a class with the same name and method, every caller
collapses onto the first matching definition, and the other file's method
receives no incoming
callsedge. With distinct class names the same coderesolves precisely, so this only affects same-named classes across files.
Reproduction
Two files, each defining
class Logger { void log(); }and a caller:Output —
useBlives inb/svc.cppbut its call resolves toa/svc.cpp:b/svc.cpp'sLogger::loghas no incomingcallsedge.Control: distinct class names resolve correctly
With
class LoggerAina/svc.cppandclass LoggerBinb/svc.cpp(callersunchanged), the same query gives:
Expected
useBconstructs a localLoggerand calls.log(), so the call would resolveto
b/svc.cpp'sLogger::log(each caller to its own file's definition).Likely cause
In
src/resolution/name-matcher.ts,resolveMethodOnType()looks up the methodby name globally (
getNodesByName); when several definitions matchLogger::log, disambiguation by file path appears to be gated onpreferredFqn,which seems to be populated only for Java/Kotlin (from import hints). C++ call
sites have no such hint, so resolution falls through to the first match
(
matches[0]).Environment