You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[python] TokenStreamRewriter _reduceToSingleOperationPerIndex error when reducing mixture of Replace and Insert operations #4818
Define a list of rewrites which has a Replace, then two Inserts which overlap. Eg [ReplaceOp(tokens, 2, 4, "foo"), InsertBeforeOp(tokens, 6, "bar"), InsertBeforeOp(tokens, 6, "baz")]
Try call _reduceToSingleOperationPerIndex (either directly in a unit test, or by calling getText()
Expected behaviour: should combine the Insert operations and leave the ReplaceOp untouched, leaving: [ReplaceOp(tokens, 2, 4, "foo"), None, InsertBeforeOp(tokens, 6, "bazbar")]
Actual behaviour: Incorrectly sets the ReplaceOp to None because the Index reference is wrong, leaving: [None, InsertBeforeOp(tokens, 6, "bar"), InsertBeforeOp(tokens, 6, "baz")]
It then fails with a ValueError because two different operations are still defined for the same index, 6.
Suggested Fix
The "# Walk Replaces" section of the same method is already solving this issue by referencing .instructionIndex. I suspect that Inserts don't do the same is an oversight. So I'd suggest implementing the same approach for Inserts checks as well:
Activity