From dee467457b63ddcb7e2fe7e16c3ee3466107cdda Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Wed, 30 Jan 2019 18:32:08 +0300 Subject: [PATCH] Stdlib warnings fixes --- .../kotlin/org/jetbrains/kotlin/ExecutorService.kt | 2 +- runtime/src/main/kotlin/kotlin/collections/Arrays.kt | 10 +++++----- .../src/main/kotlin/kotlin/collections/Collections.kt | 8 +++----- runtime/src/main/kotlin/kotlin/collections/Maps.kt | 1 + .../src/main/kotlin/kotlin/coroutines/DebugProbes.kt | 2 ++ .../kotlin/coroutines/intrinsics/IntrinsicsNative.kt | 3 +++ .../kotlin/kotlin/native/internal/KPropertyImpl.kt | 8 ++++---- runtime/src/main/kotlin/kotlin/native/ref/Weak.kt | 1 + .../main/kotlin/kotlin/text/regex/sets/AbstractSet.kt | 1 + 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt b/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt index 22a8d69f466..6d5d3fd8aea 100644 --- a/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt +++ b/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt @@ -122,7 +122,7 @@ fun runProcess(executor: (Action) -> ExecResult?, val stdOut = outStream.toString("UTF-8") val stdErr = errStream.toString("UTF-8") - return ProcessOutput(stdOut, stdErr, execResult!!.exitValue) + return ProcessOutput(stdOut, stdErr, execResult.exitValue) } fun runProcess(executor: (Action) -> ExecResult?, diff --git a/runtime/src/main/kotlin/kotlin/collections/Arrays.kt b/runtime/src/main/kotlin/kotlin/collections/Arrays.kt index 219986c07a0..d4b6e4352bc 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Arrays.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Arrays.kt @@ -15,7 +15,7 @@ import kotlin.util.sortArray /** Returns the array if it's not `null`, or an empty array otherwise. */ public actual inline fun Array?.orEmpty(): Array = this ?: emptyArray() - +@Suppress("NOTHING_TO_INLINE") @PublishedApi internal inline fun checkCopyOfRangeArguments(fromIndex: Int, toIndex: Int, size: Int) { if (toIndex > size) throw IndexOutOfBoundsException("toIndex ($toIndex) is greater than size ($size).") @@ -92,9 +92,8 @@ internal fun Array.contentDeepHashCodeImpl(): Int { return result } -internal actual fun arrayOfNulls(reference: Array, size: Int): Array { - return (@Suppress("UNCHECKED_CAST")(arrayOfNulls(size)) as Array) -} +@Suppress("UNCHECKED_CAST") +internal actual fun arrayOfNulls(reference: Array, size: Int): Array = arrayOfNulls(size) as Array internal actual fun copyToArrayImpl(collection: Collection<*>): Array { val array = arrayOfUninitializedElements(collection.size) @@ -105,6 +104,7 @@ internal actual fun copyToArrayImpl(collection: Collection<*>): Array { return array } +@Suppress("UNCHECKED_CAST") internal actual fun copyToArrayImpl(collection: Collection<*>, array: Array): Array { if (array.size < collection.size) return copyToArrayImpl(collection) as Array @@ -115,7 +115,7 @@ internal actual fun copyToArrayImpl(collection: Collection<*>, array: Array< array[index++] = iterator.next() as T } if (index < array.size) { - return (@Suppress("UNCHECKED_CAST")(array as Array)).copyOf(index) as Array + return array.copyOf(index) as Array } return array } diff --git a/runtime/src/main/kotlin/kotlin/collections/Collections.kt b/runtime/src/main/kotlin/kotlin/collections/Collections.kt index bbcdb776d54..3bb6b0dc6ca 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Collections.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Collections.kt @@ -11,11 +11,9 @@ import kotlin.random.* /** Copies typed varargs array to an array of objects */ internal actual fun Array.copyToArrayOfAny(isVarargs: Boolean): Array = - if (isVarargs) - // if the array came from varargs and already is array of Any, copying isn't required. - @Suppress("UNCHECKED_CAST") (this as Array) - else - @Suppress("UNCHECKED_CAST") (this.copyOfUninitializedElements(this.size) as Array) + // if the array came from varargs and already is array of Any, copying isn't required. + if (isVarargs) this + else this.copyOfUninitializedElements(this.size) /** diff --git a/runtime/src/main/kotlin/kotlin/collections/Maps.kt b/runtime/src/main/kotlin/kotlin/collections/Maps.kt index ab30fac508e..8d7203e48c6 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Maps.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Maps.kt @@ -6,6 +6,7 @@ package kotlin.collections // creates a singleton copy of map, if there is specialization available in target platform, otherwise returns itself +@Suppress("NOTHING_TO_INLINE") internal inline actual fun Map.toSingletonMapOrSelf(): Map = toSingletonMap() // creates a singleton copy of map diff --git a/runtime/src/main/kotlin/kotlin/coroutines/DebugProbes.kt b/runtime/src/main/kotlin/kotlin/coroutines/DebugProbes.kt index 81f83c9ca68..35e5be28297 100644 --- a/runtime/src/main/kotlin/kotlin/coroutines/DebugProbes.kt +++ b/runtime/src/main/kotlin/kotlin/coroutines/DebugProbes.kt @@ -54,6 +54,7 @@ internal fun probeCoroutineCreated(completion: Continuation): Continuatio * [BaseContinuationImpl] class, despite the fact that the declared type of [frame] * parameter in this function is `Continuation<*>`. See [probeCoroutineCreated] for details. */ +@Suppress("UNUSED_PARAMETER") @SinceKotlin("1.3") internal fun probeCoroutineResumed(frame: Continuation<*>) { } @@ -68,6 +69,7 @@ internal fun probeCoroutineResumed(frame: Continuation<*>) { * [BaseContinuationImpl] class, despite the fact that the declared type of [frame] * parameter in this function is `Continuation<*>`. See [probeCoroutineCreated] for details. */ +@Suppress("UNUSED_PARAMETER") @SinceKotlin("1.3") internal fun probeCoroutineSuspended(frame: Continuation<*>) { } diff --git a/runtime/src/main/kotlin/kotlin/coroutines/intrinsics/IntrinsicsNative.kt b/runtime/src/main/kotlin/kotlin/coroutines/intrinsics/IntrinsicsNative.kt index 675f351696f..2834425a8c4 100644 --- a/runtime/src/main/kotlin/kotlin/coroutines/intrinsics/IntrinsicsNative.kt +++ b/runtime/src/main/kotlin/kotlin/coroutines/intrinsics/IntrinsicsNative.kt @@ -71,6 +71,7 @@ private object CoroutineSuspendedMarker * state machine of the coroutine and may result in arbitrary behaviour or exception. */ @SinceKotlin("1.3") +@Suppress("UNCHECKED_CAST") public actual fun (suspend () -> T).createCoroutineUnintercepted( completion: Continuation ): Continuation { @@ -105,6 +106,7 @@ public actual fun (suspend () -> T).createCoroutineUnintercepted( * state machine of the coroutine and may result in arbitrary behaviour or exception. */ @SinceKotlin("1.3") +@Suppress("UNCHECKED_CAST") public actual fun (suspend R.() -> T).createCoroutineUnintercepted( receiver: R, completion: Continuation @@ -148,6 +150,7 @@ public actual fun Continuation.intercepted(): Continuation = * The instance of [BaseContinuationImpl] is passed to the [block] so that it can be passed to the corresponding invocation. */ @SinceKotlin("1.3") +@Suppress("UNCHECKED_CAST") private inline fun createCoroutineFromSuspendFunction( completion: Continuation, crossinline block: (Continuation) -> Any? diff --git a/runtime/src/main/kotlin/kotlin/native/internal/KPropertyImpl.kt b/runtime/src/main/kotlin/kotlin/native/internal/KPropertyImpl.kt index 77146c406bc..d80b74cabb1 100644 --- a/runtime/src/main/kotlin/kotlin/native/internal/KPropertyImpl.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/KPropertyImpl.kt @@ -34,8 +34,8 @@ open class KProperty0Impl(override val name: String, override val returnT @FixmeReflection open class KProperty1Impl(override val name: String, override val returnType: KType, val getter: (T) -> R): KProperty1 { - override fun get(p1: T): R { - return getter(p1) + override fun get(receiver: T): R { + return getter(receiver) } override fun invoke(p1: T): R { return getter(p1) @@ -58,8 +58,8 @@ open class KProperty1Impl(override val name: String, override val retu @FixmeReflection open class KProperty2Impl(override val name: String, override val returnType: KType, val getter: (T1, T2) -> R): KProperty2 { - override fun get(p1: T1, p2: T2): R { - return getter(p1, p2) + override fun get(receiver1: T1, receiver2: T2): R { + return getter(receiver1, receiver2) } override fun invoke(p1: T1, p2: T2): R { return getter(p1, p2) diff --git a/runtime/src/main/kotlin/kotlin/native/ref/Weak.kt b/runtime/src/main/kotlin/kotlin/native/ref/Weak.kt index 972b96cf3ad..3531b011e13 100644 --- a/runtime/src/main/kotlin/kotlin/native/ref/Weak.kt +++ b/runtime/src/main/kotlin/kotlin/native/ref/Weak.kt @@ -35,6 +35,7 @@ public class WeakReference { /** * Returns either reference to an object or null, if it was collected. */ + @Suppress("UNCHECKED_CAST") public fun get(): T? = pointer?.get() as T? } diff --git a/runtime/src/main/kotlin/kotlin/text/regex/sets/AbstractSet.kt b/runtime/src/main/kotlin/kotlin/text/regex/sets/AbstractSet.kt index 68f4f50dfef..897b4d61f9b 100644 --- a/runtime/src/main/kotlin/kotlin/text/regex/sets/AbstractSet.kt +++ b/runtime/src/main/kotlin/kotlin/text/regex/sets/AbstractSet.kt @@ -46,6 +46,7 @@ internal abstract class AbstractSet(val type: Int = 0) { val dummyNext = object : AbstractSet() { override var next: AbstractSet get() = throw AssertionError("This method is not expected to be called.") + @Suppress("UNUSED_PARAMETER") set(value) {} override fun matches(startIndex: Int, testString: CharSequence, matchResult: MatchResultImpl) = throw AssertionError("This method is not expected to be called.")