Remove unsafe cast function usages from IR modules
This commit is contained in:
committed by
Space Team
parent
1418423423
commit
fd9b19ee49
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.ir.util.isImmutable
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.ir.util.primaryConstructor
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.assertedCast
|
||||
|
||||
val IrBuilderWithScope.parent get() = scope.getLocalDeclarationParent()
|
||||
|
||||
@@ -76,9 +75,8 @@ fun IrBuilderWithScope.irReturn(value: IrExpression) =
|
||||
IrReturnImpl(
|
||||
startOffset, endOffset,
|
||||
context.irBuiltIns.nothingType,
|
||||
scope.scopeOwnerSymbol.assertedCast<IrReturnTargetSymbol> {
|
||||
"Function scope expected: ${scope.scopeOwnerSymbol.owner.render()}"
|
||||
},
|
||||
scope.scopeOwnerSymbol as? IrReturnTargetSymbol
|
||||
?: throw AssertionError("Function scope expected: ${scope.scopeOwnerSymbol.owner.render()}"),
|
||||
value
|
||||
)
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import java.util.*
|
||||
|
||||
abstract class IrBuilder(
|
||||
override val context: IrGeneratorContext,
|
||||
@@ -107,9 +105,11 @@ class IrBlockBuilder(
|
||||
|
||||
override fun doBuild(): IrContainerExpression {
|
||||
val resultType = this.resultType
|
||||
?: statements.lastOrNull().safeAs<IrExpression>()?.type
|
||||
?: context.irBuiltIns.unitType
|
||||
val irBlock = if (isTransparent) IrCompositeImpl(startOffset, endOffset, resultType, origin) else IrBlockImpl(startOffset, endOffset, resultType, origin)
|
||||
?: (statements.lastOrNull() as? IrExpression)?.type
|
||||
?: context.irBuiltIns.unitType
|
||||
val irBlock =
|
||||
if (isTransparent) IrCompositeImpl(startOffset, endOffset, resultType, origin)
|
||||
else IrBlockImpl(startOffset, endOffset, resultType, origin)
|
||||
irBlock.statements.addAll(statements)
|
||||
return irBlock
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.model.CaptureStatus
|
||||
import org.jetbrains.kotlin.types.model.CapturedTypeConstructorMarker
|
||||
import org.jetbrains.kotlin.types.model.CapturedTypeMarker
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
abstract class IrTypeBase(val kotlinType: KotlinType?) : IrType(), IrTypeProjection {
|
||||
override val type: IrType get() = this
|
||||
@@ -43,8 +42,7 @@ class IrDynamicTypeImpl(
|
||||
}
|
||||
|
||||
val IrType.originalKotlinType: KotlinType?
|
||||
get() = safeAs<IrTypeBase>()?.kotlinType
|
||||
|
||||
get() = (this as? IrTypeBase)?.kotlinType
|
||||
|
||||
object IrStarProjectionImpl : IrStarProjection {
|
||||
override fun equals(other: Any?): Boolean = this === other
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.resolve.isValueClass
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
abstract class DeclarationStubGenerator(
|
||||
@@ -89,7 +88,7 @@ abstract class DeclarationStubGenerator(
|
||||
}
|
||||
|
||||
fun generateOrGetFacadeClass(descriptor: DeclarationDescriptor): IrClass? {
|
||||
val directMember = descriptor.safeAs<PropertyAccessorDescriptor>()?.correspondingProperty ?: descriptor
|
||||
val directMember = (descriptor as? PropertyAccessorDescriptor)?.correspondingProperty ?: descriptor
|
||||
val packageFragment = directMember.containingDeclaration as? PackageFragmentDescriptor ?: return null
|
||||
val containerSource = extensions.getContainerSource(directMember) ?: return null
|
||||
return facadeClassMap.getOrPut(containerSource) {
|
||||
|
||||
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.ir.util
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
val IrDeclaration.isReal: Boolean get() = !isFakeOverride
|
||||
|
||||
@@ -115,7 +114,7 @@ fun <S : IrSymbol, T : IrOverridableDeclaration<S>> T.resolveFakeOverrideOrNull(
|
||||
collectRealOverrides(toSkip, { it.modality == Modality.ABSTRACT })
|
||||
.let { realOverrides ->
|
||||
// Kotlin forbids conflicts between overrides, but they may trickle down from Java.
|
||||
realOverrides.singleOrNull { it.parent.safeAs<IrClass>()?.isInterface != true }
|
||||
realOverrides.singleOrNull { (it.parent as? IrClass)?.isInterface != true }
|
||||
// TODO: We take firstOrNull instead of singleOrNull here because of KT-36188.
|
||||
?: realOverrides.firstOrNull()
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import java.io.StringWriter
|
||||
|
||||
/**
|
||||
@@ -342,10 +341,8 @@ fun IrFunction.isFakeOverriddenFromAny(): Boolean {
|
||||
|
||||
fun IrCall.isSuperToAny() = superQualifierSymbol?.let { this.symbol.owner.isFakeOverriddenFromAny() } ?: false
|
||||
|
||||
|
||||
fun IrDeclaration.hasInterfaceParent() =
|
||||
parent.safeAs<IrClass>()?.isInterface == true
|
||||
|
||||
(parent as? IrClass)?.isInterface == true
|
||||
|
||||
fun IrPossiblyExternalDeclaration.isEffectivelyExternal(): Boolean =
|
||||
this.isExternal
|
||||
|
||||
Reference in New Issue
Block a user