add split alternative pattern code action#5240
Open
vshakitskiy wants to merge 2 commits intogleam-lang:mainfrom
Open
add split alternative pattern code action#5240vshakitskiy wants to merge 2 commits intogleam-lang:mainfrom
vshakitskiy wants to merge 2 commits intogleam-lang:mainfrom
Conversation
4949210 to
456c5c8
Compare
Comment on lines
+7
to
+24
| pub fn go(n: Int) { | ||
| case n { | ||
| 1 | 2 | 3 | 4 -> todo | ||
| ▔▔▔▔↑ | ||
| _ -> todo | ||
| } | ||
| } | ||
|
|
||
|
|
||
| ----- AFTER ACTION | ||
|
|
||
| pub fn go(n: Int) { | ||
| case n { | ||
| 1 | 4 -> todo | ||
| 2 -> todo | ||
| 3 -> todo | ||
| _ -> todo | ||
| } |
Member
There was a problem hiding this comment.
I think when selecting patterns that are in the middle, the alternative should be split by keeping the same order of patterns. So in this test it should become:
case n {
1 -> todo
2 | 3 -> todo
4 -> todo
_ -> todo
}What do you think @lpil?
Member
There was a problem hiding this comment.
I would expect to get 2 | 3 and 1 | 4 as patterns here I think
Since neither 1 or 4 is selected here, I definitely wouldn't expect those to be the ones that are split
Contributor
Author
There was a problem hiding this comment.
I thought the initial idea is that we split the ones that are selected? Quoting the example from the issue page:
case a {
AAA | BBB | CCC | DDD -> todo
// ^^^^^^
}
// Becomes:
case a {
AAA -> todo
BBB -> todo
CCC | DDD -> todo
}So I guess it makes sense that if we split the ones on the middle, only them should be affected?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4856.