Fix type mapping for parameter of Collection<Int>::remove override

In the case the single parameter of override has `Integer` type instead
of `int` type (while in common case it would be just `int`)

See the comment inside forceSingleValueParameterBoxing for clarification

 #KT-19892 Fixed
This commit is contained in:
Denis Zharkov
2017-08-31 12:38:08 +03:00
parent 73c139d250
commit ed79891ee6
7 changed files with 59 additions and 3 deletions
@@ -61,6 +61,7 @@ import org.jetbrains.kotlin.diagnostics.Errors;
import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.load.java.JvmAbi;
import org.jetbrains.kotlin.load.java.sam.SamConstructorDescriptor;
import org.jetbrains.kotlin.load.kotlin.MethodSignatureMappingKt;
import org.jetbrains.kotlin.load.kotlin.TypeSignatureMappingKt;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*;
@@ -1284,8 +1285,19 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
KotlinType varType = isDelegatedLocalVariable(variableDescriptor)
? JvmCodegenUtil.getPropertyDelegateType((VariableDescriptorWithAccessors) variableDescriptor, bindingContext)
: variableDescriptor.getType();
//noinspection ConstantConditions
return asmType(varType);
if (variableDescriptor instanceof ValueParameterDescriptor &&
MethodSignatureMappingKt.forceSingleValueParameterBoxing(
(CallableDescriptor) variableDescriptor.getContainingDeclaration()
)
) {
//noinspection ConstantConditions
return asmType(TypeUtils.makeNullable(varType));
}
else {
//noinspection ConstantConditions
return asmType(varType);
}
}
private void putDescriptorIntoFrameMap(@NotNull KtElement statement) {
@@ -0,0 +1,18 @@
class MySet : HashSet<Int>() {
override fun remove(element: Int): Boolean {
return super.remove(element)
}
}
fun box(): String {
val a = MySet()
a.add(1)
a.add(2)
a.add(3)
if (!a.remove(1)) return "fail 1"
if (a.remove(1)) return "fail 2"
if (a.contains(1)) return "fail 3"
return "OK"
}
@@ -18080,6 +18080,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("removeSetInt.kt")
public void testRemoveSetInt() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/specialBuiltins/removeSetInt.kt");
doTest(fileName);
}
@TestMetadata("throwable.kt")
public void testThrowable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/specialBuiltins/throwable.kt");
@@ -18080,6 +18080,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("removeSetInt.kt")
public void testRemoveSetInt() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/specialBuiltins/removeSetInt.kt");
doTest(fileName);
}
@TestMetadata("throwable.kt")
public void testThrowable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/specialBuiltins/throwable.kt");
@@ -18080,6 +18080,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
doTest(fileName);
}
@TestMetadata("removeSetInt.kt")
public void testRemoveSetInt() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/specialBuiltins/removeSetInt.kt");
doTest(fileName);
}
@TestMetadata("throwable.kt")
public void testThrowable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/specialBuiltins/throwable.kt");
@@ -52,7 +52,9 @@ fun FunctionDescriptor.computeJvmDescriptor(withReturnType: Boolean = true)
// Boxing is only necessary for 'remove(E): Boolean' of a MutableCollection<Int> implementation
// Otherwise this method might clash with 'remove(I): E' defined in the java.util.List JDK interface (mapped to kotlin 'removeAt')
fun forceSingleValueParameterBoxing(f: FunctionDescriptor): Boolean {
fun forceSingleValueParameterBoxing(f: CallableDescriptor): Boolean {
if (f !is FunctionDescriptor) return false
if (f.valueParameters.size != 1 || f.isFromJavaOrBuiltins() || f.name.asString() != "remove") return false
if ((f.original.valueParameters.single().type.mapToJvmType() as? JvmType.Primitive)?.jvmPrimitiveType != JvmPrimitiveType.INT) return false
@@ -22076,6 +22076,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
doTest(fileName);
}
@TestMetadata("removeSetInt.kt")
public void testRemoveSetInt() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/specialBuiltins/removeSetInt.kt");
doTest(fileName);
}
@TestMetadata("throwable.kt")
public void testThrowable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/specialBuiltins/throwable.kt");