From bacc76944d53fccd029ea574a1c2a63253e38fa4 Mon Sep 17 00:00:00 2001 From: "Natalia.Ukhorskaya" Date: Fri, 1 Jun 2012 13:56:11 +0400 Subject: [PATCH] KT-2044 : "this" added in local variables table in bytecode for local functions also --- .../src/org/jetbrains/jet/codegen/CodegenUtil.java | 8 ++++++++ .../src/org/jetbrains/jet/codegen/FunctionCodegen.java | 3 +-- .../testData/checkLocalVariablesTable/namespace$foo$1.kt | 7 +++++++ .../checkLocalVariablesTable/namespace$foo1$1.kt | 9 +++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/checkLocalVariablesTable/namespace$foo$1.kt create mode 100644 compiler/testData/checkLocalVariablesTable/namespace$foo1$1.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index be95711e65a..8bf312c2602 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -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); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 287328ea27a..075d034e63a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -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++); diff --git a/compiler/testData/checkLocalVariablesTable/namespace$foo$1.kt b/compiler/testData/checkLocalVariablesTable/namespace$foo$1.kt new file mode 100644 index 00000000000..9ea8cf9f341 --- /dev/null +++ b/compiler/testData/checkLocalVariablesTable/namespace$foo$1.kt @@ -0,0 +1,7 @@ +fun foo() { + fun bar() { + } +} + +// METHOD : invoke()V +// VARIABLE : NAME=this TYPE=Lnamespace$foo$1; INDEX=0 \ No newline at end of file diff --git a/compiler/testData/checkLocalVariablesTable/namespace$foo1$1.kt b/compiler/testData/checkLocalVariablesTable/namespace$foo1$1.kt new file mode 100644 index 00000000000..bab01efd24b --- /dev/null +++ b/compiler/testData/checkLocalVariablesTable/namespace$foo1$1.kt @@ -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 \ No newline at end of file