Treat field initializer as class initializer
when checking for allowance of other field initialization in lambda with EXACTLY_ONCE contract. #KT-40948 Fixed
This commit is contained in:
+3
-1
@@ -60,7 +60,9 @@ class CapturingInClosureChecker : CallChecker {
|
|||||||
if (variable !is PropertyDescriptor || scopeContainer !is AnonymousFunctionDescriptor || variable.isVar) return
|
if (variable !is PropertyDescriptor || scopeContainer !is AnonymousFunctionDescriptor || variable.isVar) return
|
||||||
if (!isLhsOfAssignment(nameElement as KtExpression)) return
|
if (!isLhsOfAssignment(nameElement as KtExpression)) return
|
||||||
val scopeDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(scopeContainer) as? KtFunction ?: return
|
val scopeDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(scopeContainer) as? KtFunction ?: return
|
||||||
if (scopeContainer.containingDeclaration !is ConstructorDescriptor) return
|
if (scopeContainer.containingDeclaration !is ConstructorDescriptor &&
|
||||||
|
scopeContainer.containingDeclaration !is PropertyDescriptor
|
||||||
|
) return
|
||||||
if (!isExactlyOnceContract(trace.bindingContext, scopeDeclaration)) return
|
if (!isExactlyOnceContract(trace.bindingContext, scopeDeclaration)) return
|
||||||
if (trace.bindingContext[CAPTURED_IN_CLOSURE, variable] == CaptureKind.NOT_INLINE) return
|
if (trace.bindingContext[CAPTURED_IN_CLOSURE, variable] == CaptureKind.NOT_INLINE) return
|
||||||
val (callee, param) = getCalleeDescriptorAndParameter(trace.bindingContext, scopeDeclaration) ?: return
|
val (callee, param) = getCalleeDescriptorAndParameter(trace.bindingContext, scopeDeclaration) ?: return
|
||||||
|
|||||||
+21
@@ -129,3 +129,24 @@ class Test4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@kotlin.contracts.ExperimentalContracts
|
||||||
|
class Test5 {
|
||||||
|
val a: String
|
||||||
|
val b: String
|
||||||
|
val c: String
|
||||||
|
val d: String
|
||||||
|
|
||||||
|
val aInit = inlineMe {
|
||||||
|
a = "OK"
|
||||||
|
}
|
||||||
|
val bInit = crossinlineMe {
|
||||||
|
b = "OK"
|
||||||
|
}
|
||||||
|
val cInit = noinlineMe {
|
||||||
|
c = "OK"
|
||||||
|
}
|
||||||
|
val dInit = notinline {
|
||||||
|
d = "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+21
@@ -129,3 +129,24 @@ class Test4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@kotlin.contracts.ExperimentalContracts
|
||||||
|
class Test5 {
|
||||||
|
val a: String
|
||||||
|
val b: String
|
||||||
|
val c: String
|
||||||
|
val d: String
|
||||||
|
|
||||||
|
val aInit = inlineMe {
|
||||||
|
a = "OK"
|
||||||
|
}
|
||||||
|
val bInit = crossinlineMe {
|
||||||
|
<!CAPTURED_VAL_INITIALIZATION!>b<!> = "OK"
|
||||||
|
}
|
||||||
|
val cInit = noinlineMe {
|
||||||
|
<!CAPTURED_VAL_INITIALIZATION!>c<!> = "OK"
|
||||||
|
}
|
||||||
|
val dInit = notinline {
|
||||||
|
<!CAPTURED_VAL_INITIALIZATION!>d<!> = "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+15
@@ -55,3 +55,18 @@ package
|
|||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@kotlin.contracts.ExperimentalContracts public final class Test5 {
|
||||||
|
public constructor Test5()
|
||||||
|
public final val a: kotlin.String
|
||||||
|
public final val aInit: kotlin.Unit
|
||||||
|
public final val b: kotlin.String
|
||||||
|
public final val bInit: kotlin.Unit
|
||||||
|
public final val c: kotlin.String
|
||||||
|
public final val cInit: kotlin.Unit
|
||||||
|
public final val d: kotlin.String
|
||||||
|
public final val dInit: kotlin.Unit
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user