Uh oh!
There was an error while loading. Please reload this page.
Fix the error when use spread arguments twice - #33069
Fix the error when use spread arguments twice#33069rChaser53 (rchaser53) wants to merge 2 commits into
Conversation
rChaser53 (rchaser53)
commented
Jan 12, 2020
Ryan Cavanaugh (@RyanCavanaugh) CI is failed, but it doesn't seem to be my fault. |
a366747 to
e6c8381CompareEli Barzilay (elibarzilay)
commented
Mar 11, 2020
(rChaser53 (@rchaser53) -- JFYI, I pushed a rebase to drop the big merge commit.) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Eli Barzilay (elibarzilay)
commented
Mar 12, 2020
Note that I changed the PR text to keep #32835 for the additional issue there. |
rChaser53 (rchaser53)
commented
Mar 13, 2020
Thank you for the review. I fixed it as possible as I can. |
5073b62 to
71bb928Compare
Eli Barzilay (elibarzilay)
left a comment
There was a problem hiding this comment.
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
totalCountby the first spread length, but I think that you should add to ut thefirstSpreadIndexotherwise 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+1instead.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 (@rchaser53) Do you want to keep working on this? Let us know if we can help explain anything more. |
rChaser53 (rchaser53)
commented
May 21, 2020
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 fixesmicrosoft#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 fixesmicrosoft#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.)
TypeScript Bot (typescript-bot)
commented
Oct 21, 2025
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
This is a partial fix for #32835, but a full fix should also handle the additional test posted there.