Open
Description
When calling a method on a generic value that is constrained to be a reference type, the compiler mistakenly emits a box
and unbox.any
sequence of commands.
Repro steps
Compile the following function:
let getDelegateMethod<'TDelegate when 'TDelegate :> System.Delegate> (del: 'TDelegate) = del.Method
Expected behavior
The generated IL should be:
ldarg.0
callvirt instance class [System.Private.CoreLib]System.Reflection.MethodInfo [System.Private.CoreLib]System.Delegate::get_Method()
ret
Actual behavior
The generated IL is:
ldarg.0
box !!TDelegate
unbox.any [System.Private.CoreLib]System.Delegate
callvirt instance class [System.Private.CoreLib]System.Reflection.MethodInfo [System.Private.CoreLib]System.Delegate::get_Method()
ret
Known workarounds
None
Related information
Calling the method using constrained.callvirt
is not necessary; we surely have a reference type and just a callvirt
suffices.
- .NET Runtime kind: .NET SDK 5.0.100
Metadata
Metadata
Assignees
Type
Projects
Status
New