KT-2044 : "this" added in local variables table in bytecode for local functions also
This commit is contained in:
@@ -69,6 +69,14 @@ public class CodegenUtil {
|
||||
!(myClass.getParent() instanceof JetClassObject);
|
||||
}
|
||||
|
||||
public static boolean isLocalFun(DeclarationDescriptor fd, BindingContext bindingContext) {
|
||||
PsiElement psiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, fd);
|
||||
if(psiElement instanceof JetNamedFunction && psiElement.getParent() instanceof JetBlockExpression) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isNamedFun(DeclarationDescriptor fd, BindingContext bindingContext) {
|
||||
PsiElement psiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, fd);
|
||||
|
||||
@@ -244,8 +244,7 @@ public class FunctionCodegen {
|
||||
// TODO: specify signature
|
||||
mv.visitLocalVariable("this", type.getDescriptor(), null, methodBegin, methodEnd, k++);
|
||||
}
|
||||
|
||||
if (fun instanceof JetFunctionLiteralExpression) {
|
||||
else if (fun instanceof JetFunctionLiteralExpression || CodegenUtil.isLocalFun(functionDescriptor, state.getBindingContext())) {
|
||||
Type type = state.getInjector().getJetTypeMapper().mapType(
|
||||
context.getThisDescriptor().getDefaultType(), MapTypeMode.VALUE);
|
||||
mv.visitLocalVariable("this", type.getDescriptor(), null, methodBegin, methodEnd, k++);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo() {
|
||||
fun bar() {
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD : invoke()V
|
||||
// VARIABLE : NAME=this TYPE=Lnamespace$foo$1; INDEX=0
|
||||
@@ -0,0 +1,9 @@
|
||||
fun foo1() {
|
||||
(1..5).forEach {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD : invoke(I)V
|
||||
// VARIABLE : NAME=this TYPE=Lnamespace$foo1$1; INDEX=0
|
||||
// VARIABLE : NAME=it TYPE=I INDEX=1
|
||||
Reference in New Issue
Block a user