Skip to content

Commit

Permalink
Restore support for bool-backed enums too
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed May 4, 2024
1 parent f812700 commit cdccf69
Showing 1 changed file with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(obje
EETypeElementType dstElementType = dstEEType->ElementType;
EETypeElementType srcElementType = srcEEType->ElementType;

void* rawDstValue = null;

bool boolValue;
char charValue;
sbyte sbyteValue;
byte byteValue;
Expand All @@ -144,8 +143,7 @@ private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(obje
float floatValue;
double doubleValue;

Unsafe.SkipInit(out dstObject);

void* rawDstValue;
ref byte rawSrcValue = ref RuntimeHelpers.GetRawData(srcObject);

switch (dstElementType)
Expand All @@ -154,11 +152,12 @@ private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(obje
switch (srcElementType)
{
case EETypeElementType.Boolean:
dstObject = srcObject;
boolValue = Unsafe.As<byte, bool>(ref rawSrcValue);
break;
default:
goto Failure;
}
rawDstValue = &boolValue;
break;

case EETypeElementType.Char:
Expand Down Expand Up @@ -429,13 +428,7 @@ private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(obje
goto Failure;
}

// The only case where 'rawDstValue' is not set is for bool values, which set 'dstObject'
// directly. In all other cases, 'rawDstValue' is guaranteed to not be null.
if (rawDstValue != null)
{
dstObject = RuntimeImports.RhBox(dstEEType, ref *(byte*)rawDstValue);
}

dstObject = RuntimeImports.RhBox(dstEEType, ref *(byte*)rawDstValue);
Debug.Assert(dstObject.GetMethodTable() == dstEEType);
return null;

Expand Down

0 comments on commit cdccf69

Please sign in to comment.