From b08a32af2f5874badd3fcdafca96e078f5cca0f0 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 31 Jan 2018 22:07:33 +0300 Subject: [PATCH] Fix local variables table for inline classes --- .../org/jetbrains/kotlin/codegen/FunctionCodegen.java | 8 +++++--- .../kotlin/codegen/state/KotlinTypeMapper.java | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index c260c817255..23d51c511a1 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -529,16 +529,18 @@ public class FunctionCodegen { @NotNull KotlinTypeMapper typeMapper ) { ReceiverParameterDescriptor dispatchReceiver = functionDescriptor.getDispatchReceiverParameter(); + // all functions inside erased version of inline class are static, so they don't have `this` as is, + // but functions inside wrapper class should use type of wrapper class, not the underlying type if (functionDescriptor instanceof ConstructorDescriptor) { - return typeMapper.mapType(functionDescriptor); + return typeMapper.mapTypeAsDeclaration(functionDescriptor); } else if (dispatchReceiver != null) { - return typeMapper.mapType(dispatchReceiver.getType()); + return typeMapper.mapTypeAsDeclaration(dispatchReceiver.getType()); } else if (isFunctionLiteral(functionDescriptor) || isLocalFunction(functionDescriptor) || isFunctionExpression(functionDescriptor)) { - return typeMapper.mapType(context.getThisDescriptor()); + return typeMapper.mapClass(context.getThisDescriptor()); } else { return null; diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java index 1123563b3ad..866f3a5d662 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java @@ -396,12 +396,23 @@ public class KotlinTypeMapper { return mapType(jetType, null, TypeMappingMode.DEFAULT); } + @NotNull + public Type mapTypeAsDeclaration(@NotNull KotlinType kotlinType) { + return mapType(kotlinType, null, TypeMappingMode.CLASS_DECLARATION); + } + @NotNull public Type mapType(@NotNull CallableDescriptor descriptor) { //noinspection ConstantConditions return mapType(descriptor.getReturnType()); } + @NotNull + public Type mapTypeAsDeclaration(@NotNull CallableDescriptor descriptor) { + //noinspection ConstantConditions + return mapTypeAsDeclaration(descriptor.getReturnType()); + } + public Type mapErasedInlineClass(@NotNull ClassDescriptor descriptor) { return Type.getObjectType(mapClass(descriptor).getInternalName() + JvmAbi.ERASED_INLINE_CLASS_SUFFIX); }