Fix capturing of outer type parameters for classes declared inside init block

This commit is contained in:
Pavel Kirpichenkov
2019-10-07 17:43:34 +03:00
parent 5e1efead9a
commit 42740c8b97
7 changed files with 46 additions and 1 deletions
+18
View File
@@ -0,0 +1,18 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
class Outer<T> (val v: T) {
val prop: Any?
init {
class Inner(val v: T) {
override fun toString() = v.toString()
}
val value: Inner = Inner(v)
prop = value
}
}
fun box(): String {
return Outer("OK").prop.toString()
}
@@ -23103,6 +23103,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/regressions/kt2318.kt");
}
@TestMetadata("kt24913.kt")
public void testKt24913() throws Exception {
runTest("compiler/testData/codegen/box/regressions/kt24913.kt");
}
@TestMetadata("Kt2495Test.kt")
public void testKt2495Test() throws Exception {
runTest("compiler/testData/codegen/box/regressions/Kt2495Test.kt");
@@ -23103,6 +23103,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/regressions/kt2318.kt");
}
@TestMetadata("kt24913.kt")
public void testKt24913() throws Exception {
runTest("compiler/testData/codegen/box/regressions/kt24913.kt");
}
@TestMetadata("Kt2495Test.kt")
public void testKt2495Test() throws Exception {
runTest("compiler/testData/codegen/box/regressions/Kt2495Test.kt");
@@ -22003,6 +22003,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/regressions/kt2318.kt");
}
@TestMetadata("kt24913.kt")
public void testKt24913() throws Exception {
runTest("compiler/testData/codegen/box/regressions/kt24913.kt");
}
@TestMetadata("Kt2495Test.kt")
public void testKt2495Test() throws Exception {
runTest("compiler/testData/codegen/box/regressions/Kt2495Test.kt");
@@ -30,7 +30,9 @@ fun ClassifierDescriptorWithTypeParameters.computeConstructorTypeParameters(): L
val parametersFromContainingFunctions =
parents.takeWhile { it is CallableDescriptor }
.flatMap { (it as CallableDescriptor).typeParameters.asSequence() }.toList()
.filter { it !is ConstructorDescriptor }
.flatMap { (it as CallableDescriptor).typeParameters.asSequence() }
.toList()
val containingClassTypeConstructorParameters = parents.firstIsInstanceOrNull<ClassDescriptor>()?.typeConstructor?.parameters.orEmpty()
if (parametersFromContainingFunctions.isEmpty() && containingClassTypeConstructorParameters.isEmpty()) return declaredTypeParameters
@@ -17753,6 +17753,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/regressions/kt2246.kt");
}
@TestMetadata("kt24913.kt")
public void testKt24913() throws Exception {
runTest("compiler/testData/codegen/box/regressions/kt24913.kt");
}
@TestMetadata("Kt2495Test.kt")
public void testKt2495Test() throws Exception {
runTest("compiler/testData/codegen/box/regressions/Kt2495Test.kt");
@@ -18908,6 +18908,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/regressions/kt2246.kt");
}
@TestMetadata("kt24913.kt")
public void testKt24913() throws Exception {
runTest("compiler/testData/codegen/box/regressions/kt24913.kt");
}
@TestMetadata("Kt2495Test.kt")
public void testKt2495Test() throws Exception {
runTest("compiler/testData/codegen/box/regressions/Kt2495Test.kt");