Fix detection of erased this for inline class
This commit is contained in:
@@ -1673,8 +1673,11 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
|
||||
// `this` is represented as first parameter of function in erased inline class
|
||||
if (contextKind() == OwnerKind.ERASED_INLINE_CLASS &&
|
||||
InlineClassesUtilsKt.isInlineClass(propertyDescriptor.getContainingDeclaration())) {
|
||||
boolean isThisOfErasedInlineClass =
|
||||
contextKind() == OwnerKind.ERASED_INLINE_CLASS &&
|
||||
InlineClassesUtilsKt.isInlineClass(propertyDescriptor.getContainingDeclaration()) &&
|
||||
JvmCodegenUtil.hasBackingField(propertyDescriptor, contextKind(), bindingContext);
|
||||
if (isThisOfErasedInlineClass) {
|
||||
Type underlyingRepresentationType = typeMapper.mapType(propertyDescriptor.getType());
|
||||
return StackValue.local(0, underlyingRepresentationType);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
@@ -338,4 +327,12 @@ public class JvmCodegenUtil {
|
||||
isJvmInterface(companionObject.getContainingDeclaration()) &&
|
||||
!JvmAbi.isMappedIntrinsicCompanionObject((ClassDescriptor) companionObject);
|
||||
}
|
||||
|
||||
public static boolean hasBackingField(
|
||||
@NotNull PropertyDescriptor descriptor, @NotNull OwnerKind kind, @NotNull BindingContext bindingContext
|
||||
) {
|
||||
return !isJvmInterface(descriptor.getContainingDeclaration()) &&
|
||||
kind != OwnerKind.DEFAULT_IMPLS &&
|
||||
!Boolean.FALSE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class PropertyCodegen {
|
||||
private void genBackingFieldAndAnnotations(
|
||||
@Nullable KtNamedDeclaration declaration, @NotNull PropertyDescriptor descriptor, boolean isParameter
|
||||
) {
|
||||
boolean hasBackingField = hasBackingField(descriptor);
|
||||
boolean hasBackingField = JvmCodegenUtil.hasBackingField(descriptor, kind, bindingContext);
|
||||
boolean hasDelegate = declaration instanceof KtProperty && ((KtProperty) declaration).hasDelegate();
|
||||
|
||||
AnnotationSplitter annotationSplitter =
|
||||
@@ -303,12 +303,6 @@ public class PropertyCodegen {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean hasBackingField(@NotNull PropertyDescriptor descriptor) {
|
||||
return !isJvmInterface(descriptor.getContainingDeclaration()) &&
|
||||
kind != OwnerKind.DEFAULT_IMPLS &&
|
||||
!Boolean.FALSE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor));
|
||||
}
|
||||
|
||||
private boolean generateBackingField(
|
||||
@NotNull KtNamedDeclaration p,
|
||||
@NotNull PropertyDescriptor descriptor,
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class Props(val intArray: IntArray) {
|
||||
val size get() = intArray.size
|
||||
|
||||
fun foo(): Int {
|
||||
val a = size
|
||||
return a
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = Props(intArrayOf(1, 2, 3))
|
||||
if (f.foo() != 3) return "fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Generated
+6
@@ -10401,6 +10401,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callComputablePropertyInsideInlineClass.kt")
|
||||
public void testCallComputablePropertyInsideInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/callComputablePropertyInsideInlineClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
||||
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
||||
|
||||
+6
@@ -10401,6 +10401,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callComputablePropertyInsideInlineClass.kt")
|
||||
public void testCallComputablePropertyInsideInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/callComputablePropertyInsideInlineClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
||||
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
||||
|
||||
+6
@@ -10401,6 +10401,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callComputablePropertyInsideInlineClass.kt")
|
||||
public void testCallComputablePropertyInsideInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/callComputablePropertyInsideInlineClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
||||
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
||||
|
||||
+6
@@ -11385,6 +11385,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callComputablePropertyInsideInlineClass.kt")
|
||||
public void testCallComputablePropertyInsideInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/callComputablePropertyInsideInlineClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
||||
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
||||
|
||||
Reference in New Issue
Block a user