Skip to content

Commit 8a1f072

Browse files
authored
Fix handler for ldtoken with generic parameter (#3180)
***NO_CI***
1 parent b92bf08 commit 8a1f072

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

src/CLR/Core/CLR_RT_HeapBlock.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -294,31 +294,6 @@ HRESULT CLR_RT_HeapBlock::SetReflection(const CLR_RT_MethodDef_Index &md)
294294
NANOCLR_NOCLEANUP();
295295
}
296296

297-
HRESULT CLR_RT_HeapBlock::SetReflection(const CLR_RT_GenericParam_Index &gp)
298-
{
299-
NATIVE_PROFILE_CLR_CORE();
300-
NANOCLR_HEADER();
301-
302-
CLR_RT_GenericParam_Instance genericParam;
303-
CLR_RT_TypeDef_Index typeDef;
304-
305-
if (genericParam.InitializeFromIndex(gp) == false)
306-
{
307-
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
308-
}
309-
310-
// grab the type definition from the generic param
311-
typeDef = genericParam.CrossReference().classTypeDef;
312-
313-
m_id.raw = CLR_RT_HEAPBLOCK_RAW_ID(DATATYPE_REFLECTION, 0, 1);
314-
m_data.reflection.levels = 0;
315-
m_data.reflection.kind = REFLECTION_TYPE;
316-
// set the type definition in the reflection block
317-
m_data.reflection.data.type.Set(typeDef.Assembly(), typeDef.Type());
318-
319-
NANOCLR_NOCLEANUP();
320-
}
321-
322297
HRESULT CLR_RT_HeapBlock::SetObjectCls(const CLR_RT_TypeDef_Index &cls)
323298
{
324299
NATIVE_PROFILE_CLR_CORE();

src/CLR/Core/Interpreter.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3240,7 +3240,30 @@ HRESULT CLR_RT_Thread::Execute_IL(CLR_RT_StackFrame &stackArg)
32403240
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
32413241
}
32423242

3243-
evalPos[0].SetReflection(param);
3243+
if (stack->m_call.genericType != nullptr)
3244+
{
3245+
// For a method in a generic type, caller->genericType points to the TypeSpec of the
3246+
// closed type
3247+
CLR_UINT32 closedTypeSpecRow = stack->m_call.genericType->TypeSpec();
3248+
3249+
CLR_RT_TypeDef_Index resolvedTypeDef;
3250+
NanoCLRDataType resolvedDataType;
3251+
3252+
CLR_UINT32 index = CLR_DataFromTk(arg);
3253+
3254+
assm->FindGenericParamAtTypeSpec(
3255+
closedTypeSpecRow,
3256+
index,
3257+
resolvedTypeDef,
3258+
resolvedDataType);
3259+
3260+
evalPos[0].SetReflection(resolvedTypeDef);
3261+
}
3262+
else
3263+
{
3264+
// No caller context??
3265+
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
3266+
}
32443267
}
32453268
break;
32463269

src/CLR/Include/nanoCLR_Runtime__HeapBlock.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,6 @@ struct CLR_RT_HeapBlock
13511351
HRESULT SetReflection(const CLR_RT_TypeDef_Index &cls);
13521352
HRESULT SetReflection(const CLR_RT_FieldDef_Index &fd);
13531353
HRESULT SetReflection(const CLR_RT_MethodDef_Index &md);
1354-
HRESULT SetReflection(const CLR_RT_GenericParam_Index &gp);
13551354

13561355
HRESULT InitializeArrayReference(CLR_RT_HeapBlock &ref, int index);
13571356
void InitializeArrayReferenceDirect(CLR_RT_HeapBlock_Array &array, int index);

0 commit comments

Comments
 (0)