diff options
author | Michal Strehovský <MichalStrehovsky@users.noreply.github.com> | 2017-05-15 23:06:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-15 23:06:44 +0300 |
commit | 9aa607be455d6d3b013fdb8caaabda600d649fde (patch) | |
tree | e07a068dd27917c4793e018a22633f31015a025d /src/Runtime.Base | |
parent | 692b07d0946a9df4918199d4287ce957c3e81521 (diff) |
Finish support for rank 1 mdarrays (#3610)
Three parts:
1. Update casting logic to allow casting SzArray to rank 1 MdArray (but
not the other way around)
2. Update MdArray rank 1 methods to be able to operate on SzArrays
3. Update array creation path to emulate the behavior where allocating
rank 1 MdArray with 0 lower bounds actually gives you an SzArray
Third bullet point makes this the most annoying, because we can't
reliably support `newobj instance void int32[0...]::.ctor(int32)`
without hitting the type loader. I was also considering adding an
optional field on Rank 1 MdArrays that lets you get to the SzArray's
EEType from it. It might be better.
Fixes #3331.
Diffstat (limited to 'src/Runtime.Base')
-rw-r--r-- | src/Runtime.Base/src/System/Runtime/TypeCast.cs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Runtime.Base/src/System/Runtime/TypeCast.cs b/src/Runtime.Base/src/System/Runtime/TypeCast.cs index d7a549a4b..62dea8448 100644 --- a/src/Runtime.Base/src/System/Runtime/TypeCast.cs +++ b/src/Runtime.Base/src/System/Runtime/TypeCast.cs @@ -219,8 +219,16 @@ namespace System.Runtime // compare the array types structurally - if (pObjType->ParameterizedTypeShape == pTargetType->ParameterizedTypeShape && - CastCache.AreTypesAssignableInternal(pObjType->RelatedParameterType, pTargetType->RelatedParameterType, + if (pObjType->ParameterizedTypeShape != pTargetType->ParameterizedTypeShape) + { + // If the shapes are different, there's one more case to check for: Casting SzArray to MdArray rank 1. + if (!pObjType->IsSzArray || pTargetType->ArrayRank != 1) + { + return null; + } + } + + if (CastCache.AreTypesAssignableInternal(pObjType->RelatedParameterType, pTargetType->RelatedParameterType, AssignmentVariation.AllowSizeEquivalence)) { return obj; |