-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix the error when use spread arguments twice #33069
Conversation
@RyanCavanaugh CI is failed, but it doesn't seem to be my fault. |
a366747
to
e6c8381
Compare
(@rchaser53 -- JFYI, I pushed a rebase to drop the big merge commit.) |
Note that I changed the PR text to keep #32835 for the additional issue there. |
Thank you for the review. I fixed it as possible as I can. |
5073b62
to
71bb928
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but there are still a bunch of issues that I see here...
-
You still have the previous behavior as a special case, which I think should not be needed if this becomes a proper fix (more on that below).
-
You initialize
totalCount
by the first spread length, but I think that you should add to ut thefirstSpreadIndex
otherwise the code doesn't count those plain arguments that might appear before the first spread. -
The loop starts from
firstSpreadIndex
, which means that this first spread's count is added twice to the count. It should probably befirstSpreadIndex+1
instead. -
IIUC, this code (tries to) handle tuples, but it omits arrays, which makes it a partial solution. For example, it would be good to add these two tests:
takeTwoOrMore(...t5); takeTwoOrMore(...t5, ...t5);
where both should be errors --- and as it is, the second one isn't.
I think that the previous version was handling only arrays, so handling both should make the special-cased first part redundant too.
Since this is essentially doing only an arity count check, making the code handle both arrays and tuples should not be too difficult: it should go over all of the arguments, and for each:
-
if it's a simple tuple, add its length to the count,
-
if it's an array, then remember that the count is whatever it is "plus any number of arguments",
-
if it's a tuple with a rest array (like
t4
), then add the length and remember a "plus any number of arguments" as the previous case, -
if it's neither then add 1.
This should cover all cases as well as making the first special case redundant.
@rchaser53 Do you want to keep working on this? Let us know if we can help explain anything more. |
I cannot have the time to resolve this issue now. My main work is too busy. I'm really sorry for taking your time... I close this PR. |
This completes the work that started in PR microsoft#33069, and fixes microsoft#32835. There are probably two additional related changes that are needed to make this more complete: * Fix the code that composes the error message (see the first two `FIXME`s in `callWithSpread3.ts`). * Fix the code that checks the argument types (second two `FIXME`s). * There is also an error in `genericRestParameters1.ts` which changed but should not be an error in the first place. Added a `FIXME` there too. (Probably will work if the previous iterm is done.) In addition, `getEffectiveCallArguments` munges the arguments in case of a spread in the last argument which might be better to avoid. (I think that there are cases where it wouldn't work anyway, such as a spread of an array followed by a spread of an empty array.)
This completes the work that started in PR microsoft#33069, and fixes microsoft#32835. There are probably two additional related changes that are needed to make this more complete: * Fix the code that composes the error message (see the first two `FIXME`s in `callWithSpread3.ts`). * Fix the code that checks the argument types (second two `FIXME`s). * There is also an error in `genericRestParameters1.ts` which changed but should not be an error in the first place. Added a `FIXME` there too. (Probably will work if the previous iterm is done.) In addition, `getEffectiveCallArguments` munges the arguments in case of a spread in the last argument which might be better to avoid. (I think that there are cases where it wouldn't work anyway, such as a spread of an array followed by a spread of an empty array.)
This completes the work that started in PR #33069, and fixes #32835. There are probably two additional related changes that are needed to make this more complete: * Fix the code that composes the error message (see the first two `FIXME`s in `callWithSpread3.ts`). * Fix the code that checks the argument types (second two `FIXME`s). * There is also an error in `genericRestParameters1.ts` which changed but should not be an error in the first place. Added a `FIXME` there too. (Probably will work if the previous iterm is done.) In addition, `getEffectiveCallArguments` munges the arguments in case of a spread in the last argument which might be better to avoid. (I think that there are cases where it wouldn't work anyway, such as a spread of an array followed by a spread of an empty array.)
This is a partial fix for #32835, but a full fix should also handle the additional test posted there.