Skip to content

Commit be47460

Browse files
committed
Fix Type.GetHashCode for RuntimeTypes w/o MethodTable
The hashcode for these was always 0 before this change.
1 parent 5415bd2 commit be47460

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ public override Array GetEnumValuesAsUnderlyingType()
204204
}
205205

206206
public override int GetHashCode()
207-
=> ((nuint)_pUnderlyingEEType).GetHashCode();
207+
{
208+
MethodTable* pEEType = _pUnderlyingEEType;
209+
if (pEEType != null)
210+
return ((nuint)pEEType).GetHashCode();
211+
return RuntimeHelpers.GetHashCode(this);
212+
}
208213

209214
public override RuntimeTypeHandle TypeHandle
210215
{

0 commit comments

Comments
 (0)