Skip to content

Commit b99fad9

Browse files
committed
Fix resolving token from TypeSpec when creating an array
- Now passing to secondary resolution in TypeDef. - Create array now accepts TypeSpec reflection and parses TypeSpec from reflection inside.
1 parent 197503c commit b99fad9

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/CLR/Core/CLR_RT_HeapBlock_Array.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ HRESULT CLR_RT_HeapBlock_Array::CreateInstance(
1818
CLR_RT_HeapBlock_Array *pArray;
1919
CLR_RT_TypeDef_Index cls;
2020
CLR_RT_TypeDef_Instance inst{};
21+
CLR_RT_TypeDescriptor desc{};
22+
CLR_RT_ReflectionDef_Index workingReflex = reflex;
2123

2224
reference.SetObjectReference(nullptr);
2325

@@ -26,12 +28,31 @@ HRESULT CLR_RT_HeapBlock_Array::CreateInstance(
2628

2729
if (reflex.kind != REFLECTION_TYPE)
2830
{
29-
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
31+
// check for typespec
32+
if (reflex.kind == REFLECTION_TYPESPEC)
33+
{
34+
// get the type descriptor for the typespec
35+
(desc.InitializeFromTypeSpec(reflex.data.typeSpec));
36+
37+
// check that this ends up being a reflecion type
38+
if (desc.m_reflex.kind != REFLECTION_TYPE)
39+
{
40+
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
41+
}
42+
43+
// copy over to working reflex
44+
workingReflex = desc.m_reflex;
45+
workingReflex.levels++;
46+
}
47+
else
48+
{
49+
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
50+
}
3051
}
3152

32-
if (reflex.levels == 1)
53+
if (workingReflex.levels == 1)
3354
{
34-
cls = reflex.data.type;
55+
cls = workingReflex.data.type;
3556
}
3657
else
3758
{

src/CLR/Core/TypeSystem.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,10 +1054,8 @@ bool CLR_RT_TypeDef_Instance::ResolveToken(
10541054

10551055
if (elem.Levels > 0)
10561056
{
1057-
// this is an array
1058-
data = elem.Class.data;
1059-
assembly = g_CLR_RT_TypeSystem.m_assemblies[elem.Class.Assembly() - 1];
1060-
target = assembly->GetTypeDef(elem.Class.Type());
1057+
// this is an array, can't init like this
1058+
return false;
10611059
}
10621060
else
10631061
{

0 commit comments

Comments
 (0)