Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
slozier opened this issue Aug 17, 2020 · 0 comments

Comments

@slozier
Copy link
Contributor

slozier commented Aug 17, 2020

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

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

No branches or pull requests

1 participant