IR: capture more type parameters for local functions.
Types of value parameters and captured variables, even unused, need to be considered.
This commit is contained in:
+9
-6
@@ -88,13 +88,16 @@ class ClosureAnnotator(irFile: IrFile) {
|
||||
}
|
||||
|
||||
fun declareVariable(valueDeclaration: IrValueDeclaration?) {
|
||||
if (valueDeclaration != null)
|
||||
if (valueDeclaration != null) {
|
||||
declaredValues.add(valueDeclaration)
|
||||
seeType(valueDeclaration.type)
|
||||
}
|
||||
}
|
||||
|
||||
fun seeVariable(value: IrValueSymbol) {
|
||||
if (isExternal(value.owner))
|
||||
if (isExternal(value.owner)) {
|
||||
capturedValues.add(value)
|
||||
}
|
||||
}
|
||||
|
||||
fun isExternal(valueDeclaration: IrValueDeclaration): Boolean {
|
||||
@@ -144,6 +147,8 @@ class ClosureAnnotator(irFile: IrFile) {
|
||||
val closureBuilder = ClosureBuilder(declaration)
|
||||
closureBuilders[declaration] = closureBuilder
|
||||
|
||||
collectPotentiallyCapturedTypeParameters(closureBuilder)
|
||||
|
||||
closureBuilder.declareVariable(declaration.thisReceiver)
|
||||
if (declaration.isInner) {
|
||||
closureBuilder.declareVariable((declaration.parent as IrClass).thisReceiver)
|
||||
@@ -155,8 +160,6 @@ class ClosureAnnotator(irFile: IrFile) {
|
||||
constructor.valueParameters.forEach { v -> closureBuilder.declareVariable(v) }
|
||||
}
|
||||
|
||||
collectPotentiallyCapturedTypeParameters(closureBuilder)
|
||||
|
||||
closuresStack.push(closureBuilder)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
closuresStack.pop()
|
||||
@@ -166,6 +169,8 @@ class ClosureAnnotator(irFile: IrFile) {
|
||||
val closureBuilder = ClosureBuilder(declaration)
|
||||
closureBuilders[declaration] = closureBuilder
|
||||
|
||||
collectPotentiallyCapturedTypeParameters(closureBuilder)
|
||||
|
||||
declaration.valueParameters.forEach { closureBuilder.declareVariable(it) }
|
||||
closureBuilder.declareVariable(declaration.dispatchReceiverParameter)
|
||||
closureBuilder.declareVariable(declaration.extensionReceiverParameter)
|
||||
@@ -182,8 +187,6 @@ class ClosureAnnotator(irFile: IrFile) {
|
||||
}
|
||||
}
|
||||
|
||||
collectPotentiallyCapturedTypeParameters(closureBuilder)
|
||||
|
||||
closuresStack.push(closureBuilder)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
closuresStack.pop()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package test;
|
||||
|
||||
class TypeParamInInner2 {
|
||||
void check() {
|
||||
TypeParamInInner2Kt.f("OK");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
fun <V> f(x: V): Int {
|
||||
fun g(y: V) = 2
|
||||
return g(x)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package test
|
||||
|
||||
public fun </*0*/ V> f(/*0*/ V): kotlin.Int
|
||||
|
||||
public/*package*/ open class TypeParamInInner2 {
|
||||
public/*package*/ constructor TypeParamInInner2()
|
||||
public/*package*/ open fun check(): kotlin.Unit
|
||||
}
|
||||
Generated
+10
@@ -318,6 +318,11 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg
|
||||
runTest("compiler/testData/compileJavaAgainstKotlin/method/TypeParamInInner.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TypeParamInInner2.kt")
|
||||
public void testTypeParamInInner2() throws Exception {
|
||||
runTest("compiler/testData/compileJavaAgainstKotlin/method/TypeParamInInner2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
runTest("compiler/testData/compileJavaAgainstKotlin/method/Vararg.kt");
|
||||
@@ -966,6 +971,11 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg
|
||||
runTest("compiler/testData/compileJavaAgainstKotlin/method/TypeParamInInner.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TypeParamInInner2.kt")
|
||||
public void testTypeParamInInner2() throws Exception {
|
||||
runTest("compiler/testData/compileJavaAgainstKotlin/method/TypeParamInInner2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
runTest("compiler/testData/compileJavaAgainstKotlin/method/Vararg.kt");
|
||||
|
||||
Generated
+5
@@ -316,6 +316,11 @@ public class IrCompileJavaAgainstKotlinTestGenerated extends AbstractIrCompileJa
|
||||
runTest("compiler/testData/compileJavaAgainstKotlin/method/TypeParamInInner.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TypeParamInInner2.kt")
|
||||
public void testTypeParamInInner2() throws Exception {
|
||||
runTest("compiler/testData/compileJavaAgainstKotlin/method/TypeParamInInner2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
runTest("compiler/testData/compileJavaAgainstKotlin/method/Vararg.kt");
|
||||
|
||||
Reference in New Issue
Block a user