Skip to content

Commit

Permalink
Remove warning suppressions needed for compatibility with K1 compilation
Browse files Browse the repository at this point in the history
^KT-62472 Fixed
  • Loading branch information
demiurg906 authored and Space Team committed Dec 3, 2024
1 parent a7b6486 commit 8dbc24e
Show file tree
Hide file tree
Showing 38 changed files with 28 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,6 @@ internal class KaFirDataFlowProvider(
}
}

@Suppress("USELESS_IS_CHECK") // K2 warning suppression, TODO: KT-62472
require(firDefaultStatement is FirExpression)

val defaultStatementFromFir = firDefaultStatement.psi as? KtExpression ?: return null

if (!PsiTreeUtil.isAncestor(defaultStatementFromFir, defaultStatement.deparenthesize(), false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,6 @@ internal class KaFirResolver(
)
}
is FirPropertyAccessExpression, is FirCallableReferenceAccess -> {
@Suppress("USELESS_IS_CHECK") // K2 warning suppression, TODO: KT-62472
require(fir is FirQualifiedAccessExpression)
when (partiallyAppliedSymbol.symbol) {
is KaVariableSymbol -> {
@Suppress("UNCHECKED_CAST") // safe because of the above check on targetKtSymbol
Expand Down Expand Up @@ -736,9 +734,8 @@ internal class KaFirResolver(
@Suppress("UNCHECKED_CAST") // safe because of the above check on targetKtSymbol
KaBaseSimpleFunctionCall(
partiallyAppliedSymbol as KaPartiallyAppliedFunctionSymbol<KaFunctionSymbol>,
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
argumentMappingWithoutExtensionReceiver
?.createArgumentMapping(partiallyAppliedSymbol.signature as KaFunctionSignature<*>)
?.createArgumentMapping(partiallyAppliedSymbol.signature)
?: emptyMap(),
typeArgumentsMapping,
isImplicitInvoke
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaFunctionSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaVariableSymbol
import org.jetbrains.kotlin.analysis.api.types.KaSubstitutor
import org.jetbrains.kotlin.analysis.utils.errors.unexpectedElementError

@KaImplementationDetail
abstract class KaAbstractSignatureSubstitutor<T : KaSession> : KaSessionComponent<T>(), KaSignatureSubstitutor {
Expand All @@ -31,20 +30,16 @@ abstract class KaAbstractSignatureSubstitutor<T : KaSession> : KaSessionComponen
}

override fun <S : KaCallableSymbol> S.substitute(substitutor: KaSubstitutor): KaCallableSignature<S> = withValidityAssertion {
@Suppress("REDUNDANT_ELSE_IN_WHEN") // K2 warning suppression, TODO: KT-62472
when (this) {
is KaFunctionSymbol -> substitute(substitutor)
is KaVariableSymbol -> substitute(substitutor)
else -> unexpectedElementError("symbol", this)
}
}

override fun <S : KaCallableSymbol> S.asSignature(): KaCallableSignature<S> = withValidityAssertion {
@Suppress("REDUNDANT_ELSE_IN_WHEN") // K2 warning suppression, TODO: KT-62472
return when (this) {
is KaFunctionSymbol -> asSignature()
is KaVariableSymbol -> asSignature()
else -> unexpectedElementError("symbol", this)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class KtLightMethodForDecompiledDeclaration(
override fun findSuperMethodSignaturesIncludingStatic(checkAccess: Boolean): List<MethodSignatureBackedByPsiMethod> =
PsiSuperMethodImplUtil.findSuperMethodSignaturesIncludingStatic(this, checkAccess)

@Suppress("OVERRIDE_DEPRECATION") // K2 warning suppression, TODO: KT-62472
override fun findDeepestSuperMethod() = PsiSuperMethodImplUtil.findDeepestSuperMethod(this)
@Deprecated("Deprecated in Java")
override fun findDeepestSuperMethod(): PsiMethod? = PsiSuperMethodImplUtil.findDeepestSuperMethod(this)

override fun findDeepestSuperMethods(): Array<out PsiMethod> = PsiSuperMethodImplUtil.findDeepestSuperMethods(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ internal class LLFirImplicitBodyTargetResolver(
else -> throwUnexpectedFirElementError(target)
}

@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
(target as FirDeclaration).forEachDeclarationWhichCanHavePostponedSymbols(::publishPostponedSymbols)
target.forEachDeclarationWhichCanHavePostponedSymbols(::publishPostponedSymbols)
}

private fun publishPostponedSymbols(target: FirCallableDeclaration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ internal class SymbolLightClassForFacade(
if (callableSymbol !is KaNamedFunctionSymbol && callableSymbol !is KaKotlinPropertySymbol) continue

// We shouldn't materialize expect declarations
@Suppress("USELESS_IS_CHECK") // K2 warning suppression, TODO: KT-62472
if (callableSymbol is KaDeclarationSymbol && callableSymbol.isExpect) continue
if (callableSymbol.isExpect) continue
if ((callableSymbol as? KaAnnotatedSymbol)?.hasInlineOnlyAnnotation() == true) continue
if (multiFileClass && callableSymbol.toPsiVisibilityForMember() == PsiModifier.PRIVATE) continue
if (hasTypeForValueClassInSignature(callableSymbol = callableSymbol, ignoreReturnType = true)) continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ internal abstract class SymbolLightMethodBase(
override fun findSuperMethodSignaturesIncludingStatic(checkAccess: Boolean): List<MethodSignatureBackedByPsiMethod> =
PsiSuperMethodImplUtil.findSuperMethodSignaturesIncludingStatic(this, checkAccess)

@Suppress("OVERRIDE_DEPRECATION") // K2 warning suppression, TODO: KT-62472
override fun findDeepestSuperMethod() = PsiSuperMethodImplUtil.findDeepestSuperMethod(this)
@Deprecated("Deprecated in Java")
override fun findDeepestSuperMethod(): PsiMethod? = PsiSuperMethodImplUtil.findDeepestSuperMethod(this)

override fun findDeepestSuperMethods(): Array<out PsiMethod> = PsiSuperMethodImplUtil.findDeepestSuperMethods(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ open class BuildReporter<B : BuildTime, P : BuildPerformanceMetric>(
protected open val buildMetricsReporter: BuildMetricsReporter<B, P>,
) : ICReporter by icReporter, BuildMetricsReporter<B, P> by buildMetricsReporter

@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") // K2 warning suppression, TODO: KT-62472
class RemoteBuildReporter<B : BuildTime, P : BuildPerformanceMetric>(
override val icReporter: RemoteICReporter,
override val buildMetricsReporter: RemoteBuildMetricsReporter<B, P>,
Expand All @@ -23,6 +22,5 @@ class RemoteBuildReporter<B : BuildTime, P : BuildPerformanceMetric>(
}
}

@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") // K2 warning suppression, TODO: KT-62472
object DoNothingBuildReporter :
BuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>(DoNothingICReporter, DoNothingBuildMetricsReporter)
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,7 @@ class MethodInliner(

private fun getNewIndex(`var`: Int): Int {
val lambdaInfo = inliningContext.lambdaInfo
@Suppress("USELESS_IS_CHECK") // K2 warning suppression, TODO: KT-62472
if (reorderIrLambdaParameters && lambdaInfo is IrExpressionLambda) {
if (reorderIrLambdaParameters) {
val extensionSize = if (lambdaInfo.isExtensionLambda) lambdaInfo.invokeMethod.argumentTypes[0].size else 0
return when {
// v-- extensionSize v-- argsSizeOnStack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ object FirReturnsImpliesAnalyzer : FirControlFlowChecker(MppCheckerKind.Common)
val typeContext = context.session.typeContext

val isReturn = node is JumpNode && node.fir is FirReturnExpression
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
val resultExpression = if (isReturn) (node.fir as FirReturnExpression).result else node.fir

val expressionType = (resultExpression as? FirExpression)?.resolvedType?.fullyExpandedType(context.session)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ fun CheckerContext.findClosestClassOrObject(): FirClass? {
it is FirRegularClass ||
it is FirAnonymousObject
) {
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
return it as FirClass
return it
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import org.jetbrains.kotlin.fir.types.*
object FirAmbiguousAnonymousTypeChecker : FirBasicDeclarationChecker(MppCheckerKind.Common) {
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
if (declaration !is FirFunction && declaration !is FirProperty) return
@Suppress("USELESS_IS_CHECK") // K2 warning suppression, TODO: KT-62472
require(declaration is FirCallableDeclaration)
// if source is not null then this type was declared in source
// so it can not be inferred to anonymous type
if (declaration.symbol.hasExplicitReturnType) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,6 @@ class FirElementSerializer private constructor(
}

for (typeParameter in function.typeParameters) {
@Suppress("USELESS_IS_CHECK") // K2 warning suppression, TODO: KT-62472
if (typeParameter !is FirTypeParameter) continue
builder.addTypeParameter(local.typeParameterProto(typeParameter))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ class Fir2IrCallableDeclarationsGenerator(private val c: Fir2IrComponents) : Fir
?: if (isLambda) SpecialNames.ANONYMOUS else SpecialNames.NO_NAME_PROVIDED
val visibility = simpleFunction?.visibility ?: Visibilities.Local
val isSuspend =
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
if (isLambda) ((function as FirAnonymousFunction).typeRef as? FirResolvedTypeRef)?.coneType?.isSuspendOrKSuspendFunctionType(session) == true
if (isLambda) (function.typeRef as? FirResolvedTypeRef)?.coneType?.isSuspendOrKSuspendFunctionType(session) == true
else function.isSuspend
val created = function.convertWithOffsets { startOffset, endOffset ->
classifierStorage.preCacheTypeParameters(function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource

@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") // K2 warning suppression, TODO: KT-62472
class Fir2IrLazyPropertyAccessor(
c: Fir2IrComponents,
startOffset: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource

@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") // K2 warning suppression, TODO: KT-62472
class Fir2IrLazySimpleFunction(
c: Fir2IrComponents,
startOffset: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ fun FirClassSymbol<*>.collectEnumEntries(): Collection<FirEnumEntrySymbol> {
* sequence of FirTypeAlias'es points to starting
* with `this`. Or null if something goes wrong or we have anonymous object symbol.
*/
@Suppress("NO_TAIL_CALLS_FOUND", "NON_TAIL_RECURSIVE_CALL") // K2 warning suppression, TODO: KT-62472
tailrec fun FirClassLikeSymbol<*>.fullyExpandedClass(useSiteSession: FirSession): FirRegularClassSymbol? {
return when (this) {
is FirRegularClassSymbol -> this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2915,17 +2915,11 @@ open class PsiRawFirBuilder(
fun PsiElement.getLastChildExpression() = children.asList().asReversed().firstIsInstanceOrNull<KtExpression>()

return when (parent) {
// todo KT-62472 Replace with the following when K2 is used in TeamCity
// is KtBlockExpression, is KtTryExpression -> parent.getLastChildExpression() == this && parent.usedAsExpression
is KtBlockExpression -> parent.getLastChildExpression() == this && parent.usedAsExpression
is KtTryExpression -> parent.getLastChildExpression() == this && parent.usedAsExpression
is KtBlockExpression, is KtTryExpression -> parent.getLastChildExpression() == this && parent.usedAsExpression
is KtCatchClause -> (parent.parent as? KtTryExpression)?.usedAsExpression == true
is KtClassInitializer, is KtScriptInitializer, is KtSecondaryConstructor, is KtFunctionLiteral, is KtFinallySection -> false
is KtDotQualifiedExpression -> parent.firstChild == this
// todo KT-62472 Replace with the following when K2 is used in TeamCity
// is KtFunction, is KtPropertyAccessor -> parent.hasBody() && !parent.hasBlockBody()
is KtFunction -> parent.hasBody() && !parent.hasBlockBody()
is KtPropertyAccessor -> parent.hasBody() && !parent.hasBlockBody()
is KtFunction, is KtPropertyAccessor -> parent.hasBody() && !parent.hasBlockBody()
is KtContainerNodeForControlStructureBody -> when (parent.parent.elementType) {
KtNodeTypes.FOR, KtNodeTypes.WHILE, KtNodeTypes.DO_WHILE -> false
else -> true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,7 @@ abstract class AbstractRawFirBuilder<T>(val baseSession: FirSession, val context
}
require(operation == FirOperation.ASSIGN)

@Suppress("SENSELESS_COMPARISON") // K2 warning suppression, TODO: KT-62472
if (this?.elementType == SAFE_ACCESS_EXPRESSION && this != null) {
if (this?.elementType == SAFE_ACCESS_EXPRESSION) {
val safeCallNonAssignment = convert() as? FirSafeCallExpression
if (safeCallNonAssignment != null) {
return putAssignmentToSafeCall(safeCallNonAssignment, baseSource, rhsExpression, annotations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ private fun processConstructors(
}
}
is FirClassSymbol -> {
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
val firClass = matchedSymbol.fir as FirClass
val firClass = matchedSymbol.fir
when (firClass.classKind) {
ClassKind.INTERFACE -> null
else -> firClass.scopeForClass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ interface VariableInitReadOnlyControlFlowInfo :
fun checkDefiniteInitializationInWhen(merge: VariableInitReadOnlyControlFlowInfo): Boolean
}

@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") // K2 warning suppression, TODO: KT-62472
class VariableInitControlFlowInfo(map: ImmutableMap<VariableDescriptor, VariableControlFlowState> = ImmutableHashMap.empty()) :
VariableUsageControlFlowInfo<VariableInitControlFlowInfo, VariableControlFlowState>(map),
VariableInitReadOnlyControlFlowInfo {
Expand All @@ -43,7 +42,6 @@ class VariableInitControlFlowInfo(map: ImmutableMap<VariableDescriptor, Variable
}
}

@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") // K2 warning suppression, TODO: KT-62472
class UsageVariableControlFlowInfo(map: ImmutableMap<VariableDescriptor, VariableUseState> = ImmutableHashMap.empty()) :
VariableUsageControlFlowInfo<UsageVariableControlFlowInfo, VariableUseState>(map),
VariableUsageReadOnlyControlInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,7 @@ class DiagnosticReporterByTrackingStrategy(
KtPsiUtil.deparenthesize(it) ?: it
}
if (expression != null) {
@Suppress("USELESS_IS_CHECK") // K2 warning suppression, TODO: KT-62472
if (expression.isNull() && expression is KtConstantExpression) {
if (expression.isNull()) {
val factory = when (diagnostic) {
is ArgumentNullabilityErrorDiagnostic -> NULL_FOR_NONNULL_TYPE
is ArgumentNullabilityWarningDiagnostic -> NULL_FOR_NONNULL_TYPE_WARNING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ class KotlinToResolvedCallTransformer(
}

is CompletedCallResolutionResult, is ErrorCallResolutionResult -> {
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
val candidate = (baseResolvedCall as SingleCallResolutionResult).resultCallAtom
val candidate = baseResolvedCall.resultCallAtom

val resultSubstitutor =
baseResolvedCall.constraintSystem.getBuilder().currentStorage().buildResultingSubstitutor(typeSystemContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ object ActualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker :
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions)) return
val (actual, expect) = matchActualWithNonFinalExpect(declaration, descriptor, context) ?: return

// The explicit casts won't be necessary when we start compiling kotlin with K2. K1 doesn't build CFG properly
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
declaration as KtClassLikeDeclaration
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
descriptor as ClassifierDescriptorWithTypeParameters

checkExpectActualScopeDiff(expect, actual, context, declaration, descriptor)
}
}
Expand Down Expand Up @@ -76,11 +69,6 @@ internal fun matchActualWithNonFinalExpect(

// Common supertype of KtTypeAlias and KtClassOrObject is KtClassLikeDeclaration.
// Common supertype of TypeAliasDescriptor and ClassDescriptor is ClassifierDescriptorWithTypeParameters.
// The explicit casts won't be necessary when we start compiling kotlin with K2.
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
declaration as KtClassLikeDeclaration
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
descriptor as ClassifierDescriptorWithTypeParameters

if (!descriptor.isActual) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ package org.jetbrains.kotlin.resolve.checkers
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.areExpectActualClassesStable
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.KtClassLikeDeclaration
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtTypeAlias
Expand All @@ -26,12 +24,6 @@ object ExpectActualClassifiersAreInBetaChecker : DeclarationChecker {

// Common supertype of KtTypeAlias and KtClassOrObject is KtClassLikeDeclaration.
// Common supertype of TypeAliasDescriptor and ClassDescriptor is ClassifierDescriptorWithTypeParameters.
// The explicit casts won't be necessary when we start compiling kotlin with K2.
@Suppress("USELESS_IS_CHECK") // K2 warning suppression, TODO: KT-62472
check(declaration is KtClassLikeDeclaration)
@Suppress("USELESS_IS_CHECK") // K2 warning suppression, TODO: KT-62472
check(descriptor is ClassifierDescriptorWithTypeParameters)

if (descriptor.isExpect || descriptor.isActual) {
context.trace.report(Errors.EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING.on(declaration))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ abstract class UsefulDeclarationProcessor(
addReachabilityInfoIfNeeded(from, this, description, isContagiousOverridableDeclaration)

if (isContagiousOverridableDeclaration) {
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
contagiousReachableDeclarations.add(this as IrOverridableDeclaration<*>)
contagiousReachableDeclarations.add(this)
}

if (!isReachable()) {
Expand Down
Loading

0 comments on commit 8dbc24e

Please sign in to comment.