Rewrite slice error removed for LEAKING_THIS #KT-13371 Fixed
Also EA-86478 fixed (cherry picked from commit 5ac3126)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
13e64c18d9
commit
729de536de
@@ -33,14 +33,16 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
sealed class LeakingThisDescriptor(val classOrObject: KtClassOrObject) {
|
||||
class PropertyIsNull(val property: PropertyDescriptor, classOrObject: KtClassOrObject) : LeakingThisDescriptor(classOrObject)
|
||||
interface LeakingThisDescriptor {
|
||||
val classOrObject: KtClassOrObject
|
||||
|
||||
class NonFinalClass(val klass: ClassDescriptor, classOrObject: KtClassOrObject): LeakingThisDescriptor(classOrObject)
|
||||
data class PropertyIsNull(val property: PropertyDescriptor, override val classOrObject: KtClassOrObject) : LeakingThisDescriptor
|
||||
|
||||
class NonFinalProperty(val property: PropertyDescriptor, classOrObject: KtClassOrObject): LeakingThisDescriptor(classOrObject)
|
||||
data class NonFinalClass(val klass: ClassDescriptor, override val classOrObject: KtClassOrObject): LeakingThisDescriptor
|
||||
|
||||
class NonFinalFunction(val function: FunctionDescriptor, classOrObject: KtClassOrObject): LeakingThisDescriptor(classOrObject)
|
||||
data class NonFinalProperty(val property: PropertyDescriptor, override val classOrObject: KtClassOrObject): LeakingThisDescriptor
|
||||
|
||||
data class NonFinalFunction(val function: FunctionDescriptor, override val classOrObject: KtClassOrObject): LeakingThisDescriptor
|
||||
}
|
||||
|
||||
class ConstructorConsistencyChecker private constructor(
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fun use(x: Any?) = x
|
||||
|
||||
class Eap {
|
||||
private val foo = <!DEBUG_INFO_LEAKING_THIS!>toString<!>()
|
||||
|
||||
constructor(foo: Int) {
|
||||
use(foo)
|
||||
}
|
||||
constructor(foo: String) {
|
||||
use(foo)
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
public fun use(/*0*/ x: kotlin.Any?): kotlin.Any?
|
||||
|
||||
public final class Eap {
|
||||
public constructor Eap(/*0*/ foo: kotlin.Int)
|
||||
public constructor Eap(/*0*/ foo: kotlin.String)
|
||||
private final val foo: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -3212,6 +3212,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/constructorConsistency/propertyAccess.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("twoSecondaryConstructors.kt")
|
||||
public void testTwoSecondaryConstructors() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/constructorConsistency/twoSecondaryConstructors.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis")
|
||||
|
||||
@@ -43,7 +43,6 @@ class LeakingThisInspection : AbstractKotlinInspection() {
|
||||
val context = expression.analyzeFully()
|
||||
val leakingThisDescriptor = context.get(LEAKING_THIS, expression) ?: return
|
||||
val description = when (leakingThisDescriptor) {
|
||||
is PropertyIsNull -> return // Not supported yet
|
||||
is NonFinalClass ->
|
||||
if (expression is KtThisExpression)
|
||||
"Leaking 'this' in constructor of non-final class ${leakingThisDescriptor.klass.name}"
|
||||
@@ -53,6 +52,7 @@ class LeakingThisInspection : AbstractKotlinInspection() {
|
||||
"Accessing non-final property ${leakingThisDescriptor.property.name} in constructor"
|
||||
is NonFinalFunction ->
|
||||
"Calling non-final function ${leakingThisDescriptor.function.name} in constructor"
|
||||
else -> return // Not supported yet
|
||||
}
|
||||
val memberDescriptorToFix = when (leakingThisDescriptor) {
|
||||
is NonFinalProperty -> leakingThisDescriptor.property
|
||||
|
||||
Reference in New Issue
Block a user