MutableTuple allows creation of tuple of size greater than 128 by nesting tuples (e.g. a Tuple`2 which contains a Tuple`128 and a Tuple`8 if we had a size of 136). In fact, the accessor methods (e.g. MutableTuple.GetAccessPath) expect nested tuples to be laid out exactly this way. However the MutableTuple.GetSize method traverses the whole tuple and also counts the number of elements of any generic argument of type MutableTuple.
Because the size is calculated incorrectly MutableTuple.GetAccessPath can have unexpected behavior. For example, the following should throw ArgumentException but ends up throwing InvalidOperationException:
int size = 8;
Type[] args = new Type[size];
for (int i = 0; i < size; i++) {
if (i == 5) {
args[i] = MutableTuple.MakeTupleType(typeof(int), typeof(int));
} else {
args[i] = typeof(int);
}
}
var tupleType = MutableTuple.MakeTupleType(args);
MutableTuple.GetAccessPath(tupleType, 8).ToArray(); // this should throw ArgumentException since the index 8 >= size
This also causes the failure in IronLanguages/ironpython3#926
MutableTupleallows creation of tuple of size greater than 128 by nesting tuples (e.g. aTuple`2which contains aTuple`128and aTuple`8if we had a size of 136). In fact, the accessor methods (e.g.MutableTuple.GetAccessPath) expect nested tuples to be laid out exactly this way. However theMutableTuple.GetSizemethod traverses the whole tuple and also counts the number of elements of any generic argument of typeMutableTuple.Because the size is calculated incorrectly
MutableTuple.GetAccessPathcan have unexpected behavior. For example, the following should throwArgumentExceptionbut ends up throwingInvalidOperationException:This also causes the failure in IronLanguages/ironpython3#926