Summary
While reviewing main..HEAD with the locally built binary (dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll), I found a separate C# symbol-extraction false positive:
- a local variable declaration like
const string content = "hello"; is indexed as a phantom function content
- a multiline assertion/call argument like
elapsed < TimeSpan.FromSeconds(10), is indexed as a phantom function FromSeconds with bogus return_type = "elapsed <"
This pollutes symbols / outline and can make definition point at non-definitions.
Minimal repro
CDIDX='dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll'
TMPDIR=$(mktemp -d /tmp/cdidx-csharp-phantom-fn.XXXXXX)
cat > "$TMPDIR/Repro.cs" <<'EOF'
using System;
namespace Demo;
public class Repro
{
public void M(TimeSpan elapsed)
{
const string content = "hello";
Assert.True(
elapsed < TimeSpan.FromSeconds(10),
$"x {elapsed.TotalSeconds:F2}");
}
}
public static class Assert
{
public static void True(bool condition, string message) { }
}
EOF
"$CDIDX" index "$TMPDIR" --json >/dev/null
DB="$TMPDIR/.cdidx/codeindex.db"
"$CDIDX" symbols --db "$DB" --json --lang csharp
Observed extra rows:
{"kind":"function","name":"content","line":8,"signature":"const string content = \"hello\";","return_type":"string"}
{"kind":"function","name":"FromSeconds","line":10,"signature":"elapsed < TimeSpan.FromSeconds(10),","return_type":"elapsed <"}
Expected:
- only the real symbols (
namespace Demo, class Repro, function M, class Assert, function True)
- no
function content
- no
function FromSeconds
Why it matters
This is not just cosmetic noise:
outline of C# test files becomes misleading
definition content / definition FromSeconds can point at statements or expressions instead of real definitions
- AI consumers using symbol lists for orientation get false structure inside method bodies
I first noticed it on this repo's own tests/CodeIndex.Tests/SymbolExtractorTests.cs, where outline surfaced both a phantom content symbol from a fixture local and a phantom FromSeconds symbol from an Assert.True(...) argument.
Suspected direction
The C# method/function regex path is still accepting some statement-shaped lines once extraction is inside a method body.
Likely hardening points:
- reject local variable declarations (
const string content = ..., var x = ..., typed locals)
- reject expression fragments / argument lines that only contain a call site (
elapsed < TimeSpan.FromSeconds(10),)
- add explicit regression tests for both shapes in
tests/CodeIndex.Tests/SymbolExtractorTests.cs
Scope
src/CodeIndex/Indexer/SymbolExtractor.cs
tests/CodeIndex.Tests/SymbolExtractorTests.cs
Environment
- Reproduced on macOS arm64
- Binary: local build from current HEAD via
dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll
- Discovered during adversarial review of
fix-issue361
Summary
While reviewing
main..HEADwith the locally built binary (dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll), I found a separate C# symbol-extraction false positive:const string content = "hello";is indexed as a phantomfunction contentelapsed < TimeSpan.FromSeconds(10),is indexed as a phantomfunction FromSecondswith bogusreturn_type = "elapsed <"This pollutes
symbols/outlineand can makedefinitionpoint at non-definitions.Minimal repro
Observed extra rows:
{"kind":"function","name":"content","line":8,"signature":"const string content = \"hello\";","return_type":"string"} {"kind":"function","name":"FromSeconds","line":10,"signature":"elapsed < TimeSpan.FromSeconds(10),","return_type":"elapsed <"}Expected:
namespace Demo,class Repro,function M,class Assert,function True)function contentfunction FromSecondsWhy it matters
This is not just cosmetic noise:
outlineof C# test files becomes misleadingdefinition content/definition FromSecondscan point at statements or expressions instead of real definitionsI first noticed it on this repo's own
tests/CodeIndex.Tests/SymbolExtractorTests.cs, whereoutlinesurfaced both a phantomcontentsymbol from a fixture local and a phantomFromSecondssymbol from anAssert.True(...)argument.Suspected direction
The C# method/function regex path is still accepting some statement-shaped lines once extraction is inside a method body.
Likely hardening points:
const string content = ...,var x = ..., typed locals)elapsed < TimeSpan.FromSeconds(10),)tests/CodeIndex.Tests/SymbolExtractorTests.csScope
src/CodeIndex/Indexer/SymbolExtractor.cstests/CodeIndex.Tests/SymbolExtractorTests.csEnvironment
dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dllfix-issue361