I've bumped into this code accidentally while trying to do something unrelated. It looks wrong to me although there is a good chance I'm misreading it. I'm attaching a patch that either fixes two bugs, introduces two new bugs, or does something in between. I'll appreciate if someone more experienced can take a look at it. All test pass with this patch and my zsh seems to work fine. I haven't verified that this code actually runs either during testing or when I'm using zsh normally. Roman.