[FIR, IR] Fix name mangling for dynamic types
^KT-57566 Fixed
This commit is contained in:
committed by
Space Team
parent
994c2229df
commit
7abc6af124
@@ -190,6 +190,10 @@ open class FirMangleComputer(
|
||||
mangleType(tBuilder, type.lowerBound, declarationSiteSession)
|
||||
}
|
||||
|
||||
is ConeDynamicType -> {
|
||||
tBuilder.appendSignature(MangleConstant.DYNAMIC_MARK)
|
||||
}
|
||||
|
||||
is ConeFlexibleType -> {
|
||||
with(declarationSiteSession.typeContext) {
|
||||
// Need to reproduce type approximation done for flexible types in TypeTranslator.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl
|
||||
@@ -104,6 +105,9 @@ abstract class IrBasedDeclarationDescriptor<T : IrDeclaration>(val owner: T) : D
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
protected fun IrType.toIrBasedKotlinType(): KotlinType = toIrBasedKotlinType(owner.module.builtIns)
|
||||
|
||||
override fun getContainingDeclaration(): DeclarationDescriptor =
|
||||
getContainingDeclaration(owner)
|
||||
|
||||
@@ -1161,9 +1165,9 @@ private fun getContainingDeclaration(declaration: IrDeclaration): DeclarationDes
|
||||
}
|
||||
}
|
||||
|
||||
fun IrType.toIrBasedKotlinType(): KotlinType = when (this) {
|
||||
fun IrType.toIrBasedKotlinType(builtins: KotlinBuiltIns? = null): KotlinType = when (this) {
|
||||
is IrSimpleType ->
|
||||
makeKotlinType(classifier, arguments, isMarkedNullable()).let {
|
||||
makeKotlinType(classifier, arguments, isMarkedNullable(), builtins).let {
|
||||
if (classifier is IrTypeParameterSymbol && nullability == SimpleTypeNullability.DEFINITELY_NOT_NULL) {
|
||||
// avoidCheckingActualTypeNullability = true is necessary because in recursive cases `makesSenseToBeDefinitelyNotNull` triggers
|
||||
// supertype computation for a type parameter and for which bounds we need to call `toIrBasedKotlinType` again
|
||||
@@ -1172,6 +1176,7 @@ fun IrType.toIrBasedKotlinType(): KotlinType = when (this) {
|
||||
it
|
||||
}
|
||||
}
|
||||
is IrDynamicType -> kotlinType ?: builtins?.let(::createDynamicType) ?: error("Couldn't instantiate DynamicType")
|
||||
is IrErrorType -> kotlinType ?: error("Can't find KotlinType in IrErrorType: " + (this as IrType).render())
|
||||
else ->
|
||||
throw AssertionError("Unexpected type: $this = ${this.render()}")
|
||||
@@ -1180,7 +1185,8 @@ fun IrType.toIrBasedKotlinType(): KotlinType = when (this) {
|
||||
private fun makeKotlinType(
|
||||
classifier: IrClassifierSymbol,
|
||||
arguments: List<IrTypeArgument>,
|
||||
hasQuestionMark: Boolean
|
||||
hasQuestionMark: Boolean,
|
||||
builtins: KotlinBuiltIns?,
|
||||
): SimpleType =
|
||||
when (classifier) {
|
||||
is IrTypeParameterSymbol ->
|
||||
@@ -1189,7 +1195,7 @@ private fun makeKotlinType(
|
||||
val classDescriptor = classifier.toIrBasedDescriptorIfPossible()
|
||||
val kotlinTypeArguments = arguments.memoryOptimizedMapIndexed { index, it ->
|
||||
when (it) {
|
||||
is IrTypeProjection -> TypeProjectionImpl(it.variance, it.type.toIrBasedKotlinType())
|
||||
is IrTypeProjection -> TypeProjectionImpl(it.variance, it.type.toIrBasedKotlinType(builtins))
|
||||
is IrStarProjection -> StarProjectionImpl(classDescriptor.typeConstructor.parameters[index])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
// WITH_STDLIB
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun test1(d: dynamic) = d.toString()
|
||||
|
||||
fun test2(d: dynamic) = d.hashCode()
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun testArrayAccess1(d: dynamic) = d["KEY"]
|
||||
|
||||
fun testArrayAccess2(d: dynamic) = d()["KEY"]
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun testArrayAssignment(d: dynamic) {
|
||||
d["KEY"] = 1
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun testArrayAugmentedAssignment(d: dynamic) {
|
||||
d["KEY"] += "+="
|
||||
d["KEY"] -= "-="
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun testEqeq(d: dynamic) = d == 3
|
||||
fun testExclEq(d: dynamic) = d != 3
|
||||
fun testEqeqeq(d: dynamic) = d === 3
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun testAndAnd(d: dynamic) = d && d
|
||||
fun testOrOr(d: dynamic) = d || d
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun testBinaryPlus(d: dynamic) = d + 1
|
||||
fun testBinaryMinus(d: dynamic) = d - 1
|
||||
fun testMul(d: dynamic) = d * 2
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun testLess(d: dynamic) = d < 2
|
||||
fun testLessOrEqual(d: dynamic) = d <= 2
|
||||
fun testGreater(d: dynamic) = d > 2
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun test1(d: dynamic) = d.member(1, 2, 3)
|
||||
|
||||
fun test2(d: dynamic) = d?.member(1, 2, 3)
|
||||
|
||||
@@ -1,6 +1,2 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun test(d: dynamic) = d ?: "other"
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND_K1: JS_IR
|
||||
// IGNORE_BACKEND_K1: JS_IR_ES6
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun test(d: dynamic) = d!!
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun test1(d: dynamic) = d foo 123
|
||||
|
||||
fun test2(d: dynamic) = d invoke 123
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun test1(d: dynamic) = d.member
|
||||
|
||||
fun test2(d: dynamic) = d?.member
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun testMemberAssignment(d: dynamic) {
|
||||
d.m = 1
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun testAugmentedMemberAssignment(d: dynamic) {
|
||||
d.m += "+="
|
||||
d.m -= "-="
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun testUnaryMinus(d: dynamic) = -d
|
||||
fun testUnaryPlus(d: dynamic) = +d
|
||||
fun testExcl(d: dynamic) = !d
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// WITH_STDLIB
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun test1(d: dynamic) = if (d is String) d.length else -1
|
||||
|
||||
fun test2(d: dynamic) = if (d is Array<*>) d.size else -1
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
// ^ KT-57818
|
||||
|
||||
val d: dynamic = 1
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
// ^ KT-57818
|
||||
|
||||
val d1: dynamic = 1
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// MUTE_SIGNATURE_COMPARISON_K2: ANY
|
||||
// ^ KT-57566
|
||||
|
||||
fun invoke() {}
|
||||
|
||||
fun test1(a: dynamic) = a(1)
|
||||
|
||||
Reference in New Issue
Block a user