From be74e92c2720b14fdad8e6e01720bcd2eb4410d4 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 23 Jan 2020 11:13:02 +0300 Subject: [PATCH] [NI] Add missing type variables to common system in builder inference #KT-35967 Fixed --- .../inference/CoroutineInferenceSession.kt | 17 +++++++++++++---- .../testData/codegen/box/coroutines/kt35967.kt | 16 ++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 +++++ .../codegen/LightAnalysisModeTestGenerated.java | 15 ++++++++++----- .../ir/FirBlackBoxCodegenTestGenerated.java | 5 +++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 +++++ .../semantics/IrJsCodegenBoxTestGenerated.java | 5 +++++ .../semantics/JsCodegenBoxTestGenerated.java | 5 +++++ 8 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 compiler/testData/codegen/box/coroutines/kt35967.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt index 28c819ac230..5697da05623 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt @@ -132,7 +132,8 @@ class CoroutineInferenceSession( private fun integrateConstraints( commonSystem: NewConstraintSystemImpl, storage: ConstraintStorage, - nonFixedToVariablesSubstitutor: NewTypeSubstitutor + nonFixedToVariablesSubstitutor: NewTypeSubstitutor, + shouldIntegrateAllConstraints: Boolean ) { storage.notFixedTypeVariables.values.forEach { commonSystem.registerVariable(it.typeVariable) } @@ -163,6 +164,14 @@ class CoroutineInferenceSession( } } } + + if (shouldIntegrateAllConstraints) { + for ((variableConstructor, type) in storage.fixedTypeVariables) { + val typeVariable = storage.allTypeVariables.getValue(variableConstructor) + commonSystem.registerVariable(typeVariable) + commonSystem.addEqualityConstraint((typeVariable as NewTypeVariable).defaultType, type, CoroutinePosition()) + } + } } private fun buildCommonSystem(initialStorage: ConstraintStorage): NewConstraintSystemImpl { @@ -170,13 +179,13 @@ class CoroutineInferenceSession( val nonFixedToVariablesSubstitutor = createNonFixedTypeToVariableSubstitutor() - integrateConstraints(commonSystem, initialStorage, nonFixedToVariablesSubstitutor) + integrateConstraints(commonSystem, initialStorage, nonFixedToVariablesSubstitutor, false) for (call in commonCalls) { - integrateConstraints(commonSystem, call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor) + integrateConstraints(commonSystem, call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor, false) } for (call in partiallyResolvedCallsInfo) { - integrateConstraints(commonSystem, call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor) + integrateConstraints(commonSystem, call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor, true) } for (diagnostic in diagnostics) { commonSystem.addError(diagnostic) diff --git a/compiler/testData/codegen/box/coroutines/kt35967.kt b/compiler/testData/codegen/box/coroutines/kt35967.kt new file mode 100644 index 00000000000..5d3b5387c1f --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/kt35967.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NewInference +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +// FULL_JDK +// ISSUE: KT-35967 + +interface A { + val s: String +} +fun test(list: List) { + sequence { + yieldAll(list.map { it.s }) + } +} + +fun box(): String = "OK" diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index bf5a15657d8..f0cfbdbad9b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -6382,6 +6382,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); } + @TestMetadata("kt35967.kt") + public void testKt35967() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt35967.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index b1343881a2e..5181d131eac 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -6382,6 +6382,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); } + @TestMetadata("kt35967.kt") + public void testKt35967() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt35967.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental"); @@ -14715,6 +14720,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class NotNullAssertions extends AbstractLightAnalysisModeTest { + @TestMetadata("paramAssertionMessage.kt") + public void ignoreParamAssertionMessage() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt"); + } + private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } @@ -14803,11 +14813,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt"); } - @TestMetadata("paramAssertionMessage.kt") - public void testParamAssertionMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt"); - } - @TestMetadata("staticCallErrorMessage.kt") public void testStaticCallErrorMessage() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index c4963bf70e9..dd44a452ab7 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -6137,6 +6137,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); } + @TestMetadata("kt35967.kt") + public void testKt35967() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt35967.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index e12ba2fea59..f30f8a3daad 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -6137,6 +6137,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); } + @TestMetadata("kt35967.kt") + public void testKt35967() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt35967.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 5ec1984b1f0..df88a9ab915 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -5192,6 +5192,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); } + @TestMetadata("kt35967.kt") + public void testKt35967() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt35967.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index ccb5d6ce91b..16c1b1c72ed 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -5397,6 +5397,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); } + @TestMetadata("kt35967.kt") + public void testKt35967() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt35967.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental");