If-then to safe access: more correct receiver calculation
So #KT-18928 Fixed
This commit is contained in:
+16
@@ -149,6 +149,22 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/implicitReceiver.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
|
||||
<description>Replace 'if' expression with safe access expression</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>property.kt</file>
|
||||
<line>10</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/property.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
|
||||
<description>Replace 'if' expression with safe cast expression</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>propertyNotNull.kt</file>
|
||||
<line>9</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/propertyNotNull.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
|
||||
<description>Remove redundant 'if' expression</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// IS_APPLICABLE: true
|
||||
// INTENTION_TEXT: Replace 'if' expression with safe cast expression
|
||||
|
||||
interface Foo
|
||||
interface Bar : Foo
|
||||
|
||||
data class Data(val foo: Foo)
|
||||
|
||||
fun handle(data: Data) {
|
||||
val bar = <caret>if (data.foo is Bar) data.foo else null
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// IS_APPLICABLE: true
|
||||
// INTENTION_TEXT: Replace 'if' expression with safe cast expression
|
||||
|
||||
interface Foo
|
||||
interface Bar : Foo
|
||||
|
||||
data class Data(val foo: Foo)
|
||||
|
||||
fun handle(data: Data) {
|
||||
val bar = data.foo as? Bar
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// IS_APPLICABLE: true
|
||||
// INTENTION_TEXT: Remove redundant 'if' expression
|
||||
|
||||
interface Bar
|
||||
|
||||
data class Data(val bar: Bar?)
|
||||
|
||||
fun handle(data: Data) {
|
||||
val bar = <caret>if (data.bar != null) data.bar else null
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// IS_APPLICABLE: true
|
||||
// INTENTION_TEXT: Remove redundant 'if' expression
|
||||
|
||||
interface Bar
|
||||
|
||||
data class Data(val bar: Bar?)
|
||||
|
||||
fun handle(data: Data) {
|
||||
val bar = data.bar
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
interface Foo
|
||||
interface Bar : Foo {
|
||||
val x: String
|
||||
}
|
||||
|
||||
data class Data(val foo: Foo)
|
||||
|
||||
fun handle(data: Data) {
|
||||
// Not available yet (possible in principle)
|
||||
val bar = <caret>if (data.foo is Bar) data.foo.x else null
|
||||
}
|
||||
Reference in New Issue
Block a user