Skip to content

Conversation

@BCSharp
Copy link
Member

@BCSharp BCSharp commented Nov 29, 2024

Fixes IndexOutOfRangeException when equating arrays with different index bases (lower bounds).

Example:

>>> from System import *
>>> a = Array.CreateInstance(Int32, (5,), (1,))
>>> b = Array.CreateInstance(Int32, (5,), (1,))
>>> a == b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: Index was outside the bounds of the array.
>>> a != b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: Index was outside the bounds of the array.

This is due to a bug in .NET:

var a = Array.CreateInstance(typeof(int), new[] { 5 }, new[] { 1 });
var b = Array.CreateInstance(typeof(int), new[] { 5 }, new[] { 1 });
((IStructuralEquatable)a).Equals(b, EqualityComparer<int>.Default);  // IndexOutOfRangeException

I'll see if this is already reported. It just shows that nonzero bases are not very popular.

In this PR I'll also cover equating multidimensional arrays, since there is just a little bit to add to address that as well.

@BCSharp BCSharp marked this pull request as draft November 29, 2024 07:13
@BCSharp
Copy link
Member Author

BCSharp commented Nov 30, 2024

Ordering comparisons are also not working well, but I leave it as that — I don't have old code to submit.

@BCSharp BCSharp marked this pull request as ready for review November 30, 2024 04:48
Copy link
Contributor

@slozier slozier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, seems fine to me. I'll file an issue regarding array ordering comparisons not working since this seems to be a regression from 2.7.

@slozier slozier merged commit c1345b4 into IronLanguages:main Dec 2, 2024
8 checks passed
@BCSharp BCSharp deleted the array_cmpN branch December 3, 2024 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants