Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions src/CLR/Core/Execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,8 @@ HRESULT CLR_RT_ExecutionEngine::InitializeLocals(

CLR_RT_TypeSpec_Index genericTSIndex = {};

if (methodDefInstance.genericType && methodDefInstance.genericType->data != 0)
if (methodDefInstance.genericType && NANOCLR_INDEX_IS_VALID(*methodDefInstance.genericType) &&
methodDefInstance.genericType->data != CLR_EmptyToken)
{
// method is generic, it can only use class from method's class generic parameters
genericInstance.InitializeFromIndex(*methodDefInstance.genericType);
Expand Down Expand Up @@ -2093,7 +2094,8 @@ HRESULT CLR_RT_ExecutionEngine::InitializeLocals(
// type-level generic parameter in a locals signature (e.g. 'T' inside a generic type)
CLR_INT8 genericParamPosition = *sig++;

if (methodDefInstance.genericType && methodDefInstance.genericType->data != 0)
if (methodDefInstance.genericType && NANOCLR_INDEX_IS_VALID(*methodDefInstance.genericType) &&
methodDefInstance.genericType->data != CLR_EmptyToken)
{
CLR_RT_TypeSpec_Instance typeSpec{};
typeSpec.InitializeFromIndex(
Expand Down
11 changes: 10 additions & 1 deletion src/CLR/Core/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2211,7 +2211,16 @@ HRESULT CLR_RT_Thread::Execute_IL(CLR_RT_StackFrame &stackArg)
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
}

calleeInst.InitializeFromIndex(calleeReal);
if (calleeInst.genericType && NANOCLR_INDEX_IS_VALID(*calleeInst.genericType) &&
calleeInst.genericType->data != CLR_EmptyToken)
{
// store the current generic context (if any)
calleeInst.InitializeFromIndex(calleeReal, *calleeInst.genericType);
}
else
{
calleeInst.InitializeFromIndex(calleeReal);
}
}

#if defined(NANOCLR_APPDOMAINS)
Expand Down
9 changes: 4 additions & 5 deletions src/CLR/Core/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ bool CLR_RT_MethodDef_Instance::InitializeFromIndex(
}

// remember the TypeSpec so this is available when needed
this->genericType = &typeSpec;
genericType = &typeSpec;

return true;
}
Expand Down Expand Up @@ -1695,9 +1695,8 @@ bool CLR_RT_MethodDef_Instance::ResolveToken(
}
}

// Pick the “winner” between methodOwnerTS or callerGeneric:
const CLR_RT_TypeSpec_Index *definitiveTypeSpec = useCaller ? callerGeneric : methodOwnerTS;
genericType = (CLR_RT_TypeSpec_Index *)definitiveTypeSpec;
// Pick the "winner" between methodOwnerTS or callerGeneric:
genericType = useCaller ? callerGeneric : methodOwnerTS;

CLR_RT_Assembly *methodAssembly = g_CLR_RT_TypeSystem.m_assemblies[methodOwnerTS->Assembly() - 1];

Expand Down Expand Up @@ -6772,7 +6771,7 @@ HRESULT CLR_RT_TypeSystem::BuildMethodName(

declTypeIdx.Set(md.Assembly(), declTypeInst.assembly->crossReferenceMethodDef[md.Method()].GetOwner());

if (genericType != nullptr && genericType->data != 0xffffffff)
if (genericType != nullptr && NANOCLR_INDEX_IS_VALID(*genericType) && genericType->data != CLR_EmptyToken)
{
// parse TypeSpec to get its TypeDef
CLR_RT_TypeSpec_Instance tsInst = {};
Expand Down
3 changes: 2 additions & 1 deletion src/CLR/Diagnostics/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ void CLR_RT_Assembly::DumpToken(CLR_UINT32 token, const CLR_RT_MethodDef_Instanc
// use that, so ResizeArray prints as SimpleList<I4>::ResizeArray.
// 2) Otherwise, fall back to xref.genericType (the raw MethodRef own owner).
const CLR_RT_TypeSpec_Index *ownerTypeSpec;
if (methodDefInstance.genericType != nullptr && NANOCLR_INDEX_IS_VALID(*methodDefInstance.genericType))
if (methodDefInstance.genericType != nullptr && NANOCLR_INDEX_IS_VALID(*methodDefInstance.genericType) &&
methodDefInstance.genericType->data != CLR_EmptyToken)
{
ownerTypeSpec = methodDefInstance.genericType;
}
Expand Down