Skip to content

Overloaded extension method called in instance syntax is indexed as the first overload #134

Open

Description

@stacknoise

Version: scip-dotnet 0.2.16+fadd98aebb1ede2c55801636360c002679b54112, .NET SDK 8.0.134, Linux, project targeting net8.0.

A call to an overloaded extension method written as c.Neg(1L) is recorded with the symbol of the first overload (Neg().), although the compiler binds it to a later one. The same call in static syntax (Ext.Neg(c, 1L)) gets the correct symbol.

Reproduction

repro.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>
</Project>

A.cs:

public interface IClause { }

public static class Ext
{
    public static int Neg(this IClause c, int x) => x;
    public static long Neg(this IClause c, long x) => x;
    public static int Plain(int x) => x;
    public static long Plain(long x) => x;
}

public class Use
{
    public void Go(IClause c)
    {
        c.Neg(1);          // expected Ext#Neg().
        c.Neg(1L);         // expected Ext#Neg(+1).
        Ext.Neg(c, 1L);   // expected Ext#Neg(+1).
        Ext.Plain(1L);    // expected Ext#Plain(+1).
        var g = new Use();
    }
}

Run scip-dotnet index --working-directory . --output index.scip and read the occurrences of A.cs.

Observed (line, symbol written for the method name)

Call Symbol in the index Correct?
c.Neg(1); Ext#Neg(). yes
c.Neg(1L); Ext#Neg(). no, the compiler binds Neg(+1)
Ext.Neg(c, 1L); Ext#Neg(+1). yes
Ext.Plain(1L); Ext#Plain(+1). yes

So only the reduced (instance syntax) form of an extension method loses its overload disambiguator. A plausible cause is that the symbol of the reduced method is not mapped back to the original definition (IMethodSymbol.ReducedFrom) before its overload index is computed, so the index falls back to the first overload.

Effect

In a real project (a public guard-clause library, 150 sampled symbols, with Roslyn as reference) all calls of every overloaded extension method are attributed to its first overload: the first overload gets the uses of all, the others none. Eight of the sampled symbols were affected, with 139 uses according to Roslyn, of which 9 were found.

Suggested fix

Compute the overload disambiguator of a reduced extension method from ReducedFrom (or OriginalDefinition), so that c.Neg(1L) and Ext.Neg(c, 1L) produce the same symbol.

Activity

  1. linear-code commented on Nov 16, 2026

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions