NI: approximate not top-level captured types during code generation

^KT-40693 Fixed
This commit is contained in:
Victor Petukhov
2020-08-04 16:03:59 +03:00
parent f6d7e7c52a
commit f45de9d8fb
9 changed files with 64 additions and 1 deletions
@@ -2835,7 +2835,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
TypeApproximator approximator = new TypeApproximator(state.getModule().getBuiltIns());
KotlinType approximatedType =
CapturedTypeConstructorKt.isCaptured(type) ?
TypeUtils.contains(type, (containedType) -> CapturedTypeConstructorKt.isCaptured(containedType)) ?
(KotlinType) approximator.approximateToSuperType(
type, TypeApproximatorConfiguration.InternalTypesApproximation.INSTANCE
) : null;
@@ -12414,6 +12414,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("approximateNonTopLevelCapturedTypes.kt")
public void testApproximateNonTopLevelCapturedTypes() throws Exception {
runTest("compiler/testData/codegen/box/inference/approximateNonTopLevelCapturedTypes.kt");
}
@TestMetadata("builderInference.kt")
public void testBuilderInference() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference.kt");
@@ -0,0 +1,13 @@
interface BasePublisher<U>
interface Flow<out P>
fun <R> asFlow(x: BasePublisher<R>): Flow<R> = null as Flow<R>
class Document<S>
interface DerivedPublisher<K>: BasePublisher<Document<K>> {}
class Foo<T>(val x: DerivedPublisher<out T>) : Flow<Document<out T>> by asFlow(x)
fun box() = "OK"
@@ -13639,6 +13639,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("approximateNonTopLevelCapturedTypes.kt")
public void testApproximateNonTopLevelCapturedTypes() throws Exception {
runTest("compiler/testData/codegen/box/inference/approximateNonTopLevelCapturedTypes.kt");
}
@TestMetadata("builderInference.kt")
public void testBuilderInference() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference.kt");
@@ -13639,6 +13639,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("approximateNonTopLevelCapturedTypes.kt")
public void testApproximateNonTopLevelCapturedTypes() throws Exception {
runTest("compiler/testData/codegen/box/inference/approximateNonTopLevelCapturedTypes.kt");
}
@TestMetadata("builderInference.kt")
public void testBuilderInference() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference.kt");
@@ -12414,6 +12414,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("approximateNonTopLevelCapturedTypes.kt")
public void testApproximateNonTopLevelCapturedTypes() throws Exception {
runTest("compiler/testData/codegen/box/inference/approximateNonTopLevelCapturedTypes.kt");
}
@TestMetadata("builderInference.kt")
public void testBuilderInference() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference.kt");
@@ -41,6 +41,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/annotations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("annotatedObjectLiteral.kt")
public void testAnnotatedObjectLiteral() throws Exception {
runTest("compiler/testData/codegen/box/annotations/annotatedObjectLiteral.kt");
}
@TestMetadata("nestedAnnotation.kt")
public void testNestedAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt");
@@ -10689,6 +10694,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("approximateNonTopLevelCapturedTypes.kt")
public void testApproximateNonTopLevelCapturedTypes() throws Exception {
runTest("compiler/testData/codegen/box/inference/approximateNonTopLevelCapturedTypes.kt");
}
@TestMetadata("builderInferenceLeakingVariable.kt")
public void testBuilderInferenceLeakingVariable() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInferenceLeakingVariable.kt");
@@ -41,6 +41,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/annotations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("annotatedObjectLiteral.kt")
public void testAnnotatedObjectLiteral() throws Exception {
runTest("compiler/testData/codegen/box/annotations/annotatedObjectLiteral.kt");
}
@TestMetadata("nestedAnnotation.kt")
public void testNestedAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt");
@@ -10689,6 +10694,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("approximateNonTopLevelCapturedTypes.kt")
public void testApproximateNonTopLevelCapturedTypes() throws Exception {
runTest("compiler/testData/codegen/box/inference/approximateNonTopLevelCapturedTypes.kt");
}
@TestMetadata("builderInferenceLeakingVariable.kt")
public void testBuilderInferenceLeakingVariable() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInferenceLeakingVariable.kt");
@@ -41,6 +41,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/annotations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("annotatedObjectLiteral.kt")
public void testAnnotatedObjectLiteral() throws Exception {
runTest("compiler/testData/codegen/box/annotations/annotatedObjectLiteral.kt");
}
@TestMetadata("nestedAnnotation.kt")
public void testNestedAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt");
@@ -10754,6 +10759,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("approximateNonTopLevelCapturedTypes.kt")
public void testApproximateNonTopLevelCapturedTypes() throws Exception {
runTest("compiler/testData/codegen/box/inference/approximateNonTopLevelCapturedTypes.kt");
}
@TestMetadata("builderInferenceLeakingVariable.kt")
public void testBuilderInferenceLeakingVariable() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInferenceLeakingVariable.kt");