Skip to content

Commit

Permalink
[EE] Handle ArrayExpansion for 1D array with non-zero lower bounds (#…
Browse files Browse the repository at this point in the history
…58915)

Issue:
- Evaluating + expanding `Array myArray = Array.CreateInstance(typeof(int), new int[1] { 12 }, new int[1] { 1 });` while debugging crashes Visual Studio.

Changes:
1. ArrayExpansion:
- Lower bounds correction wasn't being done for 1D arrays, so add it.
- This can't really be tested in C#/VB since Array.CreateInstance with 1D params can't be cast to a 1D array (see Remarks here: https://docs.microsoft.com/en-us/dotnet/api/system.array.createinstance#system-array-createinstance(system-type-system-int32()-system-int32())
- Corner case, will add tests on debugger side.

Co-authored-by: Ramkumar Ramesh <ramram@microsoft.com>
  • Loading branch information
r-ramesh and Ramkumar Ramesh authored Jan 20, 2022
1 parent 759b3ca commit e70912b
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ private int[] GetIndices(int index)
{
if (_divisors == null)
{
return new[] { index };
// _divisors is null if dimension is 1, but
// _lowerBounds need not necessarily be so.
Debug.Assert(_lowerBounds == null || _lowerBounds.Count == 1);
int lowerBound = _lowerBounds != null && _lowerBounds.Count == 1 ? _lowerBounds[0] : 0;
return new[] { lowerBound + index };
}

var n = _divisors.Count;
Expand Down

0 comments on commit e70912b

Please sign in to comment.