fix(c,cpp): system #include resolves to same-named in-repo headers
Child of #2959. One ticket for both languages on purpose — resolveCppImportTarget delegates to resolveCImportTarget, so this is one code path and two tickets would be two people fixing it.
The defect
#include <stdio.h> → src/stdio.h (C)
#include <cstdio.h> → src/cstdio.h (C++)
Reproduced by the c and cpp arms of test/unit/scope-resolution/external-import-conformance.test.ts (both recorded in KNOWN_GAPS). Workspace:
src/stdio.h ← an unrelated local header that shadows the system one
include/util.h
src/main.c ← the importer
A repository containing its own stdio.h, string.h or vector — which is common in embedded code, in compatibility shims and in vendored libc replacements — captures every system include of that name.
The rule this should be
C and C++ already draw the distinction this needs, in the syntax:
#include "x.h"searches the including file's directory first, then the include path. Resolving it in-repo is correct.#include <x.h>searches only the implementation-defined system paths and the configured include path. It should resolve in-repo only when the repo declares that directory as an include path.
Verify first whether the parser preserves the distinction. If ParsedImport.targetRaw arrives with the brackets or quotes stripped and no flag recording which form was used, that is the first thing to fix — without it, the resolver cannot tell a system include from a local one, and no gate downstream can recover the information.
Worth handling deliberately:
- the headers the C/C++ resolvers receive come through
resolutionConfig, notallFilePaths(seenewPassinbench/import-target/measure.mjs) — the gate belongs where that set is consulted; - there is no manifest to read: CMake/Makefile include paths are not parsed today, and parsing them is a much larger job. A gate on the angle/quote form alone closes the reported case without needing them;
- a repo genuinely providing its own
stdio.hon the include path exists — fail open rather than refusing all system includes if include-path evidence is ever added and comes back incomplete.
Acceptance
#include <stdio.h>resolves tonullin the fixture above;#include "util.h"still resolves.- Both the
candcppentries leaveKNOWN_GAPSand both arms go green with no other edit to the suite.
Source: abhigyanpatwari/GitNexus