Use mapping mode for inline class underlying type without wrapping
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR
|
||||
|
||||
inline class GCmp<T>(val xc: Comparable<T>)
|
||||
inline class GSCmp<T>(val sc: Comparable<String>)
|
||||
inline class SCmp(val sc: Comparable<String>)
|
||||
inline class ICmp(val intc: Comparable<Int>)
|
||||
inline class GICmp<T>(val intc: Comparable<Int>)
|
||||
|
||||
inline class II(val i: Int) : Comparable<II> {
|
||||
override fun compareTo(other: II): Int {
|
||||
return i.compareTo(other.i)
|
||||
}
|
||||
}
|
||||
|
||||
inline class IICmp(val iic: Comparable<II>)
|
||||
inline class GIICmp<T>(val iic: Comparable<II>)
|
||||
|
||||
fun testGCmp(x: GCmp<String>) {
|
||||
if (x.xc.compareTo("OK") != 0) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testGSCmp(x: GSCmp<Any>) {
|
||||
if (x.sc.compareTo("OK") != 0) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testSCmp(x: SCmp) {
|
||||
if (x.sc.compareTo("OK") != 0) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testICmp(x: ICmp) {
|
||||
if (x.intc.compareTo(42) != 0) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testGICmp(x: GICmp<Any>) {
|
||||
if (x.intc.compareTo(42) != 0) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testIICmp(x: IICmp) {
|
||||
if (x.iic.compareTo(II(42)) != 0) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testGIICmp(x: GIICmp<Any>) {
|
||||
if (x.iic.compareTo(II(42)) != 0) throw AssertionError()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testGCmp(GCmp("OK"))
|
||||
testGSCmp(GSCmp<Any>("OK"))
|
||||
testSCmp(SCmp("OK"))
|
||||
testICmp(ICmp(42))
|
||||
testGICmp(GICmp<Any>(42))
|
||||
testIICmp(IICmp(II(42)))
|
||||
testGIICmp(GIICmp<Any>(II(42)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR
|
||||
|
||||
inline class GList<T>(val xs: List<T>)
|
||||
inline class GSList<T>(val ss: List<String>)
|
||||
inline class SList(val ss: List<String>)
|
||||
inline class IList(val ints: List<Int>)
|
||||
inline class GIList<T>(val ints: List<Int>)
|
||||
|
||||
inline class II(val i: Int)
|
||||
inline class IIList(val iis: List<II>)
|
||||
inline class GIIList<T>(val iis: List<II>)
|
||||
|
||||
fun testGList(gl: GList<String>) {
|
||||
if (gl.xs[0] != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun testGSList(sl: GSList<String>) {
|
||||
if (sl.ss[0] != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun testSList(sl: SList) {
|
||||
if (sl.ss[0] != "OK") throw AssertionError()
|
||||
}
|
||||
|
||||
fun testIList(il: IList) {
|
||||
if (il.ints[0] != 42) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testGIList(gil: GIList<Any>) {
|
||||
if (gil.ints[0] != 42) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testIIList(iil: IIList) {
|
||||
if (iil.iis[0].i != 42) throw AssertionError()
|
||||
}
|
||||
|
||||
fun testGIIList(giil: GIIList<Any>) {
|
||||
if (giil.iis[0].i != 42) throw AssertionError()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testGList(GList(listOf("OK")))
|
||||
testGSList(GSList(listOf("OK")))
|
||||
testSList(SList(listOf("OK")))
|
||||
testIList(IList(listOf(42)))
|
||||
testGIList(GIList<Any>(listOf(42)))
|
||||
testIIList(IIList(listOf(II(42))))
|
||||
testGIIList(GIIList<Any>(listOf(II(42))))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+25
-8
@@ -1,24 +1,41 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
class Inv<T>
|
||||
|
||||
inline class AsList<T>(val list: List<T>)
|
||||
inline class UInt(val value: Int)
|
||||
|
||||
inline class AsList<T>(val list: List<T>)
|
||||
inline class AsCmp<T>(val cmp: Comparable<T>)
|
||||
|
||||
object Test {
|
||||
fun withInlineClassArgument(a: AsList<UInt>) {}
|
||||
fun withInlineClassArgumentOut(a: AsList<UInt>) {}
|
||||
fun withInlineClassArgumentIn(a: AsCmp<UInt>) {}
|
||||
|
||||
fun withListOfInlineClassArgument(a: AsList<List<UInt>>) {}
|
||||
fun withInnerGenericInlineClass(a: AsList<AsList<List<UInt>>>) {}
|
||||
fun withComparableOfInlineClassArgument(a: AsCmp<Comparable<UInt>>) {}
|
||||
|
||||
fun withInnerGenericInlineClassOut(a: AsList<AsList<List<UInt>>>) {}
|
||||
fun withInnerGenericInlineClassIn(a: AsCmp<AsCmp<Comparable<UInt>>>) {}
|
||||
}
|
||||
|
||||
// method: Test::withInlineClassArgument
|
||||
// method: Test::withInlineClassArgumentOut
|
||||
// jvm signature: (Ljava/util/List;)V
|
||||
// generic signature: (Ljava/util/List<LUInt;>;)V
|
||||
|
||||
// method: Test::withInlineClassArgumentIn
|
||||
// jvm signature: (Ljava/lang/Comparable;)V
|
||||
// generic signature: (Ljava/lang/Comparable<-LUInt;>;)V
|
||||
|
||||
// method: Test::withListOfInlineClassArgument
|
||||
// jvm signature: (Ljava/util/List;)V
|
||||
// generic signature: (Ljava/util/List<+Ljava/util/List<LUInt;>;>;)V
|
||||
|
||||
// method: Test::withInnerGenericInlineClass
|
||||
// method: Test::withComparableOfInlineClassArgument
|
||||
// jvm signature: (Ljava/lang/Comparable;)V
|
||||
// generic signature: (Ljava/lang/Comparable<-Ljava/lang/Comparable<-LUInt;>;>;)V
|
||||
|
||||
// method: Test::withInnerGenericInlineClassOut
|
||||
// jvm signature: (Ljava/util/List;)V
|
||||
// generic signature: (Ljava/util/List<LAsList<Ljava/util/List<Ljava/lang/Integer;>;>;>;)V
|
||||
// generic signature: (Ljava/util/List<LAsList<Ljava/util/List<LUInt;>;>;>;)V
|
||||
|
||||
// method: Test::withInnerGenericInlineClassIn
|
||||
// jvm signature: (Ljava/lang/Comparable;)V
|
||||
// generic signature: (Ljava/lang/Comparable<-LAsCmp<Ljava/lang/Comparable<LUInt;>;>;>;)V
|
||||
+10
@@ -11553,6 +11553,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_contravariantUnderlyingType.kt")
|
||||
public void testKt26103_contravariantUnderlyingType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_contravariantUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_covariantUnderlyingType.kt")
|
||||
public void testKt26103_covariantUnderlyingType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_covariantUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_original.kt")
|
||||
public void testKt26103_original() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_original.kt");
|
||||
|
||||
+10
@@ -11553,6 +11553,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_contravariantUnderlyingType.kt")
|
||||
public void testKt26103_contravariantUnderlyingType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_contravariantUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_covariantUnderlyingType.kt")
|
||||
public void testKt26103_covariantUnderlyingType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_covariantUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_original.kt")
|
||||
public void testKt26103_original() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_original.kt");
|
||||
|
||||
+10
@@ -11553,6 +11553,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_contravariantUnderlyingType.kt")
|
||||
public void testKt26103_contravariantUnderlyingType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_contravariantUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_covariantUnderlyingType.kt")
|
||||
public void testKt26103_covariantUnderlyingType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_covariantUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_original.kt")
|
||||
public void testKt26103_original() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_original.kt");
|
||||
|
||||
@@ -107,7 +107,9 @@ class TypeMappingMode private constructor(
|
||||
if (type.isInlineClassType() && shouldUseUnderlyingType(type)) {
|
||||
val underlyingType = computeUnderlyingType(type)
|
||||
if (underlyingType != null) {
|
||||
return getOptimalModeForSignaturePart(underlyingType, isForAnnotationParameter, canBeUsedInSupertypePosition)
|
||||
return getOptimalModeForSignaturePart(
|
||||
underlyingType, isForAnnotationParameter, canBeUsedInSupertypePosition
|
||||
).dontWrapInlineClassesMode()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,4 +163,10 @@ class TypeMappingMode private constructor(
|
||||
needPrimitiveBoxing, true, isForAnnotationParameter, skipDeclarationSiteWildcards, skipDeclarationSiteWildcardsIfPossible,
|
||||
genericArgumentMode, kotlinCollectionsToJavaCollections, genericContravariantArgumentMode, genericInvariantArgumentMode
|
||||
)
|
||||
|
||||
fun dontWrapInlineClassesMode(): TypeMappingMode =
|
||||
TypeMappingMode(
|
||||
needPrimitiveBoxing, false, isForAnnotationParameter, skipDeclarationSiteWildcards, skipDeclarationSiteWildcardsIfPossible,
|
||||
genericArgumentMode, kotlinCollectionsToJavaCollections, genericContravariantArgumentMode, genericInvariantArgumentMode
|
||||
)
|
||||
}
|
||||
|
||||
+10
@@ -10123,6 +10123,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_contravariantUnderlyingType.kt")
|
||||
public void testKt26103_contravariantUnderlyingType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_contravariantUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_covariantUnderlyingType.kt")
|
||||
public void testKt26103_covariantUnderlyingType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_covariantUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_original.kt")
|
||||
public void testKt26103_original() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_original.kt");
|
||||
|
||||
+10
@@ -11178,6 +11178,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_contravariantUnderlyingType.kt")
|
||||
public void testKt26103_contravariantUnderlyingType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_contravariantUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_covariantUnderlyingType.kt")
|
||||
public void testKt26103_covariantUnderlyingType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_covariantUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26103_original.kt")
|
||||
public void testKt26103_original() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt26103_original.kt");
|
||||
|
||||
Reference in New Issue
Block a user