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

Crash in patterns branch when switch statement's last case is empty #1181

Closed
munificent opened this issue Feb 18, 2023 · 0 comments
Closed
Labels

Comments

@munificent
Copy link
Member

This will crash the latest code on the "patterns" branch:

switch (e) {
  case E.e1:
    break;
  case E.e2:
}

It has to do with the new compact switch formatting and the unusual behavior where there is a rule for the cases that goes across the hard splits between each case. To handle that correctly, the ChunkBuilder doesn't divide at a hard split if it sees that a rule is used both before and after it. But in this case (heh), since the last case is empty, the rule for splitting the case bodies doesn't actually appear after the hard split before the last case.

So it divides the two cases. But the body splitting rule does show up in a constraint of one of the other rules. Because of that, it ends up getting an index assigned when it splits the first case and then the LineSplitter gets very confused when it gets to the second case because the assumption is that every rule has a null index before line splitting begins.

The core problem is that we shouldn't divide the chunks between the two cases. I'll need to come up with a better way to determine that. I tried traverse the rule constraints and preventing a divide if any rule is used on both sides of a hard split as a chunk's rule or in a constraint, but it's much too slow.

@munificent munificent added the bug label Feb 18, 2023
munificent added a commit that referenced this issue Feb 24, 2023
In the process, I came up with a cleaner and faster solution for
handling rules that span hard splits.

Fix #1181.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant