You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If an inner class has a plan reference to this, UnnecessaryInnerClass should still raise an issue.
Observed Behavior
UnnecessaryInnerClass does not raise an issue, even though the class could be made non-inner.
Steps to Reproduce
@Test
fun `reports even with calls to this`() {
val code = """
class A {
inner class B {
fun foo() {
this
}
}
}
""".trimIndent()
assertThat(subject.lintWithContext(env, code)).hasSize(1)
}
Context
I came across this issue while working on labeled expressions in #4865 but was unable to find a resolution. It seems that visitReferenceExpression() will be invoked for any plain call to this and resolve it in the example above as class A when it should be B. Even though it's a reference to this, the expression is not a KtThisExpression but a plain KtNameReferenceExpression with a referenced name of this; aside from checking against that referenced name I couldn't find a way to distinguish it from other expressions.
I don't have a particular use case, but it does seem to interfere with labeled expressions in some cases, e.g.
@Test
fun `reports irrelevant labeled expressions`() {
val code = """
class A {
inner class B {
fun inner() {
return Unit.apply { this@B }
}
}
}
""".trimIndent()
assertThat(subject.lintWithContext(env, code)).hasSize(1)
}
this test will fail, not because of labeled expression as per #4865 but because of the use of this@B, even though that doesn't require B to be inner.
Your Environment
current main branch (fcd9c48159685fc049da6e6d2b3a77db3aea00bd)
The text was updated successfully, but these errors were encountered:
Expected Behavior
If an
inner class
has a plan reference tothis
,UnnecessaryInnerClass
should still raise an issue.Observed Behavior
UnnecessaryInnerClass
does not raise an issue, even though the class could be made non-inner
.Steps to Reproduce
Context
I came across this issue while working on labeled expressions in #4865 but was unable to find a resolution. It seems that
visitReferenceExpression()
will be invoked for any plain call tothis
and resolve it in the example above as classA
when it should beB
. Even though it's a reference tothis
, the expression is not aKtThisExpression
but a plainKtNameReferenceExpression
with a referenced name ofthis
; aside from checking against that referenced name I couldn't find a way to distinguish it from other expressions.I don't have a particular use case, but it does seem to interfere with labeled expressions in some cases, e.g.
this test will fail, not because of labeled expression as per #4865 but because of the use of
this@B
, even though that doesn't requireB
to beinner
.Your Environment
fcd9c48159685fc049da6e6d2b3a77db3aea00bd
)The text was updated successfully, but these errors were encountered: