Skip to content

Commit

Permalink
UnnecessaryInnerClass: add test for safe qualified expressions (#4864)
Browse files Browse the repository at this point in the history
Add a unit test for a bug in which safe qualified references to a nullable field
in the parent class (i.e. as `?.`) would not be marked as warnings in release
1.20.0. This issue has been inadvertently fixed by
#4738, but adding a unit test will guard
against future regressions.

I was able to confirm this test fails by checking out the 1.20.0 tag and running
the unit test; against that tag the fix was to override the
visitSafeQualifiedExpression() function with the same logic as
visitCallExpression().
  • Loading branch information
dzirbel committed May 27, 2022
1 parent fcd9c48 commit 2e2d471
Showing 1 changed file with 17 additions and 0 deletions.
Expand Up @@ -274,6 +274,23 @@ class UnnecessaryInnerClassSpec(val env: KotlinCoreEnvironment) {
assertThat(subject.lintWithContext(env, code)).isEmpty()
}

@Test
fun `as a safe qualified expression`() {
val code = """
class A {
var foo: String? = null
inner class B {
fun fooLength() {
foo?.length
}
}
}
""".trimIndent()

assertThat(subject.lintWithContext(env, code)).isEmpty()
}

@Test
fun `to call a function of the member`() {
val code = """
Expand Down

0 comments on commit 2e2d471

Please sign in to comment.