diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ExpressionTypeProvider.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ExpressionTypeProvider.kt index ddfcc0c3052..7a13e711cd5 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ExpressionTypeProvider.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ExpressionTypeProvider.kt @@ -300,10 +300,9 @@ class KtFe10ExpressionTypeProvider( } override fun isDefinitelyNotNull(expression: KtExpression): Boolean { - val ktExpression = expression as? KtExpression ?: return false - val bindingContext = analysisContext.analyze(ktExpression) + val bindingContext = analysisContext.analyze(expression) - val smartCasts = bindingContext[BindingContext.SMARTCAST, ktExpression] + val smartCasts = bindingContext[BindingContext.SMARTCAST, expression] if (smartCasts is MultipleSmartCasts) { if (smartCasts.map.values.all { !it.isMarkedNullable }) { diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/pointers/KtFirMemberSymbolPointer.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/pointers/KtFirMemberSymbolPointer.kt index 160e7503b4f..7412b2408e1 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/pointers/KtFirMemberSymbolPointer.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/pointers/KtFirMemberSymbolPointer.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer import org.jetbrains.kotlin.analysis.utils.errors.requireIsInstance import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope @@ -42,7 +41,7 @@ internal abstract class KtFirMemberSymbolPointer( val firSession = useSiteSession val scopeSession = getScopeSessionFor(firSession) return if (isStatic) { - val firClass = owner.fir as? FirClass ?: return null + val firClass = owner.fir firClass.scopeProvider.getStaticMemberScopeForCallables(firClass, firSession, scopeSession) } else { owner.unsubstitutedScope( diff --git a/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/components/symbolDeclarationRenderer/AbstractRendererTest.kt b/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/components/symbolDeclarationRenderer/AbstractRendererTest.kt index 2c779ba6ce9..42908cc579f 100644 --- a/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/components/symbolDeclarationRenderer/AbstractRendererTest.kt +++ b/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/components/symbolDeclarationRenderer/AbstractRendererTest.kt @@ -36,8 +36,7 @@ abstract class AbstractRendererTest : AbstractAnalysisApiSingleFileTest() { buildString { ktFile.declarations.forEach { declaration -> analyseForTest(declaration) { - val symbol = declaration.getSymbol() as? KtDeclarationSymbol ?: return@analyseForTest - append(symbol.render(renderer)) + append(declaration.getSymbol().render(renderer)) appendLine() appendLine() } diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/stubBased/deserialization/StubBasedFirTypeDeserializer.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/stubBased/deserialization/StubBasedFirTypeDeserializer.kt index 37704117cb5..5228ebddace 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/stubBased/deserialization/StubBasedFirTypeDeserializer.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/stubBased/deserialization/StubBasedFirTypeDeserializer.kt @@ -108,7 +108,7 @@ internal class StubBasedFirTypeDeserializer( val annotations = annotationDeserializer.loadAnnotations(typeReference).toMutableList() val parent = (typeReference.stub ?: loadStubByElement(typeReference))?.parentStub if (parent is KotlinParameterStubImpl) { - (parent as? KotlinParameterStubImpl)?.functionTypeParameterName?.let { paramName -> + parent.functionTypeParameterName?.let { paramName -> annotations += buildAnnotation { annotationTypeRef = buildResolvedTypeRef { type = StandardNames.FqNames.parameterNameClassId.toLookupTag() diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiInlineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiInlineCodegen.kt index 158e8386660..5d8fcd25bde 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiInlineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiInlineCodegen.kt @@ -194,8 +194,7 @@ class PsiInlineCodegen( override fun reorderArgumentsIfNeeded(actualArgsWithDeclIndex: List, valueParameterTypes: List) = Unit override fun isInlinedToInlineFunInKotlinRuntime(): Boolean { - val codegen = this.codegen as? ExpressionCodegen ?: return false - val caller = codegen.context.functionDescriptor + val caller = this.codegen.context.functionDescriptor if (!caller.isInline) return false val callerPackage = DescriptorUtils.getParentOfType(caller, PackageFragmentDescriptor::class.java) ?: return false return callerPackage.fqName.asString().startsWith("kotlin.") diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeIntrinsicRangeValue.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeIntrinsicRangeValue.kt index e44f0109117..7325fe73e89 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeIntrinsicRangeValue.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeIntrinsicRangeValue.kt @@ -65,8 +65,7 @@ abstract class PrimitiveNumberRangeIntrinsicRangeValue( return when (comparisonGenerator.comparedType) { Type.DOUBLE_TYPE, Type.FLOAT_TYPE -> { - val rangeLiteral = getBoundedValue(codegen) as? BoundedValue - ?: throw AssertionError("Floating point intrinsic range value should be a range literal") + val rangeLiteral = getBoundedValue(codegen) InFloatingPointRangeLiteralExpressionGenerator(operatorReference, rangeLiteral, comparisonGenerator, codegen.frameMap) } else -> diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/pipeline/compilerPipeline.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/pipeline/compilerPipeline.kt index 4ad3ed0cd7c..b4a93ffbfc3 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/pipeline/compilerPipeline.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/pipeline/compilerPipeline.kt @@ -274,9 +274,7 @@ fun compileModuleToAnalyzedFir( incrementalExcludesScope )?.also { librariesScope -= it } - val extensionRegistrars = (projectEnvironment as? VfsBasedProjectEnvironment) - ?.let { FirExtensionRegistrar.getInstances(it.project) } - ?: emptyList() + val extensionRegistrars = FirExtensionRegistrar.getInstances(projectEnvironment.project) val allSources = mutableListOf().apply { addAll(input.groupedSources.commonSources) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt index 0de775706db..f15eb2c8729 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt @@ -190,22 +190,20 @@ fun checkUpperBoundViolated( if (argumentType != null && argumentSource != null) { if (!isIgnoreTypeParameters || (argumentType.typeArguments.isEmpty() && argumentType !is ConeTypeParameterType)) { val intersection = - typeSystemContext.intersectTypes(typeParameters[index].resolvedBounds.map { it.coneType }) as? ConeKotlinType - if (intersection != null) { - val upperBound = substitutor.substituteOrSelf(intersection) - if (!AbstractTypeChecker.isSubtypeOf( - typeSystemContext, - argumentType, - upperBound, - stubTypesEqualToAnything = true - ) - ) { - val factory = when { - isReportExpansionError && argumentTypeRef == null -> FirErrors.UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION - else -> FirErrors.UPPER_BOUND_VIOLATED - } - reporter.reportOn(argumentSource, factory, upperBound, argumentType.type, context) + typeSystemContext.intersectTypes(typeParameters[index].resolvedBounds.map { it.coneType }) + val upperBound = substitutor.substituteOrSelf(intersection) + if (!AbstractTypeChecker.isSubtypeOf( + typeSystemContext, + argumentType, + upperBound, + stubTypesEqualToAnything = true + ) + ) { + val factory = when { + isReportExpansionError && argumentTypeRef == null -> FirErrors.UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION + else -> FirErrors.UPPER_BOUND_VIOLATED } + reporter.reportOn(argumentSource, factory, upperBound, argumentType.type, context) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTopLevelPropertiesChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTopLevelPropertiesChecker.kt index 9441f933927..466118c1959 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTopLevelPropertiesChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTopLevelPropertiesChecker.kt @@ -27,7 +27,6 @@ import org.jetbrains.kotlin.fir.declarations.utils.* import org.jetbrains.kotlin.fir.resolve.dfa.cfg.NormalPath import org.jetbrains.kotlin.fir.resolve.dfa.controlFlowGraph import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeLocalVariableNoTypeOrInitializer -import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.types.FirErrorTypeRef import org.jetbrains.kotlin.lexer.KtTokens @@ -58,7 +57,7 @@ object FirTopLevelPropertiesChecker : FirFileChecker() { } val propertySymbols = topLevelProperties.mapNotNullTo(mutableSetOf()) { declaration -> - (declaration.symbol as? FirPropertySymbol)?.takeIf { it.requiresInitialization(isForInitialization = true) } + declaration.symbol.takeIf { it.requiresInitialization(isForInitialization = true) } } if (propertySymbols.isEmpty()) return null diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirValueClassDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirValueClassDeclarationChecker.kt index 8dd465120af..0cf983e71a8 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirValueClassDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirValueClassDeclarationChecker.kt @@ -284,7 +284,7 @@ object FirValueClassDeclarationChecker : FirRegularClassChecker() { return lookupSuperTypes(this, lookupInterfaces = true, deep = true, session, substituteTypes = false).any { superType -> // Note: We check just classId here, so type substitution isn't needed ^ (we aren't interested in type arguments) - (superType as? ConeClassLikeType)?.fullyExpandedType(session)?.lookupTag?.classId?.isCloneableId() == true + superType.fullyExpandedType(session).lookupTag.classId.isCloneableId() } } diff --git a/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt b/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt index ecc392b2db0..7fc13190e68 100644 --- a/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt +++ b/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt @@ -136,8 +136,8 @@ class FirJvmTypeMapper(val session: FirSession) : FirSessionComponent { return when (val symbol = lookupTag.toSymbol(session)) { is FirRegularClassSymbol -> buildPossiblyInnerType(symbol, 0) is FirTypeAliasSymbol -> { - val expandedType = fullyExpandedType(session) as? ConeClassLikeType - val classSymbol = expandedType?.lookupTag?.toSymbol(session) as? FirRegularClassSymbol + val expandedType = fullyExpandedType(session) + val classSymbol = expandedType.lookupTag.toSymbol(session) as? FirRegularClassSymbol classSymbol?.let { expandedType.buildPossiblyInnerType(it, 0) } } else -> null diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt index f7c11423846..29d74671f50 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt @@ -369,13 +369,13 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I subClassLookupTag: ConeClassLikeLookupTag, firField: FirField, ): D? { - val callable = this.fir as? D ?: return null + val callable = this.fir val delegatedWrapperData = callable.delegatedWrapperData ?: return null if (delegatedWrapperData.containingClass != subClassLookupTag) return null if (delegatedWrapperData.delegateField != firField) return null - val wrapped = delegatedWrapperData.wrapped as? D ?: return null + val wrapped = delegatedWrapperData.wrapped @Suppress("UNCHECKED_CAST") val wrappedSymbol = wrapped.symbol as? S ?: return null diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt index ea49ff4b531..129fb979556 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt @@ -442,8 +442,7 @@ class FakeOverrideGenerator( overridden.containingClassLookupTag()?.toSymbol(session)?.fir as? FirClass ?: return emptyList() val overriddenContainingIrClass = - declarationStorage.classifierStorage.getOrCreateIrClass(overriddenContainingClass.symbol).symbol.owner as? IrClass - ?: return emptyList() + declarationStorage.classifierStorage.getOrCreateIrClass(overriddenContainingClass.symbol).symbol.owner return superClasses.mapNotNull { superClass -> if (superClass == overriddenContainingIrClass || diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassStaticUseSiteScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassStaticUseSiteScope.kt index 045a1203758..69c1fb13efb 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassStaticUseSiteScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassStaticUseSiteScope.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.utils.addIfNotNull class JavaClassStaticUseSiteScope internal constructor( session: FirSession, @@ -34,7 +33,7 @@ class JavaClassStaticUseSiteScope internal constructor( private fun computeFunctions(name: Name): MutableList { val superClassSymbols = mutableListOf() superClassScope.processFunctionsByName(name) { - superClassSymbols.addIfNotNull(it as? FirNamedFunctionSymbol) + superClassSymbols.add(it) } val result = mutableListOf() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt index eeade77e653..7c370d0183d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.fir.resolve.inference.model.ConeReceiverConstraintPo import org.jetbrains.kotlin.fir.resolve.inference.preprocessCallableReference import org.jetbrains.kotlin.fir.resolve.inference.preprocessLambdaArgument import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator -import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType import org.jetbrains.kotlin.fir.resolve.transformers.ensureResolvedTypeDeclaration import org.jetbrains.kotlin.fir.returnExpressions import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag @@ -362,9 +361,7 @@ private fun checkApplicabilityForArgumentType( return ConeTypeIntersector.intersectTypes(context.session.typeContext, constraintTypes) } - val originalTypeParameter = - (lookupTag as? ConeTypeVariableTypeConstructor)?.originalTypeParameter as? ConeTypeParameterLookupTag - + val originalTypeParameter = lookupTag.originalTypeParameter as? ConeTypeParameterLookupTag if (originalTypeParameter != null) return ConeTypeParameterTypeImpl(originalTypeParameter, type.isNullable, type.attributes) } else if (type is ConeIntegerLiteralType) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/SuperCalls.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/SuperCalls.kt index 83a215666c0..5e67ffe3748 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/SuperCalls.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/SuperCalls.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.isClass import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirResolvePhase -import org.jetbrains.kotlin.fir.declarations.FirVariable import org.jetbrains.kotlin.fir.declarations.utils.modality import org.jetbrains.kotlin.fir.dispatchReceiverClassLookupTagOrNull import org.jetbrains.kotlin.fir.expressions.FirFunctionCall @@ -27,7 +26,6 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.utils.SmartList -import org.jetbrains.kotlin.utils.addIfNotNull fun BodyResolveComponents.findTypesForSuperCandidates( superTypeRefs: List, @@ -144,7 +142,7 @@ private fun BodyResolveComponents.getPropertyMembers(type: ConeKotlinType, name: scopeSession = scopeSession, callableCopyTypeCalculator = CallableCopyTypeCalculator.DoNothing, requiredMembersPhase = FirResolvePhase.STATUS, - )?.processPropertiesByName(name) { addIfNotNull(it.fir as? FirVariable) } + )?.processPropertiesByName(name) { add(it.fir) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt index f3b72ca91ef..4433cdcdd60 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt @@ -421,7 +421,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c processBlocks = true ) { candidate -> candidate.postponedAtoms.forEach { atom -> - notAnalyzedArguments.addIfNotNull((atom as? PostponedResolvedAtom)?.takeUnless { it.analyzed }) + notAnalyzedArguments.addIfNotNull(atom.takeUnless { it.analyzed }) } } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 2b668ab5c0d..b4ab1aa1f93 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -1027,7 +1027,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT ), ) - (result as? FirVariableAssignment)?.let { dataFlowAnalyzer.exitVariableAssignment(it) } + dataFlowAnalyzer.exitVariableAssignment(result) return result } diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/declarations/ImplicitReceiverUtils.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/declarations/ImplicitReceiverUtils.kt index fdcff7f9002..8f72fb53183 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/declarations/ImplicitReceiverUtils.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/declarations/ImplicitReceiverUtils.kt @@ -22,10 +22,8 @@ import org.jetbrains.kotlin.fir.types.ConeErrorType import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeStubType import org.jetbrains.kotlin.fir.types.coneType -import org.jetbrains.kotlin.fir.utils.exceptions.withConeTypeEntry import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.utils.addIfNotNull -import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment fun SessionHolder.collectImplicitReceivers( type: ConeKotlinType?, @@ -87,7 +85,7 @@ fun SessionHolder.collectTowerDataElementsForClass(owner: FirClass, defaultType: ?.asTowerDataElementForStaticScope(staticScopeOwnerSymbol = superClass.symbol) ?.let(superClassesStaticsAndCompanionReceivers::add) - (superClass as? FirRegularClass)?.companionObjectSymbol?.let { + superClass.companionObjectSymbol?.let { val superCompanionReceiver = ImplicitDispatchReceiverValue( it, session, scopeSession ) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NullableVarargArgumentCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NullableVarargArgumentCallChecker.kt index 2f4a6c253ff..7377f9a9f74 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NullableVarargArgumentCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NullableVarargArgumentCallChecker.kt @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl import org.jetbrains.kotlin.resolve.calls.tower.SimplePSIKotlinCallArgument -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.types.FlexibleType import org.jetbrains.kotlin.types.TypeUtils @@ -32,7 +31,7 @@ object NullableVarargArgumentCallChecker : CallChecker { if (!arg.isSpread || arg !is SimplePSIKotlinCallArgument) continue val spreadElement = arg.valueArgument.getSpreadElement() ?: continue - val receiver = (arg.receiver as? ReceiverValueWithSmartCastInfo) ?: continue + val receiver = arg.receiver val type = if (receiver.stableType.constructor is TypeVariableTypeConstructor) { context.trace.bindingContext[EXPRESSION_TYPE_INFO, arg.valueArgument.getArgumentExpression()]?.type diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ValueClassDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ValueClassDeclarationChecker.kt index 82b7ef58b6e..0227d09d104 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ValueClassDeclarationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ValueClassDeclarationChecker.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.resolve.checkers -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.* @@ -89,7 +88,7 @@ object ValueClassDeclarationChecker : DeclarationChecker { } var baseParametersOk = true - val baseParameterTypes = (descriptor as? ClassDescriptor)?.defaultType?.substitutedUnderlyingTypes() ?: emptyList() + val baseParameterTypes = descriptor.defaultType.substitutedUnderlyingTypes() for ((baseParameter, baseParameterType) in primaryConstructor.valueParameters zip baseParameterTypes) { if (!isParameterAcceptableForInlineClass(baseParameter)) { diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalFirJvmCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalFirJvmCompilerRunner.kt index c8a9731b137..8a58d5e3b9a 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalFirJvmCompilerRunner.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalFirJvmCompilerRunner.kt @@ -282,8 +282,7 @@ open class IncrementalFirJvmCompilerRunner( allowNonCachedDeclarations = false, useIrFakeOverrideBuilder = configuration.getBoolean(CommonConfigurationKeys.USE_IR_FAKE_OVERRIDE_BUILDER), ) - val irGenerationExtensions = - (projectEnvironment as? VfsBasedProjectEnvironment)?.project?.let { IrGenerationExtension.getInstances(it) }.orEmpty() + val irGenerationExtensions = projectEnvironment.project.let { IrGenerationExtension.getInstances(it) } val (irModuleFragment, components, pluginContext, irActualizedResult) = cycleResult.convertToIrAndActualizeForJvm( extensions, fir2IrConfiguration, irGenerationExtensions, ) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/FlattenStringConcatenationLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/FlattenStringConcatenationLowering.kt index 8545436e98d..6c020342ddf 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/FlattenStringConcatenationLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/FlattenStringConcatenationLowering.kt @@ -120,9 +120,7 @@ class FlattenStringConcatenationLowering(val context: CommonBackendContext) : Fi if (superQualifierSymbol != null) return false - val function = symbol.owner as? IrSimpleFunction - ?: return false - + val function = symbol.owner return function.isToString || function.isNullableToString } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt index ba840ed711c..f2e79e21177 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt @@ -137,7 +137,7 @@ fun translateFunction(declaration: IrFunction, name: JsName?, context: JsGenerat private fun isFunctionTypeInvoke(receiver: JsExpression?, call: IrCall): Boolean { if (receiver == null || receiver is JsThisRef) return false - val simpleFunction = call.symbol.owner as? IrSimpleFunction ?: return false + val simpleFunction = call.symbol.owner val receiverType = simpleFunction.dispatchReceiverParameter?.type ?: return false if (call.origin === JsStatementOrigins.EXPLICIT_INVOKE) return false diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/EnumExternalEntriesLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/EnumExternalEntriesLowering.kt index 97739c7494d..12d76249a62 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/EnumExternalEntriesLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/EnumExternalEntriesLowering.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.ir.builders.irExprBody import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrField import org.jetbrains.kotlin.ir.declarations.IrFile -import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl @@ -101,8 +100,8 @@ class EnumExternalEntriesLowering(private val context: JvmBackendContext) : File } override fun visitCall(expression: IrCall): IrExpression { - val owner = expression.symbol.owner as? IrSimpleFunction - val parentClass = owner?.parent as? IrClass ?: return super.visitCall(expression) + val owner = expression.symbol.owner + val parentClass = owner.parent as? IrClass ?: return super.visitCall(expression) val shouldBeLowered = owner.name == SpecialNames.ENUM_GET_ENTRIES && parentClass.isEnumClassWhichRequiresExternalEntries() if (!shouldBeLowered) return super.visitCall(expression) val field = state!!.getEntriesFieldForEnum(parentClass) diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOptimizationLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOptimizationLowering.kt index 1f7986e7ec3..fd4401e2a7b 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOptimizationLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOptimizationLowering.kt @@ -114,7 +114,7 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass } private fun optimizePropertyAccess(expression: IrCall, data: IrDeclaration?): IrExpression { - val accessor = expression.symbol.owner as? IrSimpleFunction ?: return expression + val accessor = expression.symbol.owner if (accessor.modality != Modality.FINAL || accessor.isExternal) return expression val property = accessor.correspondingPropertySymbol?.owner ?: return expression if (property.isLateinit) return expression @@ -357,9 +357,8 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass when (statement) { is IrDoWhileLoop -> { // Expecting counter loop - val doWhileLoop = statement as? IrDoWhileLoop ?: return null - if (doWhileLoop.origin != JvmLoweredStatementOrigin.DO_WHILE_COUNTER_LOOP) return null - val doWhileLoopBody = doWhileLoop.body as? IrComposite ?: return null + if (statement.origin != JvmLoweredStatementOrigin.DO_WHILE_COUNTER_LOOP) return null + val doWhileLoopBody = statement.body as? IrComposite ?: return null if (doWhileLoopBody.origin != IrStatementOrigin.FOR_LOOP_INNER_WHILE) return null val iterationInitialization = doWhileLoopBody.statements[0] as? IrComposite ?: return null val loopVariableIndex = iterationInitialization.statements.indexOfFirst { it.isLoopVariable() } diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt index 1a82aa68b92..c66ae4e4546 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt @@ -51,7 +51,7 @@ class JvmPropertiesLowering(private val backendContext: JvmBackendContext) : IrE } override fun visitCall(expression: IrCall): IrExpression { - val simpleFunction = (expression.symbol.owner as? IrSimpleFunction) ?: return super.visitCall(expression) + val simpleFunction = expression.symbol.owner val property = simpleFunction.correspondingPropertySymbol?.owner ?: return super.visitCall(expression) expression.transformChildrenVoid() diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/ResolveInlineCalls.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/ResolveInlineCalls.kt index 376351fcf47..d7eee4ab811 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/ResolveInlineCalls.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/ResolveInlineCalls.kt @@ -39,7 +39,7 @@ class ResolveInlineCalls(val context: JvmBackendContext) : IrElementVisitorVoid, expression.acceptChildren(this, null) if (!expression.symbol.owner.isInlineFunctionCall(context)) return - val maybeFakeOverrideOfMultiFileBridge = expression.symbol.owner as? IrSimpleFunction ?: return + val maybeFakeOverrideOfMultiFileBridge = expression.symbol.owner val resolved = maybeFakeOverrideOfMultiFileBridge.resolveMultiFileFacadeMember() ?: maybeFakeOverrideOfMultiFileBridge.resolveFakeOverride() ?: return diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/GenericReturnTypeLowering.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/GenericReturnTypeLowering.kt index b384b05a8db..50bc9c1694a 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/GenericReturnTypeLowering.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/GenericReturnTypeLowering.kt @@ -8,20 +8,17 @@ package org.jetbrains.kotlin.backend.wasm.lower import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext import org.jetbrains.kotlin.backend.common.lower.createIrBuilder -import org.jetbrains.kotlin.backend.common.lower.irComposite import org.jetbrains.kotlin.backend.wasm.WasmBackendContext import org.jetbrains.kotlin.ir.backend.js.utils.erasedUpperBound import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget import org.jetbrains.kotlin.ir.builders.irImplicitCast import org.jetbrains.kotlin.ir.declarations.IrFile -import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.util.defaultType import org.jetbrains.kotlin.ir.util.irCall -import org.jetbrains.kotlin.ir.util.isTypeParameter import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid /** @@ -48,8 +45,7 @@ class GenericReturnTypeLowering(val context: WasmBackendContext) : FileLoweringP } private fun transformGenericCall(call: IrCall, scopeOwnerSymbol: IrSymbol): IrExpression { - val function: IrSimpleFunction = - call.symbol.owner as? IrSimpleFunction ?: return call + val function = call.symbol.owner val erasedReturnType: IrType = function.realOverrideTarget.returnType.eraseUpperBoundType() diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/preprocessor/IrInterpreterConstGetterPreprocessor.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/preprocessor/IrInterpreterConstGetterPreprocessor.kt index a5562a3789b..2874f6450b6 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/preprocessor/IrInterpreterConstGetterPreprocessor.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/preprocessor/IrInterpreterConstGetterPreprocessor.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrField import org.jetbrains.kotlin.ir.declarations.IrFunction -import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.IrCompositeImpl import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl @@ -25,8 +24,7 @@ class IrInterpreterConstGetterPreprocessor : IrInterpreterPreprocessor { } override fun visitCall(expression: IrCall, data: IrInterpreterPreprocessorData): IrElement { - val function = (expression.symbol.owner as? IrSimpleFunction) ?: return super.visitCall(expression, data) - val field = function.correspondingPropertySymbol?.owner?.backingField ?: return super.visitCall(expression, data) + val field = expression.symbol.owner.correspondingPropertySymbol?.owner?.backingField ?: return super.visitCall(expression, data) return expression.lowerConstRead(field, data) ?: super.visitCall(expression, data) } diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/transformer/IrConstOnlyNecessaryTransformer.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/transformer/IrConstOnlyNecessaryTransformer.kt index 5b495580ecc..510a203e4c7 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/transformer/IrConstOnlyNecessaryTransformer.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/transformer/IrConstOnlyNecessaryTransformer.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.declarations.IrField import org.jetbrains.kotlin.ir.declarations.IrFile -import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.interpreter.IrInterpreter import org.jetbrains.kotlin.ir.interpreter.checker.EvaluationMode @@ -35,7 +34,7 @@ internal class IrConstOnlyNecessaryTransformer( interpreter, irFile, mode, checker, evaluatedConstTracker, inlineConstTracker, onWarning, onError, suppressExceptions ) { override fun visitCall(expression: IrCall, data: Data): IrElement { - val isConstGetter = (expression.symbol.owner as? IrSimpleFunction)?.correspondingPropertySymbol?.owner?.isConst == true + val isConstGetter = expression.symbol.owner.correspondingPropertySymbol?.owner?.isConst == true if (!data.inAnnotation && !isConstGetter) { expression.transformChildren(this, data) return expression diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt index 3b0bb1e7863..cd32df41caf 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt @@ -17,9 +17,9 @@ import org.jetbrains.kotlin.ir.builders.irImplicitCast import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* -import org.jetbrains.kotlin.ir.overrides.IrUnimplementedOverridesStrategy import org.jetbrains.kotlin.ir.overrides.FakeOverrideBuilderStrategy import org.jetbrains.kotlin.ir.overrides.IrFakeOverrideBuilder +import org.jetbrains.kotlin.ir.overrides.IrUnimplementedOverridesStrategy import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl @@ -28,11 +28,7 @@ import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection import org.jetbrains.kotlin.ir.visitors.IrElementVisitor -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.name.SpecialNames -import org.jetbrains.kotlin.name.StandardClassIds +import org.jetbrains.kotlin.name.* import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.utils.* import java.io.StringWriter @@ -842,7 +838,7 @@ fun IrClass.addSimpleDelegatingConstructor( ) } -val IrCall.isSuspend get() = (symbol.owner as? IrSimpleFunction)?.isSuspend == true +val IrCall.isSuspend get() = symbol.owner.isSuspend val IrFunctionReference.isSuspend get() = (symbol.owner as? IrSimpleFunction)?.isSuspend == true val IrFunction.isOverridable get() = this is IrSimpleFunction && this.isOverridable diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt index a45c0945b2d..ec6a339e661 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt @@ -193,7 +193,7 @@ internal open class KtUltraLightFieldImpl protected constructor( override val lightMemberOrigin = LightMemberOriginForDeclaration(declaration, JvmDeclarationOriginKind.OTHER) override fun setName(@NonNls name: String): PsiElement { - (kotlinOrigin as? KtNamedDeclaration)?.setName(name) + kotlinOrigin.setName(name) return this } diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/RawSubstitution.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/RawSubstitution.kt index ce8dfd7d93b..f3addf54183 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/RawSubstitution.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/RawSubstitution.kt @@ -75,7 +75,7 @@ internal class RawSubstitution(typeParameterUpperBoundEraser: TypeParameterUpper }, type.isMarkedNullable, memberScope ) factory@{ kotlinTypeRefiner -> - val classId = (declaration as? ClassDescriptor)?.classId ?: return@factory null + val classId = declaration.classId ?: return@factory null @OptIn(TypeRefinement::class) val refinedClassDescriptor = kotlinTypeRefiner.findClassAcrossModuleDependencies(classId) ?: return@factory null diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassLayoutBuilder.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassLayoutBuilder.kt index 0240e033a7b..ae13b8ef55d 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassLayoutBuilder.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassLayoutBuilder.kt @@ -7,23 +7,24 @@ package org.jetbrains.kotlin.backend.konan.descriptors import llvm.LLVMABIAlignmentOfType import llvm.LLVMABISizeOfType -import llvm.LLVMPreferredAlignmentOfType import llvm.LLVMStoreSizeOfType import org.jetbrains.kotlin.backend.common.lower.coroutines.getOrCreateFunctionWithContinuationStub import org.jetbrains.kotlin.backend.konan.* -import org.jetbrains.kotlin.backend.konan.ir.* +import org.jetbrains.kotlin.backend.konan.ir.getSuperClassNotAny +import org.jetbrains.kotlin.backend.konan.ir.isSpecialClassWithNoSupertypes import org.jetbrains.kotlin.backend.konan.llvm.CodegenLlvmHelpers import org.jetbrains.kotlin.backend.konan.llvm.computeFunctionName -import org.jetbrains.kotlin.backend.konan.llvm.toLLVMType import org.jetbrains.kotlin.backend.konan.llvm.localHash +import org.jetbrains.kotlin.backend.konan.llvm.toLLVMType import org.jetbrains.kotlin.backend.konan.lower.bridgeTarget -import org.jetbrains.kotlin.backend.konan.serialization.KonanIrLinker import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrClassReference import org.jetbrains.kotlin.ir.expressions.IrConst -import org.jetbrains.kotlin.ir.objcinterop.* +import org.jetbrains.kotlin.ir.objcinterop.canObjCClassMethodBeCalledVirtually +import org.jetbrains.kotlin.ir.objcinterop.isKotlinObjCClass +import org.jetbrains.kotlin.ir.objcinterop.isObjCClassMethod import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.* @@ -470,8 +471,7 @@ internal class ClassLayoutBuilder(val irClass: IrClass, val context: Context) { irClass.annotations.forEach { val irFile = irClass.fileOrNull - val annotationClass = (it.symbol.owner as? IrConstructor)?.constructedClass - ?: error(irFile, it, "unexpected annotation") + val annotationClass = it.symbol.owner.constructedClass if (annotationClass.hasAnnotation(RuntimeNames.associatedObjectKey)) { val argument = it.getValueArgument(0) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt index c7c7c28dfec..edea3eb6f47 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt @@ -51,8 +51,6 @@ import org.jetbrains.kotlin.konan.library.KonanLibrary import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.native.interop.ObjCMethodInfo -import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe -import org.jetbrains.kotlin.resolve.descriptorUtil.module internal class InteropLowering(generationState: NativeGenerationState) : FileLoweringPass { // TODO: merge these lowerings. @@ -1034,11 +1032,7 @@ private class InteropTransformer( if (!function.isFromInteropLibrary()) return null if (!function.isGetter) return null - val constantProperty = (function as? IrSimpleFunction) - ?.correspondingPropertySymbol - ?.owner - ?.takeIf { it.isConst } - ?: return null + val constantProperty = function.correspondingPropertySymbol?.owner?.takeIf { it.isConst } ?: return null val initializer = constantProperty.backingField?.initializer?.expression require(initializer is IrConst<*>) { renderCompilerError(expression) } @@ -1088,9 +1082,7 @@ private class InteropTransformer( builder.at(expression) val function = expression.symbol.owner - if ((function as? IrSimpleFunction)?.resolveFakeOverrideMaybeAbstract()?.symbol - == symbols.interopNativePointedRawPtrGetter) { - + if (function.resolveFakeOverrideMaybeAbstract()?.symbol == symbols.interopNativePointedRawPtrGetter) { // Replace by the intrinsic call to be handled by code generator: return builder.irCall(symbols.interopNativePointedGetRawPointer).apply { extensionReceiver = expression.dispatchReceiver diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ObjectClassLowering.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ObjectClassLowering.kt index 2fb5f29a106..703e80c82d2 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ObjectClassLowering.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ObjectClassLowering.kt @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.objcinterop.* import org.jetbrains.kotlin.ir.util.* -import org.jetbrains.kotlin.ir.util.irCall internal fun Context.getObjectClassInstanceFunction(clazz: IrClass) = mapping.objectInstanceGetter.getOrPut(clazz) { when { @@ -159,8 +158,7 @@ internal class ObjectClassLowering(val generationState: NativeGenerationState) : val statements = this.body?.statements ?: return false if (statements.isEmpty()) return false val constructorCall = statements[0] as? IrDelegatingConstructorCall ?: return false - val constructor = constructorCall.symbol.owner as? IrConstructor ?: return false - if (!constructor.constructedClass.isAny()) return false + if (!constructorCall.symbol.owner.constructedClass.isAny()) return false return statements.asSequence().drop(1).all { it is IrBlock && it.origin == IrStatementOrigin.INITIALIZE_FIELD } diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt index 2c4583d842e..f6e59d2cab3 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.backend.konan.lower import org.jetbrains.kotlin.backend.common.BodyLoweringPass -import org.jetbrains.kotlin.backend.common.ir.Symbols import org.jetbrains.kotlin.backend.common.lower.at import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.konan.Context @@ -83,7 +82,7 @@ internal class PostInlineLowering(val context: Context) : BodyLoweringPass { val builder = StringBuilder() args.elements.forEach { require(it is IrConst<*>) { renderCompilerError(irFile, it, "expected const") } - val value = (it as? IrConst<*>)?.value + val value = it.value require(value is Short && value >= 0 && value <= 0xff) { renderCompilerError(irFile, it, "incorrect value for binary data: $value") } diff --git a/kotlin-native/utilities/cli-runner/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/InteropCompiler.kt b/kotlin-native/utilities/cli-runner/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/InteropCompiler.kt index a05b8f6382e..8f025a941ee 100644 --- a/kotlin-native/utilities/cli-runner/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/InteropCompiler.kt +++ b/kotlin-native/utilities/cli-runner/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/InteropCompiler.kt @@ -31,8 +31,8 @@ fun invokeInterop(flavor: String, args: Array, runFromDaemon: Boolean): val purgeUserLibs = arguments.purgeUserLibs val nopack = arguments.nopack val temporaryFilesDir = arguments.tempDir - val moduleName = (arguments as? CInteropArguments)?.moduleName - val shortModuleName = (arguments as? CInteropArguments)?.shortModuleName + val moduleName = arguments.moduleName + val shortModuleName = arguments.shortModuleName val buildDir = File("$outputFileName-build") val generatedDir = File(buildDir, "kotlin") diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt index 1baa6cbd234..be22d213ca5 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -339,8 +339,16 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati if (!checkIfValidTypeName(clazz, Type.getObjectType(clazz.name))) return null val descriptor = kaptContext.origins[clazz]?.descriptor ?: return null - val isNested = (descriptor as? ClassDescriptor)?.isNested ?: false - val isInner = isNested && (descriptor as? ClassDescriptor)?.isInner ?: false + + val isNested: Boolean + val isInner: Boolean + if (descriptor is ClassDescriptor) { + isNested = descriptor.isNested + isInner = isNested && descriptor.isInner + } else { + isNested = false + isInner = false + } val flags = getClassAccessFlags(clazz, descriptor, isInner, isNested)