diff --git a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt index 0f7a72c8f86..de873d3e92f 100644 --- a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt +++ b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource @@ -51,9 +52,8 @@ class IrConstructorImpl( override lateinit var parent: IrDeclarationParent override var annotations: List = emptyList() - @Suppress("DEPRECATION") override var returnType: IrType = returnType - get() = if (field === org.jetbrains.kotlin.ir.types.impl.IrUninitializedType) { + get() = if (field === IrUninitializedType) { error("Return type is not initialized") } else { field diff --git a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt index f3fd898ec5f..c991a15867d 100644 --- a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt +++ b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource @@ -41,9 +42,8 @@ abstract class IrFunctionCommonImpl( override lateinit var parent: IrDeclarationParent override var annotations: List = emptyList() - @Suppress("DEPRECATION") override var returnType: IrType = returnType - get() = if (field === org.jetbrains.kotlin.ir.types.impl.IrUninitializedType) { + get() = if (field === IrUninitializedType) { error("Return type is not initialized") } else { field diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt index 4c50c67e73d..82a5abb4600 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource @@ -70,10 +71,9 @@ internal class PersistentIrConstructor( } } - @Suppress("DEPRECATION") override var returnType: IrType get() = returnTypeField.let { - if (it !== org.jetbrains.kotlin.ir.types.impl.IrUninitializedType) it else error("Return type is not initialized") + if (it !== IrUninitializedType) it else error("Return type is not initialized") } set(c) { returnTypeField = c diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt index b2570b021d7..9061ec6c4b5 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource @@ -60,10 +61,9 @@ internal abstract class PersistentIrFunctionCommon( } } - @Suppress("DEPRECATION") final override var returnType: IrType get() = returnTypeField.let { - if (it !== org.jetbrains.kotlin.ir.types.impl.IrUninitializedType) it else error("Return type is not initialized") + if (it !== IrUninitializedType) it else error("Return type is not initialized") } set(c) { returnTypeField = c diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt index 7fa13e944a9..1f8259e667a 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt @@ -46,7 +46,16 @@ object IrStarProjectionImpl : IrStarProjection { override fun hashCode(): Int = System.identityHashCode(this) } -@Deprecated("Hack to temporary cover late type initialization") +/** + * An instance which should be used when creating an IR element whose type cannot be determined at the moment of creation. + * + * Example: when translating generic functions in psi2ir, we're creating an IrFunction first, then adding IrTypeParameter instances to it, + * and only then translating the function's return type with respect to those created type parameters. + * + * Instead of using this special instance, we could just make IrFunction/IrConstructor constructors allow to accept no return type, + * however this could lead to a situation where we forget to set return type sometimes. This would result in crashes at unexpected moments, + * especially in Kotlin/JS where function return types are not present in the resulting binary files. + */ object IrUninitializedType : IrType { override val annotations: List = emptyList()