Skip to content

Commit 165aba6

Browse files
authored
Fix WriteDataType for generic types and arrays (#188)
***NO_CI***
1 parent 73be9ed commit 165aba6

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

MetadataProcessor.Shared/Tables/nanoSignaturesTable.cs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
// Original work from Oleg Rakhmatulin.
@@ -433,20 +433,22 @@ public void WriteDataType(
433433
{
434434
writer.WriteByte((byte)NanoCLRDataType.DATATYPE_SZARRAY);
435435

436-
var array = (ArrayType)typeDefinition;
437-
438-
if (array.ElementType.IsGenericParameter)
436+
if (alsoWriteSubType)
439437
{
440-
// ECMA 335 VI.B.4.3 Metadata
441-
writer.WriteByte((byte)NanoCLRDataType.DATATYPE_VAR);
438+
ArrayType array = (ArrayType)typeDefinition;
442439

443-
// OK to use byte here as we won't support more than 0x7F generic parameters
444-
writer.WriteByte((byte)(array.ElementType as GenericParameter).Position);
445-
}
446-
else if (alsoWriteSubType)
447-
{
440+
if (array.ElementType.IsGenericParameter)
441+
{
442+
// ECMA 335 VI.B.4.3 Metadata
443+
writer.WriteByte((byte)NanoCLRDataType.DATATYPE_VAR);
448444

449-
WriteDataType(array.ElementType, writer, true, expandEnumType, isTypeDefinition);
445+
// OK to use byte here as we won't support more than 0x7F generic parameters
446+
writer.WriteByte((byte)(array.ElementType as GenericParameter).Position);
447+
}
448+
else
449+
{
450+
WriteDataType(array.ElementType, writer, true, expandEnumType, isTypeDefinition);
451+
}
450452
}
451453

452454
return;
@@ -458,7 +460,7 @@ public void WriteDataType(
458460

459461
if (alsoWriteSubType)
460462
{
461-
var resolvedType = typeDefinition.Resolve();
463+
TypeDefinition resolvedType = typeDefinition.Resolve();
462464

463465
WriteDataType(resolvedType, writer, false, expandEnumType, isTypeDefinition);
464466
}
@@ -472,15 +474,18 @@ public void WriteDataType(
472474
// II.23.2.12 Type
473475
writer.WriteByte((byte)NanoCLRDataType.DATATYPE_GENERICINST);
474476

475-
var genericType = (GenericInstanceType)typeDefinition;
476-
WriteDataType(genericType.Resolve(), writer, true, expandEnumType, isTypeDefinition);
477+
if (alsoWriteSubType)
478+
{
479+
GenericInstanceType genericType = (GenericInstanceType)typeDefinition;
480+
WriteDataType(genericType.Resolve(), writer, true, expandEnumType, isTypeDefinition);
477481

478-
// OK to use byte here as we won't support more than 0x7F arguments
479-
writer.WriteByte((byte)genericType.GenericArguments.Count);
482+
// OK to use byte here as we won't support more than 0x7F arguments
483+
writer.WriteByte((byte)genericType.GenericArguments.Count);
480484

481-
foreach (var a in genericType.GenericArguments)
482-
{
483-
WriteDataType(a, writer, true, expandEnumType, isTypeDefinition);
485+
foreach (TypeReference a in genericType.GenericArguments)
486+
{
487+
WriteDataType(a, writer, true, expandEnumType, isTypeDefinition);
488+
}
484489
}
485490

486491
return;

0 commit comments

Comments
 (0)