diff --git a/compiler/testData/codegen/boxWithJava/number/FortyTwoExtractor.java b/compiler/testData/codegen/boxWithJava/number/FortyTwoExtractor.java new file mode 100644 index 00000000000..123c96689f4 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/number/FortyTwoExtractor.java @@ -0,0 +1,8 @@ +public class FortyTwoExtractor { + private Number fortyTwo = new FortyTwo(); + + public int intValue() { + return fortyTwo.intValue(); + } +} + diff --git a/compiler/testData/codegen/boxWithJava/number/FortyTwoExtractor.kt b/compiler/testData/codegen/boxWithJava/number/FortyTwoExtractor.kt new file mode 100644 index 00000000000..d08d9a00233 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/number/FortyTwoExtractor.kt @@ -0,0 +1,21 @@ +class FortyTwo : Number() { + override fun toByte() = 42.toByte() + + override fun toShort() = 42.toShort() + + override fun toInt() = 42 + + override fun toLong() = 42L + + override fun toFloat() = 42.0f + + override fun toDouble() = 42.0 + + override fun toChar() = 42.toChar() +} + +fun box(): String { + val extractor = FortyTwoExtractor() + if (extractor.intValue() != 42) return "FAIL" + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index 87f002ff38e..5674bb9177f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -77,6 +77,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege doTestWithJava(fileName); } + @TestMetadata("number") + public void testNumber() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/number/"); + doTestWithJava(fileName); + } + @TestMetadata("platformName") public void testPlatformName() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/platformName/"); diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt index 8c3669cbf3a..13803185115 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt @@ -137,6 +137,12 @@ object BuiltinSpecialMethods { val REMOVE_AT_FQ_NAME = FqName("kotlin.MutableList.removeAt") val FQ_NAMES_TO_JVM_MAP: Map = mapOf( + FqName("kotlin.Number.toByte") to Name.identifier("byteValue"), + FqName("kotlin.Number.toShort") to Name.identifier("shortValue"), + FqName("kotlin.Number.toInt") to Name.identifier("intValue"), + FqName("kotlin.Number.toLong") to Name.identifier("longValue"), + FqName("kotlin.Number.toFloat") to Name.identifier("floatValue"), + FqName("kotlin.Number.toDouble") to Name.identifier("doubleValue"), REMOVE_AT_FQ_NAME to Name.identifier("remove"), FqName("kotlin.CharSequence.get") to Name.identifier("charAt") )