Skip to content

ILLink: Trimmer will map matching public virtual methods as implementations of interface methods when a MethodImpl for the interface method exists on the type #103316

Closed
@jtschuster

Description

@jtschuster

The trimmer will look for the first method with a matching signature for an interface method implementation, even if there is a methodImpl for that method. This will keep the method, even though it's not needed.

		public static void Main ()
		{
			IFoo f = new FooWithImpl ();
			f.Method ();
			f = new FooWithBase ();
			f.Method ();
		}

		[Kept]
		interface IFoo
		{
			[Kept]
			void Method ();
		}

		[Kept]
		[KeptMember (".ctor()")]
		class BaseFoo
		{
			[Kept] // Should not be kept, but TypeMapInfo finds it as the first method with matching signature
			public virtual void Method ()
			{
			}
		}

		[Kept]
		[KeptMember (".ctor()")]
		[KeptBaseType (typeof (BaseFoo2))]
		[KeptInterface (typeof (IFoo))]
		class FooWithBase : BaseFoo, IFoo
		{
			[Kept]
			void IFoo.Method () { }
		}

		[Kept]
		[KeptInterface(typeof(IFoo))]
		class FooWithImpl : IFoo
		{
			[Kept]
			void IFoo.Method() { }
			[Kept] // Should not be kept
			public virtual void Method() { }
		}

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