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
|
var parameterUser: PsiElement = nameExpression
|
||||||
do {
|
do {
|
||||||
parameterUser = PsiTreeUtil.getParentOfType(parameterUser, KtProperty::class.java, KtPropertyAccessor::class.java,
|
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)
|
} while (parameterUser is KtProperty && parameterUser.isLocal)
|
||||||
return when (parameterUser) {
|
return when (parameterUser) {
|
||||||
is KtProperty -> parameterUser.containingClassOrObject !== klass
|
is KtProperty -> parameterUser.containingClassOrObject !== klass
|
||||||
is KtPropertyAccessor -> true
|
is KtPropertyAccessor -> true
|
||||||
is KtClassInitializer -> parameterUser.containingDeclaration !== klass
|
is KtClassInitializer -> parameterUser.containingDeclaration !== klass
|
||||||
is KtSecondaryConstructor -> parameterUser.getContainingClassOrObject() !== klass
|
is KtSecondaryConstructor -> parameterUser.getContainingClassOrObject() !== klass
|
||||||
|
is KtFunctionLiteral -> true
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,3 +103,17 @@ class ModifiedInInit(var x: Int) {
|
|||||||
open class UsedInOverride(val x: Int)
|
open class UsedInOverride(val x: Int)
|
||||||
|
|
||||||
class UserInOverride(override val x: Int) : UsedInOverride(x)
|
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