Repository navigation
fix(csharp): extract past a verbatim interpolated string ending in an escaped quote (#3376) - #3612
rohit-jsfreaky wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.
Formal verification. No changes could be formally verified in this run.
Graphify review — findings
Works around a tree-sitter-c-sharp 0.23.5 grammar bug (#3376) where a verbatim interpolated string ending in an interpolation hole, an escaped quote and the terminator causes a parse error that silently drops every member after it. extract_csharp now feeds _extract_generic a source override from _normalize_csharp_verbatim_interpolation, which parses the file, and only if it errors, masks the offending trailing "" escapes (located by _csharp_broken_escape_offsets, which skips comments, char literals and other strings) with two spaces and re-parses. The rewrite is byte-length preserving so reported line/column offsets stay accurate, and it falls back to the original source untouched when the grammar is unavailable, the file already parses, or masking doesn't clear the errors.
Worth a look
- Quadratic scan on malformed C# prefix runs —
graphify/extract.py:2546· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 2027 functions depend on the 267 functions this change touches.
Health — this change adds coupling hotspots:
- new:
extract()— 647 callers, 45 callees - new:
_rebuild_code()— 129 callers, 54 callees - new:
extract_js()— 85 callers, 4 callees - new:
extract_xaml()— 19 callers, 17 callees - new:
dispatch_command()— 2 callers, 125 callees - new:
_get_extractor()— 26 callers, 6 callees - new:
run_pipeline()— 8 callers, 13 callees - new:
collect_files()— 17 callers, 6 callees - …and 30 more — each is listed as a finding
Verification — 2027 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 1852 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
118 of 287 test file(s) selected (41%) via static blast radius.
tests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_cjs_module_extension.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_enum_members.py— impacttests/test_csharp_field_generic_args.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_type_resolution.py— impacttests/test_csharp_verbatim_interpolation.py— impact, changed-testtests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_elixir_import_resolution.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impacttests/test_file_label_disambiguation.py— impacttests/test_file_node_id_spec.py— impacttests/test_forwarding_review_findings.py— impacttests/test_go_builtin_call_targets.py— impacttests/test_go_qualified_resolution.py— impacttests/test_import_extension_resolution.py— impacttests/test_import_self_loops.py— impacttests/test_imported_export_forwarding.py— impacttests/test_incremental.py— impacttests/test_indirect_call_arrow_single_param_shadow.py— impacttests/test_indirect_call_catch_binding_shadow.py— impacttests/test_indirect_call_external_import_shadow.py— impacttests/test_indirect_call_for_of_binding_shadow.py— impacttests/test_indirect_call_function_expression_shadow.py— impacttests/test_indirect_call_nested_closure_shadow.py— impacttests/test_indirect_dispatch.py— impacttests/test_indirect_dispatch_assign_return.py— impacttests/test_indirect_dispatch_getattr.py— impacttests/test_inferred_confidence_rubric.py— impacttests/test_inherited_field_receivers.py— impact- … and 68 more
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
Could not verify: Could not verify extract\_csharp.
The verifier did not have enough to check extract\_csharp, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set
· 38 more finding(s) on lines outside this diff (see the check run).
|
Follow-up pushed for the review finding. Quadratic prefix scan — confirmed, then fixed. I measured it before changing anything, on a file that is a run of
Doubling N quadrupled the time, so the finding was right, and the path is reachable — the scan only runs on files the grammar already rejected, which is exactly what such a file is. The cause was mine: when no string opened at a position I advanced a single byte, so a long
Added an eighth test that feeds it 1,000,000 characters with a 5-second ceiling, so it cannot regress quietly. The end-to-end behaviour is unchanged: the repro file still yields 10 nodes with all six methods. Separately, correcting a number in my own PR description above: I wrote "All 159 existing C# tests pass". That 159 counted this PR's own test file. The real split is 153 existing + 8 added here = 161. Apologies for the inflated figure. |
There was a problem hiding this comment.
Graphify reviewed this change.
Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).
Formal verification. No changes could be formally verified in this run.
Graphify review — findings
Works around a tree-sitter-c-sharp 0.23.5 grammar bug (#3376) where a verbatim interpolated string ending in }"" is rejected and every C# member after it silently drops from the graph. extract_csharp now runs _normalize_csharp_verbatim_interpolation, which reparses the file, locates the offending trailing "" escapes via a single-pass scan that skips comments, char literals and other strings, and overwrites each with two spaces — a byte-length-preserving mask that keeps all source locations accurate. The rewrite is only applied when the file genuinely fails to parse and the mask actually fixes it; otherwise the original source is used unchanged.
No blocking issues surfaced. 8 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 2029 functions depend on the 269 functions this change touches.
Health — this change adds coupling hotspots:
- new:
extract()— 647 callers, 45 callees - new:
_rebuild_code()— 129 callers, 54 callees - new:
extract_js()— 85 callers, 4 callees - new:
extract_xaml()— 19 callers, 17 callees - new:
dispatch_command()— 2 callers, 125 callees - new:
_get_extractor()— 26 callers, 6 callees - new:
run_pipeline()— 8 callers, 13 callees - new:
collect_files()— 17 callers, 6 callees - …and 30 more — each is listed as a finding
Verification — 2029 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 1854 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
118 of 287 test file(s) selected (41%) via static blast radius.
tests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_cjs_module_extension.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_enum_members.py— impacttests/test_csharp_field_generic_args.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_type_resolution.py— impacttests/test_csharp_verbatim_interpolation.py— impact, changed-testtests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_elixir_import_resolution.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impacttests/test_file_label_disambiguation.py— impacttests/test_file_node_id_spec.py— impacttests/test_forwarding_review_findings.py— impacttests/test_go_builtin_call_targets.py— impacttests/test_go_qualified_resolution.py— impacttests/test_import_extension_resolution.py— impacttests/test_import_self_loops.py— impacttests/test_imported_export_forwarding.py— impacttests/test_incremental.py— impacttests/test_indirect_call_arrow_single_param_shadow.py— impacttests/test_indirect_call_catch_binding_shadow.py— impacttests/test_indirect_call_external_import_shadow.py— impacttests/test_indirect_call_for_of_binding_shadow.py— impacttests/test_indirect_call_function_expression_shadow.py— impacttests/test_indirect_call_nested_closure_shadow.py— impacttests/test_indirect_dispatch.py— impacttests/test_indirect_dispatch_assign_return.py— impacttests/test_indirect_dispatch_getattr.py— impacttests/test_inferred_confidence_rubric.py— impacttests/test_inherited_field_receivers.py— impact- … and 68 more
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
Could not verify: Could not verify extract\_csharp.
The verifier did not have enough to check extract\_csharp, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set
· 38 more finding(s) on lines outside this diff (see the check run).
17811f4 to
7f0fd6d
Compare
|
Rebased onto v8 at 0.9.86 (a5ba60d), no conflicts. The new tests still fail on clean 0.9.86 and pass here. Full suite with this and my other refreshed PRs applied: 3 failed, 7324 passed. The same 3 fail on clean 0.9.86 on my machine. |
Python property-accessor decorators and `Self` (#4385, #4386), Swift `Self` (#4387), Go generic type params (#4388), the Python forward type-hint file-node fix (#4343), PowerShell dot-source paths (#4369), and the C# verbatim-interpolated-string recovery (#3612) all change AST extraction output, so warm caches must re-extract. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Shipped in v0.9.88, just released to PyPI as |
Fixes #3376
What
A C# file containing a verbatim interpolated string whose text ends with an interpolation hole, an escaped quote and then the terminator is now extracted in full. Before this, the bundled grammar rejected the literal and every member declared after that line was silently missing from the graph.
Why
The spelling is valid C# —
dotnet buildaccepts it — but tree-sitter-c-sharp 0.23.5 rejects it. As the issue shows, every neighbouring spelling parses; the trigger is specifically the}"""adjacency at the end of the literal. 0.23.5 is the newest release on PyPI and the project already allows>=0.23,<0.25, so there is no grammar bump to take.The cost is silent. The file still extracts, just not all of it, and the warning names the parser's recovery line rather than the literal — the issue reports chasing an unrelated
[InlineData]attribute because of it.How
extract_csharpnow passes the source through_normalize_csharp_verbatim_interpolation, the samesource_overrideseamextract_js,extract_vueandextract_cppalready use.Only the trailing escape is overwritten, with two spaces. The rewrite is byte-length preserving — nothing is inserted or deleted and no line break is touched — so every offset, line and column still points at the same place in the file on disk and reported
source_locationvalues stay accurate (the #2876 contract that_normalize_cpp_clidocuments). The interpolation hole itself is kept, so identifiers referenced inside it still resolve.Two gates keep it inert everywhere else:
The scanner walks the file once, skipping comments, char literals, raw strings and every other string form, so the spelling written inside a comment or another string is never mistaken for code.
Testing
tests/test_csharp_verbatim_interpolation.py, 7 tests.Before, on a class with six methods and the literal in the third:
After: 10 nodes, all six methods, no warning.
Byte-level check on that same file — 783 bytes, 39 newlines:
and each member's reported location matches the line it is really on (L7, L12, L17, L24, L29, L34).
The two behavioural tests fail with the
source_overridehook removed and pass with it; the other five exercise the normalizer directly (length preservation, multi-line literals, two literals in one file, a healthy file left untouched, and the spelling appearing only inside comments).Full suite: 16 failed, 5565 passed, 194 skipped. Those 16 are pre-existing — re-running the same ten files with this change reverted gives the identical 16 failed / 477 passed, and none of them touch C# or extraction. All 159 existing C# tests pass.
ruff checkis clean on both files.Scope
This does not fix the grammar, which is where the bug actually is — upstream tree-sitter-c-sharp should accept that spelling. It stops graphify silently dropping symbols while the grammar is what it is, and steps aside the moment a file parses cleanly. If you would rather wait for an upstream fix instead of carrying this, that is a fair call.