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

Adapt WHEN_WITHOUT_ELSE according to new features of Kotlin 1.6 #1149

Closed
petertrr opened this issue Dec 13, 2021 · 2 comments · Fixed by #1206
Closed

Adapt WHEN_WITHOUT_ELSE according to new features of Kotlin 1.6 #1149

petertrr opened this issue Dec 13, 2021 · 2 comments · Fixed by #1206
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@petertrr
Copy link
Member

petertrr commented Dec 13, 2021

Now our 'generated else block' is treated as a compiler warning sometimes:

when (state.confirmationType) {
                ConfirmationType.NO_BINARY_CONFIRM, ConfirmationType.NO_CONFIRM -> submitExecutionRequest()
                ConfirmationType.DELETE_CONFIRM -> deleteProjectBuilder()
                else -> {
                    // this is a generated else block
                }
            }

causes

w: 'when' is exhaustive so 'else' is redundant here
@petertrr petertrr added the enhancement New feature or request label Dec 13, 2021
@orchestr7 orchestr7 added this to the 1.0.3 milestone Jan 26, 2022
@sanyavertolet
Copy link
Member

I am not sure if it is possible to tell whether else block is redundant or not without compiling.
In example above ConfirmationType could be declared in another file so if we examine the only file with an example we cannot see if when covers all possible values of `ConfirmationType'.

@petertrr
Copy link
Member Author

I think this can be considered similar to #1168 : we don't have enough information to reason about when statement, so we just skip it and let the user use compiler warnings. We can detect if all branches are enum entries (e.g. there are no call statements or literals) and skip these cases.

sanyavertolet pushed a commit that referenced this issue Feb 3, 2022
### What's done:
 * changed behavior with expressions that look like enum entries of when: now if all the entries look like enum entries, WHEN_WITHOUT_ELSE rule is ignored
 * added tests

(#1149)
sanyavertolet pushed a commit that referenced this issue Feb 3, 2022
### What's done:
 * changed behavior with expressions that look like enum entries of when: now if all the entries look like enum entries, WHEN_WITHOUT_ELSE rule is ignored
 * added tests

(#1149)
sanyavertolet pushed a commit that referenced this issue Feb 3, 2022
### What's done:
 * changed behavior with expressions that look like enum entries of when: now if all the entries look like enum entries, WHEN_WITHOUT_ELSE rule is ignored
 * added tests

(#1149)
sanyavertolet pushed a commit that referenced this issue Feb 3, 2022
### What's done:
 * changed behavior with expressions that look like enum entries of when: now if all the entries look like enum entries, WHEN_WITHOUT_ELSE rule is ignored
 * added tests

(#1149)
sanyavertolet pushed a commit that referenced this issue Feb 3, 2022
### What's done:
 * changed behavior with expressions that look like enum entries of when: now if all the entries look like enum entries, WHEN_WITHOUT_ELSE rule is ignored
 * added tests

(#1149)
sanyavertolet added a commit that referenced this issue Feb 4, 2022
* Adapt WHEN_WITHOUT_ELSE according to new features of Kotlin 1.6

### What's done:
 * changed behavior with expressions that look like enum entries of when: now if all the entries look like enum entries, WHEN_WITHOUT_ELSE rule is ignored
 * added tests

(#1149)
sanyavertolet pushed a commit that referenced this issue Feb 25, 2022
### What's done:
 * improved autofix: now we don't use `let` and `run` in some cases
 * added tests

(#1149)
sanyavertolet added a commit that referenced this issue Mar 9, 2022
* Improve autofix in AVOID_NULL_CHECKS rule

### What's done:
 * improved autofix: now we don't use `let` and `run` in some cases
 * added tests

(#899)

* Improve autofix in AVOID_NULL_CHECKS rule

### What's done:
 * improved autofix: now we don't use `let` and `run` in some cases
 * added tests

(#899)

* Improve autofix in AVOID_NULL_CHECKS rule

### What's done:
 * improved autofix: now we don't use `let` and `run` in some cases
 * added tests

(#899)

* Improve autofix in AVOID_NULL_CHECKS rule

### What's done:
 * improved autofix: now we don't use `let` and `run` in some cases
 * added tests

(#899)

* Improve autofix in AVOID_NULL_CHECKS rule

### What's done:
 * improved autofix: now we don't use `let` and `run` in some cases
 * added tests

(#1149)

* Improve autofix in AVOID_NULL_CHECKS rule

### What's done:
 * improved autofix: now we don't use `let` and `run` in some cases
 * improved autofix: now we count statements, not lines
 * added tests

(#1201)

* Improve autofix in AVOID_NULL_CHECKS rule

### What's done:
 * improved autofix: now we don't use `let` and `run` in some cases
 * improved autofix: now we count statements, not lines
 * added tests

(#1201)

* Improve autofix in AVOID_NULL_CHECKS rule

### What's done:
 * improved autofix: now we don't use `let` and `run` in some cases
 * improved autofix: now we count statements, not lines
 * added tests

(#1201)

Co-authored-by: sanyavertolet <alexander.frolov@huawei.com>
Co-authored-by: Andrey Kuleshov <andrewkuleshov7@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants