Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix value type unboxing bug #69815

Merged
merged 3 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/coreclr/vm/comdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,7 @@ FCIMPL1(ReflectMethodObject *, COMDelegate::FindMethodHandle, Object* refThisIn)
HELPER_METHOD_FRAME_BEGIN_RET_1(refThis);

pMD = GetMethodDesc(refThis);
pMD = MethodDesc::FindOrCreateAssociatedMethodDescForReflection(pMD, TypeHandle(pMD->GetMethodTable()), pMD->GetMethodInstantiation());
pRet = pMD->GetStubMethodInfo();
HELPER_METHOD_FRAME_END();

Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/vm/genmeth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,8 +1267,7 @@ MethodDesc::FindOrCreateAssociatedMethodDesc(MethodDesc* pDefMD,
// that keeps the reflection logic the same for value types

// we need unboxing stubs for virtual methods on value types unless the method is generic
BOOL fNeedUnboxingStub = pMethod->IsUnboxingStub() ||
( instType.IsValueType() && pMethod->IsVirtual() );
BOOL fNeedUnboxingStub = instType.IsValueType() && pMethod->IsVirtual();
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved

pInstMD = MethodDesc::FindOrCreateAssociatedMethodDesc(
pMethod, /* the original MD */
Expand Down
11 changes: 11 additions & 0 deletions src/libraries/System.Runtime/tests/System/DelegateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -435,6 +436,16 @@ private static void IntIntMethod(int expected, int actual)
Assert.Equal(expected, actual);
}

[Fact]
public static void SameMethodObtainedViaDelegateAndReflectionAreSame()
{
var m1 = ((MethodCallExpression)((Expression<Action>)(() => new C().M())).Body).Method;
var m2 = new Action(new C().M).Method;
Assert.True(m1.Equals(m2));
}

struct C { internal void M() { } }
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved

private delegate void IntIntDelegate(int expected, int actual);
private delegate void IntIntDelegateWithDefault(int expected, int actual = 7);

Expand Down