KT-28585 Fix boxing for values of captured vars of inline class type

This commit is contained in:
Dmitry Petrov
2018-12-07 14:11:37 +03:00
parent 45035d3e11
commit 8ede477f99
7 changed files with 54 additions and 5 deletions
@@ -728,15 +728,20 @@ public abstract class StackValue {
@NotNull Field refWrapper,
@NotNull VariableDescriptor variableDescriptor
) {
return new FieldForSharedVar(localType, classType, fieldName, refWrapper,
variableDescriptor.isLateInit(), variableDescriptor.getName());
return new FieldForSharedVar(
localType, variableDescriptor.getType(), classType, fieldName, refWrapper,
variableDescriptor.isLateInit(), variableDescriptor.getName()
);
}
@NotNull
public static FieldForSharedVar fieldForSharedVar(@NotNull FieldForSharedVar field, @NotNull StackValue newReceiver) {
Field oldReceiver = (Field) field.receiver;
Field newSharedVarReceiver = field(oldReceiver, newReceiver);
return new FieldForSharedVar(field.type, field.owner, field.name, newSharedVarReceiver, field.isLateinit, field.variableName);
return new FieldForSharedVar(
field.type, field.kotlinType,
field.owner, field.name, newSharedVarReceiver, field.isLateinit, field.variableName
);
}
public static StackValue coercion(@NotNull StackValue value, @NotNull Type castType, @Nullable KotlinType castKotlinType) {
@@ -1900,10 +1905,11 @@ public abstract class StackValue {
final Name variableName;
public FieldForSharedVar(
Type type, Type owner, String name, StackValue.Field receiver,
Type type, KotlinType kotlinType,
Type owner, String name, StackValue.Field receiver,
boolean isLateinit, Name variableName
) {
super(type, null, false, false, receiver, receiver.canHaveSideEffects());
super(type, kotlinType, false, false, receiver, receiver.canHaveSideEffects());
if (isLateinit && variableName == null) {
throw new IllegalArgumentException("variableName should be non-null for captured lateinit variable " + name);
+18
View File
@@ -0,0 +1,18 @@
// !LANGUAGE: +InlineClasses
// WITH_RUNTIME
// IGNORE_BACKEND: JVM_IR
fun box(): String {
var uint1 = 1u
var uint2 = 2u
var uint3 = 3u
val uintSet = mutableSetOf(uint1)
uintSet.add(uint2);
{
uintSet.add(uint3)
if (!uintSet.contains(1u)) throw AssertionError()
if (!uintSet.contains(2u)) throw AssertionError()
if (!uintSet.contains(3u)) throw AssertionError()
}()
return "OK"
}
@@ -12125,6 +12125,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt28405.kt");
}
@TestMetadata("kt28585.kt")
public void testKt28585() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt28585.kt");
}
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
@@ -12125,6 +12125,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/kt28405.kt");
}
@TestMetadata("kt28585.kt")
public void testKt28585() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt28585.kt");
}
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
@@ -12130,6 +12130,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inlineClasses/kt28405.kt");
}
@TestMetadata("kt28585.kt")
public void testKt28585() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt28585.kt");
}
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
@@ -10495,6 +10495,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt28405.kt");
}
@TestMetadata("kt28585.kt")
public void testKt28585() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt28585.kt");
}
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
@@ -11550,6 +11550,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt28405.kt");
}
@TestMetadata("kt28585.kt")
public void testKt28585() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt28585.kt");
}
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");