Don't run contract-specific checks in propery scopes
^KT-45118 Fixed
This commit is contained in:
+6
@@ -18068,6 +18068,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt45118.kt")
|
||||
public void testKt45118() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/kt45118.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt47316.kt")
|
||||
public void testKt47316() throws Exception {
|
||||
|
||||
+4
-7
@@ -41,14 +41,13 @@ class ContractParsingServices(val languageVersionSettings: LanguageVersionSettin
|
||||
*
|
||||
* Otherwise, it may lead to inconsistent resolve state and failed assertions
|
||||
*/
|
||||
fun checkContractAndRecordIfPresent(expression: KtExpression, trace: BindingTrace, scope: LexicalScope) {
|
||||
fun checkContractAndRecordIfPresent(expression: KtExpression, trace: BindingTrace, ownerDescriptor: FunctionDescriptor) {
|
||||
// Fastpath. Note that it doesn't violates invariant described in KDoc, because 'isContractDescriptionCallPsiCheck'
|
||||
// is a *necessary* (but not sufficient, actually) condition for presence of 'LazyContractProvider'
|
||||
if (!expression.isContractDescriptionCallPsiCheck()) return
|
||||
|
||||
val callContext = ContractCallContext(expression, scope, trace, languageVersionSettings)
|
||||
val contractProviderIfAny =
|
||||
(scope.ownerDescriptor as? FunctionDescriptor)?.getUserData(ContractProviderKey) as? LazyContractProvider?
|
||||
val callContext = ContractCallContext(expression, ownerDescriptor, trace, languageVersionSettings)
|
||||
val contractProviderIfAny = ownerDescriptor.getUserData(ContractProviderKey) as? LazyContractProvider?
|
||||
var resultingContractDescription: ContractDescription? = null
|
||||
|
||||
try {
|
||||
@@ -103,11 +102,9 @@ class ContractParsingServices(val languageVersionSettings: LanguageVersionSettin
|
||||
|
||||
class ContractCallContext(
|
||||
val contractCallExpression: KtExpression,
|
||||
val scope: LexicalScope,
|
||||
val functionDescriptor: FunctionDescriptor,
|
||||
val trace: BindingTrace,
|
||||
val languageVersionSettings: LanguageVersionSettings
|
||||
) {
|
||||
val ownerDescriptor: DeclarationDescriptor = scope.ownerDescriptor
|
||||
val functionDescriptor: FunctionDescriptor = ownerDescriptor as FunctionDescriptor
|
||||
val bindingContext: BindingContext = trace.bindingContext
|
||||
}
|
||||
+6
-2
@@ -353,8 +353,12 @@ public class ExpressionTypingServices {
|
||||
}
|
||||
blockLevelVisitor = new ExpressionTypingVisitorDispatcher.ForBlock(expressionTypingComponents, annotationChecker, scope);
|
||||
|
||||
if (isFirstStatement) {
|
||||
expressionTypingComponents.contractParsingServices.checkContractAndRecordIfPresent(statementExpression, context.trace, scope);
|
||||
DeclarationDescriptor ownerDescriptor = scope.getOwnerDescriptor();
|
||||
|
||||
if (isFirstStatement && ownerDescriptor instanceof FunctionDescriptor) {
|
||||
expressionTypingComponents.contractParsingServices.checkContractAndRecordIfPresent(
|
||||
statementExpression, context.trace, (FunctionDescriptor) ownerDescriptor
|
||||
);
|
||||
isFirstStatement = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
open class Foo(open val x: Boolean)
|
||||
|
||||
class Bar: Foo(false) {
|
||||
val y = "OK"
|
||||
}
|
||||
|
||||
fun contract(x: Foo) = x
|
||||
|
||||
val temp = if (true) contract(Bar()) else Bar()
|
||||
|
||||
fun box(): String = (temp as Bar).y
|
||||
+6
@@ -17948,6 +17948,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt45118.kt")
|
||||
public void testKt45118() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/kt45118.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt47316.kt")
|
||||
public void testKt47316() throws Exception {
|
||||
|
||||
+6
@@ -18068,6 +18068,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt45118.kt")
|
||||
public void testKt45118() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/kt45118.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt47316.kt")
|
||||
public void testKt47316() throws Exception {
|
||||
|
||||
+5
@@ -14871,6 +14871,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45118.kt")
|
||||
public void testKt45118() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/kt45118.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt47316.kt")
|
||||
public void testKt47316() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/kt47316.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -13050,6 +13050,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45118.kt")
|
||||
public void testKt45118() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/kt45118.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaWithStarReturn.kt")
|
||||
public void testLambdaWithStarReturn() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/lambdaWithStarReturn.kt");
|
||||
|
||||
Generated
+5
@@ -12456,6 +12456,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45118.kt")
|
||||
public void testKt45118() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/kt45118.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaWithStarReturn.kt")
|
||||
public void testLambdaWithStarReturn() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/lambdaWithStarReturn.kt");
|
||||
|
||||
Generated
+5
@@ -12486,6 +12486,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45118.kt")
|
||||
public void testKt45118() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/kt45118.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaWithStarReturn.kt")
|
||||
public void testLambdaWithStarReturn() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/lambdaWithStarReturn.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -7600,6 +7600,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45118.kt")
|
||||
public void testKt45118() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/kt45118.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaWithStarReturn.kt")
|
||||
public void testLambdaWithStarReturn() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/lambdaWithStarReturn.kt");
|
||||
|
||||
Reference in New Issue
Block a user