Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3515,7 +3515,7 @@ static bool TypeIsInlineArrayType(TypeDefinition type)
return false;
}

protected virtual void MarkRequirementsForInstantiatedTypes(TypeDefinition type)
protected internal virtual void MarkRequirementsForInstantiatedTypes(TypeDefinition type)
{
if (Annotations.IsInstantiated(type))
return;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/illink/src/linker/Linker/TypeMapHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void MarkTypeMapAttribute(CustomAttributeWithOrigin entry, DependencyInfo info)
// Mark the target type as instantiated
if (entry.TargetType is { } targetType
&& _context.Resolve(UnwrapToResolvableType(targetType)) is TypeDefinition targetTypeDef)
_context.Annotations.MarkInstantiated(targetTypeDef);
_markStep.MarkRequirementsForInstantiatedTypes(targetTypeDef);
}

public void ProcessType(TypeDefinition definition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
[assembly: TypeMapAssemblyTarget<UsedTypeMapUniverse>("library")]
[assembly: TypeMapAssemblyTarget<UnusedTypeMap2>("library")] // Should be removed

// Verify that a type can be kept if it's used for both TypeMap and TypeMapAssociation
[assembly: TypeMap<UsedTypeMap>("BothInExternalAndProxy", typeof(BothInExternalAndProxy), typeof(BothInExternalAndProxy))] // Kept
[assembly: TypeMapAssociation<UsedTypeMap>(typeof(BothInExternalAndProxy), typeof(BothInExternalAndProxyTarget))] // Kept
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "BothInExternalAndProxy", typeof(BothInExternalAndProxy), typeof(BothInExternalAndProxy))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAssociationAttribute<UsedTypeMap>), typeof(BothInExternalAndProxy), typeof(BothInExternalAndProxyTarget))]

namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupLinkerAction("link", "System.Private.CoreLib")] // Needed to get the RemoveAttributeInstances in embedded xml
Expand Down Expand Up @@ -234,6 +240,9 @@ static void ConstrainedStaticCall<T>(T t) where T : IStaticInterface
_ = new int();
_ = TypeMapping.GetOrCreateExternalTypeMapping<string>();
_ = TypeMapping.GetOrCreateProxyTypeMapping<string>();

// Use BothInExternalAndProxy in a way that preserves any corresponding typemap entries.
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instantiating BothInExternalAndProxy here roots the type, but it still doesn't ensure the proxy type-map group for the added TypeMapAssociation attribute is referenced. If the intent is to cover the bug where the proxy association is missed because the type was already marked instantiated by an external TypeMap entry, the test should also ensure the relevant proxy type-map universe is "seen" (via GetOrCreateProxyTypeMapping for the same group) so the association is expected to be kept.

Suggested change
// Use BothInExternalAndProxy in a way that preserves any corresponding typemap entries.
// Use BothInExternalAndProxy in a way that preserves any corresponding typemap entries.
// Explicitly reference the proxy type-map universe for the same group as the external entry,
// so the test validates that the proxy association is kept even when the type was already
// marked instantiated by the external type map.
_ = TypeMapping.GetOrCreateProxyTypeMapping<UsedExternalTypeMap>();

Copilot uses AI. Check for mistakes.
Console.WriteLine(new BothInExternalAndProxy());
}

[ExpectBodyModified]
Expand Down Expand Up @@ -562,6 +571,12 @@ class UsedProxyTarget2;
[Kept]
class PreservedTargetType;

[Kept]
[KeptMember(".ctor()")]
class BothInExternalAndProxy;
[Kept]
class BothInExternalAndProxyTarget;

[Kept]
class ArrayTypeTrimTargetTarget;

Expand Down
Loading