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
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
sealed class ExpectActualCompatibility {
// Note that the reason is used in the diagnostic output, see PlatformIncompatibilityDiagnosticRenderer
sealed class Incompatible(val reason: String?) : ExpectActualCompatibility() {
sealed class WeakIncompatible(reason: String?) : Incompatible(reason)
// For StrongIncompatible `actual` declaration is considered as overload and error reports on expected declaration
sealed class StrongIncompatible(reason: String?) : Incompatible(reason)
// Callables
object CallableKind : StrongIncompatible("callable kinds are different (function vs property)")
object ParameterShape : StrongIncompatible("parameter shapes are different (extension vs non-extension)")
object ParameterCount : StrongIncompatible("number of value parameters is different")
// FunctionTypeParameterCount is strong because functions can be overloaded by type parameter count
object FunctionTypeParameterCount : StrongIncompatible("number of type parameters is different")
// ClassTypeParameterCount is weak because classes cannot be overloaded
object ClassTypeParameterCount : WeakIncompatible(FunctionTypeParameterCount.reason)
object ParameterTypes : StrongIncompatible("parameter types are different")
object ReturnType : StrongIncompatible("return type is different")
object ParameterNames : WeakIncompatible("parameter names are different")
object TypeParameterNames : WeakIncompatible("names of type parameters are different")
object ValueParameterVararg : WeakIncompatible("some value parameter is vararg in one declaration and non-vararg in the other")
object ValueParameterNoinline : WeakIncompatible(
"some value parameter is noinline in one declaration and not noinline in the other"
)
object ValueParameterCrossinline : WeakIncompatible(
"some value parameter is crossinline in one declaration and not crossinline in the other"
)
// Functions
object FunctionModifiersDifferent : WeakIncompatible("modifiers are different (suspend)")
object FunctionModifiersNotSubset : WeakIncompatible(
"some modifiers on expected declaration are missing on the actual one (infix, inline, operator)"
)
object ActualFunctionWithDefaultParameters :
WeakIncompatible("actual function cannot have default argument values, they should be declared in the expected function")
// Properties
object PropertyKind : WeakIncompatible("property kinds are different (val vs var)")
object PropertyLateinitModifier : WeakIncompatible("modifiers are different (lateinit)")
object PropertyConstModifier : WeakIncompatible("modifiers are different (const)")
object PropertySetterVisibility : WeakIncompatible("setter visibility is different")
// Classifiers
object ClassKind : WeakIncompatible("class kinds are different (class, interface, object, enum, annotation)")
object ClassModifiers : WeakIncompatible("modifiers are different (companion, inner, inline)")
object FunInterfaceModifier : WeakIncompatible("actual declaration for fun expect interface is not a functional interface")
object Supertypes : WeakIncompatible("some supertypes are missing in the actual declaration")
class ClassScopes(
val unfulfilled: List, Collection>>>
) : WeakIncompatible("some expected members have no actual ones")
object EnumEntries : WeakIncompatible("some entries from expected enum are missing in the actual enum")
// Common
object Modality : WeakIncompatible("modality is different")
object Visibility : WeakIncompatible("visibility is different")
// FunctionTypeParameterUpperBounds is weak because functions can be overloaded by type parameter upper bounds
object FunctionTypeParameterUpperBounds : StrongIncompatible("upper bounds of type parameters are different")
// ClassTypeParameterUpperBounds is strong because classes cannot be overloaded
object ClassTypeParameterUpperBounds : WeakIncompatible(FunctionTypeParameterUpperBounds.reason)
object TypeParameterVariance : WeakIncompatible("declaration-site variances of type parameters are different")
object TypeParameterReified : WeakIncompatible(
"some type parameter is reified in one declaration and non-reified in the other"
)
object Unknown : WeakIncompatible(null)
}
object Compatible : ExpectActualCompatibility()
}
val ExpectActualCompatibility<*>.compatible: Boolean
get() = this == ExpectActualCompatibility.Compatible
@OptIn(ExperimentalContracts::class)
fun ExpectActualCompatibility<*>.isIncompatible(): Boolean {
contract {
returns(true) implies (this@isIncompatible is ExpectActualCompatibility.Incompatible<*>)
}
return !compatible
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy