Fix mapping for inline classes when JvmSuppressWildcards mode is using
#KT-28097 Fixed
This commit is contained in:
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.firstOverridden
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor
|
||||
import org.jetbrains.kotlin.resolve.isInlineClassType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.getEffectiveVariance
|
||||
@@ -78,12 +79,19 @@ private val METHODS_WITH_DECLARATION_SITE_WILDCARDS = setOf(
|
||||
fun TypeMappingMode.updateArgumentModeFromAnnotations(type: KotlinType): TypeMappingMode {
|
||||
type.suppressWildcardsMode()?.let {
|
||||
return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode(
|
||||
skipDeclarationSiteWildcards = it, isForAnnotationParameter = isForAnnotationParameter)
|
||||
skipDeclarationSiteWildcards = it,
|
||||
isForAnnotationParameter = isForAnnotationParameter,
|
||||
needInlineClassWrapping = needInlineClassWrapping
|
||||
)
|
||||
}
|
||||
|
||||
if (type.annotations.hasAnnotation(JVM_WILDCARD_ANNOTATION_FQ_NAME)) {
|
||||
return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode(
|
||||
skipDeclarationSiteWildcards = false, isForAnnotationParameter = isForAnnotationParameter, fallbackMode = this)
|
||||
skipDeclarationSiteWildcards = false,
|
||||
isForAnnotationParameter = isForAnnotationParameter,
|
||||
fallbackMode = this,
|
||||
needInlineClassWrapping = needInlineClassWrapping
|
||||
)
|
||||
}
|
||||
|
||||
return this
|
||||
@@ -97,7 +105,10 @@ internal fun extractTypeMappingModeFromAnnotation(
|
||||
(outerType.suppressWildcardsMode() ?: callableDescriptor?.suppressWildcardsMode())?.let {
|
||||
if (outerType.arguments.isNotEmpty())
|
||||
TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode(
|
||||
skipDeclarationSiteWildcards = it, isForAnnotationParameter = isForAnnotationParameter)
|
||||
skipDeclarationSiteWildcards = it,
|
||||
isForAnnotationParameter = isForAnnotationParameter,
|
||||
needInlineClassWrapping = !outerType.isInlineClassType()
|
||||
)
|
||||
else
|
||||
TypeMappingMode.DEFAULT
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JS, JS_IR
|
||||
|
||||
class Foo<T>(val x: Int)
|
||||
|
||||
@JvmSuppressWildcards
|
||||
class Bar {
|
||||
fun run(f: (Foo<String>) -> Foo<Long>): Foo<Long> {
|
||||
return f(Foo<String>(42))
|
||||
}
|
||||
|
||||
fun invokeFun(): Foo<Long> {
|
||||
return run { f ->
|
||||
Foo<Long>(f.x + 1)
|
||||
}
|
||||
}
|
||||
|
||||
fun nullableFoo(f: Foo<Long>?): Foo<Long> = f!!
|
||||
|
||||
fun listOfFoo(f: List<Foo<String>>): Foo<String> = f[0]
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = Bar()
|
||||
if(b.invokeFun().x != 43) return "Fail 1"
|
||||
|
||||
if (b.nullableFoo(Foo<Long>(1)).x != 1) return "Fail 2"
|
||||
|
||||
val f: Foo<Long>? = Foo<Long>(2)
|
||||
if (b.nullableFoo(f).x != 2) return "Fail 3"
|
||||
|
||||
val ls = listOf(Foo<String>(3))
|
||||
if (b.listOfFoo(ls).x != 3) return "Fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -12070,6 +12070,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt27706.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
|
||||
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||
|
||||
+5
@@ -12070,6 +12070,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt27706.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
|
||||
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||
|
||||
+5
@@ -12075,6 +12075,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt27706.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
|
||||
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||
|
||||
@@ -143,11 +143,13 @@ class TypeMappingMode private constructor(
|
||||
fun createWithConstantDeclarationSiteWildcardsMode(
|
||||
skipDeclarationSiteWildcards: Boolean,
|
||||
isForAnnotationParameter: Boolean,
|
||||
needInlineClassWrapping: Boolean,
|
||||
fallbackMode: TypeMappingMode? = null
|
||||
) = TypeMappingMode(
|
||||
isForAnnotationParameter = isForAnnotationParameter,
|
||||
skipDeclarationSiteWildcards = skipDeclarationSiteWildcards,
|
||||
genericArgumentMode = fallbackMode
|
||||
genericArgumentMode = fallbackMode,
|
||||
needInlineClassWrapping = needInlineClassWrapping
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -10470,6 +10470,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt27706.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
|
||||
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||
|
||||
+5
@@ -11515,6 +11515,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt27706.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
|
||||
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||
|
||||
Reference in New Issue
Block a user