[NI] Add missing type variables to common system in builder inference

#KT-35967 Fixed
This commit is contained in:
Dmitriy Novozhilov
2020-01-23 11:13:02 +03:00
parent 6d49f36cd6
commit be74e92c27
8 changed files with 64 additions and 9 deletions
@@ -132,7 +132,8 @@ class CoroutineInferenceSession(
private fun integrateConstraints( private fun integrateConstraints(
commonSystem: NewConstraintSystemImpl, commonSystem: NewConstraintSystemImpl,
storage: ConstraintStorage, storage: ConstraintStorage,
nonFixedToVariablesSubstitutor: NewTypeSubstitutor nonFixedToVariablesSubstitutor: NewTypeSubstitutor,
shouldIntegrateAllConstraints: Boolean
) { ) {
storage.notFixedTypeVariables.values.forEach { commonSystem.registerVariable(it.typeVariable) } 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 { private fun buildCommonSystem(initialStorage: ConstraintStorage): NewConstraintSystemImpl {
@@ -170,13 +179,13 @@ class CoroutineInferenceSession(
val nonFixedToVariablesSubstitutor = createNonFixedTypeToVariableSubstitutor() val nonFixedToVariablesSubstitutor = createNonFixedTypeToVariableSubstitutor()
integrateConstraints(commonSystem, initialStorage, nonFixedToVariablesSubstitutor) integrateConstraints(commonSystem, initialStorage, nonFixedToVariablesSubstitutor, false)
for (call in commonCalls) { for (call in commonCalls) {
integrateConstraints(commonSystem, call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor) integrateConstraints(commonSystem, call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor, false)
} }
for (call in partiallyResolvedCallsInfo) { for (call in partiallyResolvedCallsInfo) {
integrateConstraints(commonSystem, call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor) integrateConstraints(commonSystem, call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor, true)
} }
for (diagnostic in diagnostics) { for (diagnostic in diagnostics) {
commonSystem.addError(diagnostic) commonSystem.addError(diagnostic)
+16
View File
@@ -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<A>) {
sequence {
yieldAll(list.map { it.s })
}
}
fun box(): String = "OK"
@@ -6382,6 +6382,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); 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") @TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_2() throws Exception { public void testLastExpressionIsLoop_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental"); runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental");
@@ -6382,6 +6382,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); 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") @TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_2() throws Exception { public void testLastExpressionIsLoop_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental"); runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental");
@@ -14715,6 +14720,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
public static class NotNullAssertions extends AbstractLightAnalysisModeTest { 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 { private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); 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"); 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") @TestMetadata("staticCallErrorMessage.kt")
public void testStaticCallErrorMessage() throws Exception { public void testStaticCallErrorMessage() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt"); runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt");
@@ -6137,6 +6137,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); 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") @TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_3() throws Exception { public void testLastExpressionIsLoop_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines"); runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines");
@@ -6137,6 +6137,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); 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") @TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_3() throws Exception { public void testLastExpressionIsLoop_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines"); runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines");
@@ -5192,6 +5192,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); 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") @TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_3() throws Exception { public void testLastExpressionIsLoop_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines"); runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines");
@@ -5397,6 +5397,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/kt31784.kt"); 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") @TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_2() throws Exception { public void testLastExpressionIsLoop_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental"); runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental");