Skip to content

Linker should consider static members on base types and interfaces (only) if BindingFlags.FlattenHierarchy is specified #102525

Open

Description

@vitek-karas
using System;
using System.Reflection;

interface IFace
{
    public static int PublicStaticOnInterface = 0;

    private static int PrivateStaticOnInterface = 0;
}

class Base
{
    public static int PublicStaticOnBase = 0;
    public int PublicInstanceOnBase = 0;
    static int PrivateStaticOnBase = 0;
    int PrivateInstanceOnBase = 0;
}
class Program : Base, IFace
{
    static void Main(string[] args)
    {
        foreach (var f in typeof(Program).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy)) Console.WriteLine(f);
    }
}

Prints out:

Int32 PublicInstanceOnBase
Int32 PublicStaticOnBase
Int32 PublicStaticOnInterface

Activity

  1. vitek-karas commented on May 11, 2021

    @vitek-karas
    MemberAuthor

    Also investigate how this works for events, methods, properties and nested types.

  2. transferred this issue fromdotnet/linkeron May 21, 2024
  3. dotnet-policy-service commented on May 21, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-numerics
    See info in area-owners.md if you want to be subscribed.

  4. changed the title [-]Linker should mark public static fields on implemented interfaces[/-] [+]Linker should consider static members on base types and interfaces (only) if BindingFlags.FlattenHierarchy is specified[/+] on May 21, 2024
  5. added
    area-Tools-ILLink.NET linker development as well as trimming analyzers
    and removed
    untriagedNew issue has not been triaged by the area owner
    on May 21, 2024
  6. dotnet-policy-service commented on May 21, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
    See info in area-owners.md if you want to be subscribed.

  7. added this to the Future milestone on Jul 8, 2024
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

    area-Tools-ILLink.NET linker development as well as trimming analyzers

    Type

    No type

    Projects

    • Status
      No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions