Can be parameter inspection: use inside function literals is now handled as "property use" #KT-11949 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
ae2e3f1811
commit
795b92461e
@@ -54,13 +54,15 @@ class CanBeParameterInspection : AbstractKotlinInspection() {
|
||||
var parameterUser: PsiElement = nameExpression
|
||||
do {
|
||||
parameterUser = PsiTreeUtil.getParentOfType(parameterUser, KtProperty::class.java, KtPropertyAccessor::class.java,
|
||||
KtClassInitializer::class.java, KtSecondaryConstructor::class.java) ?: return true
|
||||
KtClassInitializer::class.java, KtSecondaryConstructor::class.java,
|
||||
KtFunctionLiteral::class.java) ?: return true
|
||||
} while (parameterUser is KtProperty && parameterUser.isLocal)
|
||||
return when (parameterUser) {
|
||||
is KtProperty -> parameterUser.containingClassOrObject !== klass
|
||||
is KtPropertyAccessor -> true
|
||||
is KtClassInitializer -> parameterUser.containingDeclaration !== klass
|
||||
is KtSecondaryConstructor -> parameterUser.getContainingClassOrObject() !== klass
|
||||
is KtFunctionLiteral -> true
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,3 +103,17 @@ class ModifiedInInit(var x: Int) {
|
||||
open class UsedInOverride(val x: Int)
|
||||
|
||||
class UserInOverride(override val x: Int) : UsedInOverride(x)
|
||||
// NO
|
||||
class UsedInLambda(val x: Int) {
|
||||
init {
|
||||
run {
|
||||
val y = x
|
||||
}
|
||||
}
|
||||
}
|
||||
// NO
|
||||
class UsedInDelegate(val x: Int) {
|
||||
val y: Int by lazy {
|
||||
x * x
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user