Skip to content

illink: TypeMapAssociation attribute always trimmed if there's a TypeMap attribute for the same type. #127004

@rolfbjarne

Description

@rolfbjarne

Test case:

[assembly: TypeMap<UsedExternalTypeMap>("BothInExternalAndProxy", typeof(BothInExternalAndProxy), typeof(BothInExternalAndProxy))]
[assembly: TypeMapAssociation<UsedExternalTypeMap>(typeof(BothInExternalAndProxy), typeof(BothInExternalAndProxyTarget))]

class BothInExternalAndProxy;
class BothInExternalAndProxyTarget;

Console.WriteLine(new BothInExternalAndProxy());

results in the TypeMapAssociation attribute being trimmed away.

This happens because when illink sees a TypeMap attribute, it marks the target type as instantiated:

_context.Annotations.MarkInstantiated(targetTypeDef);

which causes MarkRequirementsForInstantiatedTypes to exit early:

protected virtual void MarkRequirementsForInstantiatedTypes(TypeDefinition type)
{
if (Annotations.IsInstantiated(type))
return;

and then TypeMapHandler.ProcessInstantiatedType later in the method isn't called:

_typeMapHandler.ProcessInstantiated(type);

so then the TypeMapAssociation attribute is never marked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Tools-ILLink.NET linker development as well as trimming analyzersuntriagedNew issue has not been triaged by the area owner

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions