KT-13658: don't capture FakeCallableDescriptorForObject in closure
This commit is contained in:
@@ -191,4 +191,8 @@ public final class ClosureTest extends SingleFileTranslationTest {
|
|||||||
public void testLambdaInLocalFun() throws Exception {
|
public void testLambdaInLocalFun() throws Exception {
|
||||||
checkFooBoxIsOk();
|
checkFooBoxIsOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testObjectWithInvokeOperator() throws Exception {
|
||||||
|
checkFooBoxIsOk();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.js.translate.utils.ManglingUtils.getSuggestedName
|
|||||||
import com.google.dart.compiler.backend.js.ast.JsScope
|
import com.google.dart.compiler.backend.js.ast.JsScope
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.*
|
import org.jetbrains.kotlin.resolve.DescriptorUtils.*
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||||
|
|
||||||
private val CAPTURED_RECEIVER_NAME_PREFIX : String = "this$"
|
private val CAPTURED_RECEIVER_NAME_PREFIX : String = "this$"
|
||||||
|
|
||||||
@@ -43,6 +44,8 @@ class UsageTracker(
|
|||||||
fun used(descriptor: DeclarationDescriptor) {
|
fun used(descriptor: DeclarationDescriptor) {
|
||||||
if (isCaptured(descriptor)) return
|
if (isCaptured(descriptor)) return
|
||||||
|
|
||||||
|
if (descriptor is FakeCallableDescriptorForObject) return
|
||||||
|
|
||||||
// local named function
|
// local named function
|
||||||
if (descriptor is FunctionDescriptor && descriptor.visibility == Visibilities.LOCAL) {
|
if (descriptor is FunctionDescriptor && descriptor.visibility == Visibilities.LOCAL) {
|
||||||
assert(!descriptor.getName().isSpecial) { "Function with special name can not be captured, descriptor: $descriptor" }
|
assert(!descriptor.getName().isSpecial) { "Function with special name can not be captured, descriptor: $descriptor" }
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
object O {
|
||||||
|
val result = "O"
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun O.invoke() = result
|
||||||
|
|
||||||
|
|
||||||
|
class A(val x: Int) {
|
||||||
|
companion object {
|
||||||
|
val result = "A"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun A.Companion.invoke() = result
|
||||||
|
|
||||||
|
|
||||||
|
enum class B {
|
||||||
|
E {
|
||||||
|
val result = "B"
|
||||||
|
|
||||||
|
override operator fun invoke() = result
|
||||||
|
};
|
||||||
|
|
||||||
|
abstract operator fun invoke(): String
|
||||||
|
}
|
||||||
|
|
||||||
|
fun f() = { O() + A() + B.E() }
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val result = f()()
|
||||||
|
if (result != "OAB") return "expected 'OAB', got '$result'"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user