Skip to content

[Bug]: C#: an #if block can close the class early, so later members lose their class and their calls #5002

Closed

Description

@rohit-jsfreaky

Pre-flight checks

  • I have checked the Troubleshooting section in the README

What happened?

In C#, an #if block can make tree-sitter close the enclosing class too early. Every member after that point loses its class. It becomes a node with no Type. owner, no method edge from the class and no field typing, so its member calls are lost.

This is a different bug from #2631, where members inside the #if were missing (that one looks fixed on v8). Here the members after the block are hit, even when the #if body is trivial.

On Newtonsoft.Json, Dapper and AutoMapper I compared graphify's calls edges with what Roslyn resolves. On v8, 40 files in these three libraries parse with tree-sitter errors. Fixing just this takes total recall from 70.8% to 75.4% (Newtonsoft.Json alone: 72.8% to 79.0%).

Steps to reproduce

Two files in one folder, then graphify update .:

Buffer.cs

namespace Repro3
{
    public class Buffer
    {
        public void Append(char c) { }
    }
}

Writer.cs

namespace Repro3
{
    public class Writer
    {
        private readonly Buffer _buffer = new Buffer();
        private int _state;

        public int State
        {
            get
            {
                {
                    return _state;
                }
            }
        }

        public string Path
        {
            get
            {
                {
                    return "";
                }
            }
        }

        public void WriteValue(int typeCode)
        {
            {
                switch (typeCode)
                {
#if HAVE_DB_NULL
                    case 1:
                        break;
#endif
                }
            }
        }

        public void Flush()
        {
            Prepare();
            _buffer.Append('x');
        }

        private void Prepare() { }
    }
}

This is cut down from Newtonsoft.Json's JsonWriter.cs.

Error output or graph output

Writer method .WriteValue()
Flush() calls Prepare()
Buffer method .Append()

Flush() and Prepare() are no longer members of Writer, and Flush() -> Append() is missing. Expected:

Writer method .WriteValue()
Writer method .Flush()
Writer method .Prepare()
.Flush() calls .Prepare()
.Flush() calls .Append()
Buffer method .Append()

Graphify version

0.9.102

Operating System

Windows

Python Version

3.12

Installation Method

uv tool install (recommended)

Activity

  1. github-actions commented on Nov 4, 2026

    @github-actions

    Thanks for opening this issue, @rohit-jsfreaky. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. safishamsi commented on Nov 5, 2026

    @safishamsi
    Member

    Fixed in 0.9.103 (published to PyPI) via #5003. C# preprocessor directives and #if branches are blanked before parsing, so they no longer close a class early and drop later members.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions