Skip to content

Proposal: Support delegate signature equivalence #4331

@HaloFour

Description

@HaloFour

See Roslyn: Convert delegate types with compatible signature automatically

Currently the various CLR compilers do not permit treating one delegate of a specific signature as the same as another delegate of an identical signature. The compilers that do (VB.NET) do so by wrapping the existing delegate instance with the new delegate which incurs a performance penalty at the time of invocation.

It appears that for whatever reason, accidentally or otherwise, the CLR/JIT have no real issue using one delegate in place of another. The verifier does complain that an unexpected type is on the stack for the specified call but otherwise the program does execute.

I propose that the verifier be modified that if the type expected and the type on the stack are different but are both delegate types, and that the Invoke method on both delegates share the same signature that the verifier allow the operation.

This would permit delegates of identical signatures to be considered equivalent without the performance penalty either at the time of conversion or the time of invocation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions