org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.multiplatform
sealed class ExpectActualCompatibility {
// For IncompatibilityKind.STRONG `actual` declaration is considered as overload and error reports on expected declaration
enum class IncompatibilityKind {
WEAK, STRONG
}
// Note that the reason is used in the diagnostic output, see PlatformIncompatibilityDiagnosticRenderer
sealed class Incompatible(
val reason: String?,
val kind: IncompatibilityKind = IncompatibilityKind.WEAK
) : ExpectActualCompatibility() {
// Callables
object CallableKind : Incompatible(
"callable kinds are different (function vs property)",
IncompatibilityKind.STRONG
)
object ParameterShape : Incompatible(
"parameter shapes are different (extension vs non-extension)",
IncompatibilityKind.STRONG
)
object ParameterCount : Incompatible("number of value parameters is different", IncompatibilityKind.STRONG)
object TypeParameterCount : Incompatible("number of type parameters is different", IncompatibilityKind.STRONG)
object ParameterTypes : Incompatible("parameter types are different", IncompatibilityKind.STRONG)
object ReturnType : Incompatible("return type is different", IncompatibilityKind.STRONG)
object ParameterNames : Incompatible("parameter names are different")
object TypeParameterNames : Incompatible("names of type parameters are different")
object ValueParameterVararg : Incompatible("some value parameter is vararg in one declaration and non-vararg in the other")
object ValueParameterNoinline : Incompatible(
"some value parameter is noinline in one declaration and not noinline in the other"
)
object ValueParameterCrossinline : Incompatible(
"some value parameter is crossinline in one declaration and not crossinline in the other"
)
// Functions
object FunctionModifiersDifferent : Incompatible("modifiers are different (suspend)")
object FunctionModifiersNotSubset : Incompatible(
"some modifiers on expected declaration are missing on the actual one (external, infix, inline, operator, tailrec)"
)
// Properties
object PropertyKind : Incompatible("property kinds are different (val vs var)")
object PropertyLateinitModifier : Incompatible("modifiers are different (lateinit)")
object PropertyConstModifier : Incompatible("modifiers are different (const)")
// Classifiers
object ClassKind : Incompatible("class kinds are different (class, interface, object, enum, annotation)")
object ClassModifiers : Incompatible("modifiers are different (companion, inner, inline)")
object Supertypes : Incompatible("some supertypes are missing in the actual declaration")
class ClassScopes(
val unfulfilled: List, Collection>>>
) : Incompatible("some expected members have no actual ones")
object EnumEntries : Incompatible("some entries from expected enum are missing in the actual enum")
// Common
object Modality : Incompatible("modality is different")
object Visibility : Incompatible("visibility is different")
object TypeParameterUpperBounds : Incompatible("upper bounds of type parameters are different", IncompatibilityKind.STRONG)
object TypeParameterVariance : Incompatible("declaration-site variances of type parameters are different")
object TypeParameterReified : Incompatible(
"some type parameter is reified in one declaration and non-reified in the other"
)
object Unknown : Incompatible(null)
}
object Compatible : ExpectActualCompatibility()
}
val ExpectActualCompatibility<*>.compatible: Boolean
get() = this == ExpectActualCompatibility.Compatible