[NI] Avoid type capturing for types that can contain type variables

This commit is contained in:
Mikhail Zarechenskiy
2017-08-17 14:36:56 +03:00
committed by Stanislav Erokhin
parent e040a317cc
commit 08964006de
7 changed files with 75 additions and 1 deletions
@@ -224,7 +224,9 @@ internal fun createSimplePSICallArgument(
ownerDescriptor, bindingContext,
typeInfoForArgument.dataFlowInfo, // dataFlowInfoBeforeThisArgument cannot be used here, because of if() { if (x != null) return; x }
ExpressionReceiver.create(ktExpression, baseType, bindingContext)
).prepareReceiverRegardingCaptureTypes()
).let {
if (onlyResolvedCall == null) it.prepareReceiverRegardingCaptureTypes() else it
}
return if (onlyResolvedCall == null) {
ExpressionKotlinCallArgumentImpl(valueArgument, dataFlowInfoBeforeThisArgument, typeInfoForArgument.dataFlowInfo, receiverToCast)
@@ -0,0 +1,14 @@
fun test(i: Inv<out Any?>) {
foo(i.superclass())
}
fun <T> foo(x: T) {}
class Inv<T>
fun <T> Inv<T>.superclass(): Inv<in T> = Inv()
fun box(): String {
test(Inv())
return "OK"
}
@@ -0,0 +1,10 @@
fun foo(useScriptArgs: Array<out Any?>?) {
val constructorArgs: Array<out Any?> = arrayOf(useScriptArgs.orEmpty())
}
inline fun <reified T> Array<out T>?.orEmpty(): Array<out T> = this ?: emptyArray<T>()
fun box(): String {
foo(arrayOf(1))
return "OK"
}
@@ -16580,6 +16580,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("dontCaptureTypesWithTypeVariables.kt")
public void testDontCaptureTypesWithTypeVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/dontCaptureTypesWithTypeVariables.kt");
doTest(fileName);
}
@TestMetadata("doubleMerge.kt")
public void testDoubleMerge() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/doubleMerge.kt");
@@ -16976,6 +16982,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("noCapturingForTypesWithTypeVariables.kt")
public void testNoCapturingForTypesWithTypeVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noCapturingForTypesWithTypeVariables.kt");
doTest(fileName);
}
@TestMetadata("noResolutionRecursion.kt")
public void testNoResolutionRecursion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noResolutionRecursion.kt");
@@ -16580,6 +16580,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("dontCaptureTypesWithTypeVariables.kt")
public void testDontCaptureTypesWithTypeVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/dontCaptureTypesWithTypeVariables.kt");
doTest(fileName);
}
@TestMetadata("doubleMerge.kt")
public void testDoubleMerge() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/doubleMerge.kt");
@@ -16976,6 +16982,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("noCapturingForTypesWithTypeVariables.kt")
public void testNoCapturingForTypesWithTypeVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noCapturingForTypesWithTypeVariables.kt");
doTest(fileName);
}
@TestMetadata("noResolutionRecursion.kt")
public void testNoResolutionRecursion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noResolutionRecursion.kt");
@@ -16580,6 +16580,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
doTest(fileName);
}
@TestMetadata("dontCaptureTypesWithTypeVariables.kt")
public void testDontCaptureTypesWithTypeVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/dontCaptureTypesWithTypeVariables.kt");
doTest(fileName);
}
@TestMetadata("doubleMerge.kt")
public void testDoubleMerge() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/doubleMerge.kt");
@@ -16976,6 +16982,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
doTest(fileName);
}
@TestMetadata("noCapturingForTypesWithTypeVariables.kt")
public void testNoCapturingForTypesWithTypeVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noCapturingForTypesWithTypeVariables.kt");
doTest(fileName);
}
@TestMetadata("noResolutionRecursion.kt")
public void testNoResolutionRecursion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noResolutionRecursion.kt");
@@ -20228,6 +20228,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
doTest(fileName);
}
@TestMetadata("dontCaptureTypesWithTypeVariables.kt")
public void testDontCaptureTypesWithTypeVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/dontCaptureTypesWithTypeVariables.kt");
doTest(fileName);
}
@TestMetadata("doubleMerge.kt")
public void testDoubleMerge() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/doubleMerge.kt");
@@ -20750,6 +20756,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
}
@TestMetadata("noCapturingForTypesWithTypeVariables.kt")
public void testNoCapturingForTypesWithTypeVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noCapturingForTypesWithTypeVariables.kt");
doTest(fileName);
}
@TestMetadata("noResolutionRecursion.kt")
public void testNoResolutionRecursion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noResolutionRecursion.kt");