Skip to content

Commit

Permalink
[STDLIB] 1/2 Drop AllowDifferentMembersInActual from stdlib
Browse files Browse the repository at this point in the history
^KT-62656 Fixed

I blindly converted all `@AllowDifferentMembersInActual` to suppresses.
But some suppresses in stdlib are redundant. I'm too lazy properly
annotate only the necessary places. All these suppresses will go away
after the bootstrap update anyway

I drop allowDifferentMembersInActual_class and
allowDifferentMembersInActual_typealias tests because their only purpose
was to check that `@AllowDifferentMembersInActual` works as expected

Note: some tests are failing in the compiler because of that. I will fix
them in the next commit
  • Loading branch information
nikitabobko authored and qodana-bot committed Oct 20, 2023
1 parent 5cbfe24 commit 882f468
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ package kotlin.reflect
*
* @param R return type of the callable.
*/
@AllowDifferentMembersInActual // New 'KAnnotatedElement` supertype is added compared to the expect declaration
@Suppress(
"ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING",
"ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING"
) // Can be dropped after bootstrap update
public actual interface KCallable<out R> : KAnnotatedElement {
/**
* The name of this callable as it was declared in the source code.
Expand All @@ -26,5 +29,6 @@ public actual interface KCallable<out R> : KAnnotatedElement {
/**
* The type of values returned by this callable.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
public val returnType: KType
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package kotlin.reflect
*
* @param T the type of the class.
*/
@AllowDifferentMembersInActual // New 'KDeclarationContainer', 'KAnnotatedElement` supertypes are added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
public actual interface KClass<T : Any> : KDeclarationContainer, KAnnotatedElement, KClassifier {
/**
* The simple name of the class as it was declared in the source code,
Expand Down
9 changes: 0 additions & 9 deletions libraries/stdlib/api/js/kotlin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -846,15 +846,6 @@ public inline fun kotlin.Short.toUShort(): kotlin.UShort
@kotlin.internal.InlineOnly
public inline fun <T : kotlin.AutoCloseable?, R> T.use(block: (T) -> R): R

@kotlin.annotation.Retention(value = AnnotationRetention.SOURCE)
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS})
@kotlin.annotation.MustBeDocumented
@kotlin.ExperimentalMultiplatform
@kotlin.SinceKotlin(version = "1.9")
public final annotation class AllowDifferentMembersInActual : kotlin.Annotation {
public constructor AllowDifferentMembersInActual()
}

public interface Annotation {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package kotlin.collections
*
* @param E the type of elements contained in the collection. The collection is invariant in its element type.
*/
@AllowDifferentMembersInActual // New 'checkIsMutable', 'toJSON', etc. members are added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING", "ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
public actual abstract class AbstractMutableCollection<E> protected actual constructor() : AbstractCollection<E>(), MutableCollection<E> {

actual abstract override fun add(element: E): Boolean
Expand Down Expand Up @@ -57,6 +57,7 @@ public actual abstract class AbstractMutableCollection<E> protected actual const
}
}

@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
@Deprecated("Provided so that subclasses inherit this function", level = DeprecationLevel.HIDDEN)
@JsName("toJSON")
protected fun toJSON(): Any = this.toArray()
Expand All @@ -66,6 +67,7 @@ public actual abstract class AbstractMutableCollection<E> protected actual const
* This method is called every time when a mutating method is called on this mutable collection.
* Mutable collections that are built (frozen) must throw `UnsupportedOperationException`.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
internal open fun checkIsMutable(): Unit { }
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ package kotlin.collections
*
* @param E the type of elements contained in the list. The list is invariant in its element type.
*/
@AllowDifferentMembersInActual // New 'removeRange', 'checkIsMutable', etc. members are added compared to the expect declaration
@Suppress(
"ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING",
"ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING"
) // Can be dropped after bootstrap update
public actual abstract class AbstractMutableList<E> protected actual constructor() : AbstractMutableCollection<E>(), MutableList<E> {
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
protected var modCount: Int = 0

abstract override fun add(index: Int, element: E): Unit
Expand Down Expand Up @@ -82,6 +86,7 @@ public actual abstract class AbstractMutableList<E> protected actual constructor
/**
* Removes the range of elements from this list starting from [fromIndex] and ending with but not including [toIndex].
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
protected open fun removeRange(fromIndex: Int, toIndex: Int) {
val iterator = listIterator(fromIndex)
repeat(toIndex - fromIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package kotlin.collections
* @param K the type of map keys. The map is invariant in its key type.
* @param V the type of map values. The map is invariant in its value type.
*/
@AllowDifferentMembersInActual // New 'createKeysView', 'checkIsMutable', etc. members are added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING", "ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
public actual abstract class AbstractMutableMap<K, V> protected actual constructor() : AbstractMap<K, V>(), MutableMap<K, V> {

@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
internal open fun createKeysView(): MutableSet<K> = HashMapKeysDefault(this)
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
internal open fun createValuesView(): MutableCollection<V> = HashMapValuesDefault(this)

private var keysView: MutableSet<K>? = null
Expand Down Expand Up @@ -66,5 +68,6 @@ public actual abstract class AbstractMutableMap<K, V> protected actual construct
* This method is called every time when a mutating method is called on this mutable map.
* Mutable maps that are built (frozen) must throw `UnsupportedOperationException`.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
internal open fun checkIsMutable() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package kotlin.collections
*
* @param E the type of elements contained in the set. The set is invariant in its element type.
*/
@AllowDifferentMembersInActual // New 'AbstractMutableCollection` supertype is added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING", "ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
public actual abstract class AbstractMutableSet<E> protected actual constructor() : AbstractMutableCollection<E>(), MutableSet<E> {

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/stdlib/jvm/runtime/kotlin/TypeAliases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ package kotlin
@Suppress("NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS")
@SinceKotlin("1.3") public actual typealias ConcurrentModificationException = java.util.ConcurrentModificationException

@AllowDifferentMembersInActual // New 'reversed', 'thenComparing', etc. members are added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING", "ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
@SinceKotlin("1.1") public actual typealias Comparator<T> = java.util.Comparator<T>
2 changes: 1 addition & 1 deletion libraries/stdlib/jvm/runtime/kotlin/text/TypeAliases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package kotlin.text

@AllowDifferentMembersInActual // New 'append' members are added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING", "ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
@SinceKotlin("1.1") public actual typealias Appendable = java.lang.Appendable

@Suppress("ACTUAL_WITHOUT_EXPECT") // TODO: some supertypes are missing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import java.util.AbstractCollection
* @param E the type of elements contained in the collection. The collection is invariant in its element type.
*/
@SinceKotlin("1.1")
@AllowDifferentMembersInActual // New 'AbstractCollection` supertype is added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING", "ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
public actual abstract class AbstractMutableCollection<E> protected actual constructor() : MutableCollection<E>, AbstractCollection<E>() {
/**
* Adds the specified element to the collection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import java.util.AbstractList
* @param E the type of elements contained in the list. The list is invariant in its element type.
*/
@SinceKotlin("1.1")
@AllowDifferentMembersInActual // New 'AbstractList` supertype is added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING", "ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
public actual abstract class AbstractMutableList<E> protected actual constructor() : MutableList<E>, AbstractList<E>() {
/**
* Replaces the element at the specified position in this list with the specified element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.util.AbstractMap
* @param V the type of map values. The map is invariant in its value type.
*/
@SinceKotlin("1.1")
@AllowDifferentMembersInActual // New 'AbstractMap` supertype is added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING", "ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
public actual abstract class AbstractMutableMap<K, V> protected actual constructor() : MutableMap<K, V>, AbstractMap<K, V>() {
/**
* Associates the specified [value] with the specified [key] in the map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import java.util.AbstractSet
* @param E the type of elements contained in the set. The set is invariant in its element type.
*/
@SinceKotlin("1.1")
@AllowDifferentMembersInActual // New 'AbstractSet` supertype is added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING", "ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
public actual abstract class AbstractMutableSet<E> protected actual constructor() : MutableSet<E>, AbstractSet<E>() {
/**
* Adds the specified element to the set.
Expand Down
12 changes: 11 additions & 1 deletion libraries/stdlib/jvm/src/kotlin/reflect/KCallable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package kotlin.reflect
*
* @param R return type of the callable.
*/
@AllowDifferentMembersInActual // New 'KAnnotatedElement` supertype is added compared to the expect declaration
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING", "ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING") // Can be dropped after bootstrap update
public actual interface KCallable<out R> : KAnnotatedElement {
/**
* The name of this callable as it was declared in the source code.
Expand All @@ -28,16 +28,19 @@ public actual interface KCallable<out R> : KAnnotatedElement {
* If this callable requires a `this` instance or an extension receiver parameter,
* they come first in the list in that order.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
public val parameters: List<KParameter>

/**
* The type of values returned by this callable.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
public val returnType: KType

/**
* The list of type parameters of this callable.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
@SinceKotlin("1.1")
public val typeParameters: List<KTypeParameter>

Expand All @@ -46,42 +49,49 @@ public actual interface KCallable<out R> : KAnnotatedElement {
* Throws an exception if the number of specified arguments is not equal to the size of [parameters],
* or if their types do not match the types of the parameters.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
public fun call(vararg args: Any?): R

/**
* Calls this callable with the specified mapping of parameters to arguments and returns the result.
* If a parameter is not found in the mapping and is not optional (as per [KParameter.isOptional]),
* or its type does not match the type of the provided value, an exception is thrown.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
public fun callBy(args: Map<KParameter, Any?>): R

/**
* Visibility of this callable, or `null` if its visibility cannot be represented in Kotlin.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
@SinceKotlin("1.1")
public val visibility: KVisibility?

/**
* `true` if this callable is `final`.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
@SinceKotlin("1.1")
public val isFinal: Boolean

/**
* `true` if this callable is `open`.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
@SinceKotlin("1.1")
public val isOpen: Boolean

/**
* `true` if this callable is `abstract`.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
@SinceKotlin("1.1")
public val isAbstract: Boolean

/**
* `true` if this is a suspending function.
*/
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING") // Can be dropped after bootstrap update
@SinceKotlin("1.3")
public val isSuspend: Boolean
}
Loading

0 comments on commit 882f468

Please sign in to comment.