Skip to content

MutableTuple.GetSize does not report proper size if the tuple contains another tuple #231

@slozier

Description

@slozier

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions