Skip to content

Commit

Permalink
Remove a bunch of warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Nov 4, 2023
1 parent 19d1a29 commit ad08c57
Show file tree
Hide file tree
Showing 58 changed files with 271 additions and 239 deletions.
6 changes: 2 additions & 4 deletions arrow-libs/core/arrow-atomic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ kotlin {
}
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-Xexpect-actual-classes"
}
tasks.withType<KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
}

tasks.withType<Test> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class EitherCallAdapterFactory : CallAdapter.Factory() {
}
}

private inline fun extractErrorAndReturnType(wrapperType: Type, returnType: ParameterizedType): Pair<Type, Type> {
private fun extractErrorAndReturnType(wrapperType: Type, returnType: ParameterizedType): Pair<Type, Type> {
if (wrapperType !is ParameterizedType) {
val name = parseTypeName(returnType)
throw IllegalArgumentException(
Expand Down
4 changes: 4 additions & 0 deletions arrow-libs/core/arrow-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ kotlin {
}

// enables context receivers for Jvm Tests
tasks.withType<KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
}

tasks.named<KotlinCompile>("compileTestKotlinJvm") {
kotlinOptions.freeCompilerArgs += "-Xcontext-receivers"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ public inline infix fun <A, B> Either<A, B>.getOrElse(default: (A) -> B): B {
* <!--- KNIT example-either-33.kt -->
* <!--- TEST lines.isEmpty() -->
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun <A> Either<A, A>.merge(): A =
fold(::identity, ::identity)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public value class NonEmptyList<out A> @PublishedApi internal constructor(
else -> head
}

@Suppress("OVERRIDE_BY_INLINE")
@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE")
public override inline fun distinct(): NonEmptyList<A> =
NonEmptyList(all.distinct())

Expand Down Expand Up @@ -340,6 +340,7 @@ public fun <A> nonEmptyListOf(head: A, vararg t: A): NonEmptyList<A> =
NonEmptyList(listOf(head) + t)

@JvmName("nel")
@Suppress("NOTHING_TO_INLINE")
public inline fun <A> A.nel(): NonEmptyList<A> =
NonEmptyList(listOf(this))

Expand All @@ -355,9 +356,11 @@ public inline fun <A, B : Comparable<B>> NonEmptyList<A>.minBy(selector: (A) ->
public inline fun <A, B : Comparable<B>> NonEmptyList<A>.maxBy(selector: (A) -> B): A =
maxByOrNull(selector)!!

@Suppress("NOTHING_TO_INLINE")
public inline fun <T : Comparable<T>> NonEmptyList<T>.min(): T =
minOrNull()!!

@Suppress("NOTHING_TO_INLINE")
public inline fun <T : Comparable<T>> NonEmptyList<T>.max(): T =
maxOrNull()!!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlin.coroutines.cancellation.CancellationException
* else -> "Hello"
* }
*
* fun main(args: Array<String>) {
* fun main() {
* val nonFatal: Either<Throwable, String> =
* //sampleStart
* try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package arrow.core
import arrow.core.Either.Left
import arrow.core.Either.Right
import arrow.core.raise.RaiseAccumulate
import arrow.core.raise.either
import arrow.core.raise.fold
import kotlin.experimental.ExperimentalTypeInference

Expand Down Expand Up @@ -574,7 +573,7 @@ public fun <A> Sequence<A>.salign(
* @return a tuple containing Sequence with [Either.Left] and another Sequence with its [Either.Right] values.
*/
public fun <A, B> Sequence<Either<A, B>>.separateEither(): Pair<List<A>, List<B>> =
fold(listOf<A>() to listOf<B>()) { (lefts, rights), either ->
fold(listOf<A>() to listOf()) { (lefts, rights), either ->
when (either) {
is Left -> lefts + either.value to rights
is Right -> lefts to rights + either.value
Expand Down Expand Up @@ -637,7 +636,7 @@ public fun <Error, A, B> Sequence<A>.mapOrAccumulate(
* import arrow.core.leftIor
* import arrow.core.unalign
*
* fun main(args: Array<String>) {
* fun main() {
* //sampleStart
* val result = sequenceOf(("A" to 1).bothIor(), ("B" to 2).bothIor(), "C".leftIor()).unalign()
* //sampleEnd
Expand All @@ -662,7 +661,7 @@ public fun <A, B> Sequence<Ior<A, B>>.unalign(): Pair<Sequence<A>, Sequence<B>>
* import arrow.core.leftIor
* import arrow.core.unalign
*
* fun main(args: Array<String>) {
* fun main() {
* //sampleStart
* val result = sequenceOf(1, 2, 3).unalign { it.leftIor() }
* //sampleEnd
Expand All @@ -680,7 +679,7 @@ public fun <A, B, C> Sequence<C>.unalign(fa: (C) -> Ior<A, B>): Pair<Sequence<A>
* ```kotlin
* import arrow.core.unweave
*
* fun main(args: Array<String>) {
* fun main() {
* //sampleStart
* val result = sequenceOf(1,2,3).unweave { i -> sequenceOf("$i, ${i + 1}") }
* //sampleEnd
Expand All @@ -700,7 +699,7 @@ public fun <A, B> Sequence<A>.unweave(ffa: (A) -> Sequence<B>): Sequence<B> =
* ```kotlin
* import arrow.core.unzip
*
* fun main(args: Array<String>) {
* fun main() {
* //sampleStart
* val result = sequenceOf("A" to 1, "B" to 2).unzip()
* //sampleEnd
Expand All @@ -720,7 +719,7 @@ public fun <A, B> Sequence<Pair<A, B>>.unzip(): Pair<Sequence<A>, Sequence<B>> =
* ```kotlin
* import arrow.core.unzip
*
* fun main(args: Array<String>) {
* fun main() {
* //sampleStart
* val result =
* sequenceOf("A:1", "B:2", "C:3").unzip { e ->
Expand All @@ -743,7 +742,7 @@ public fun <A, B, C> Sequence<C>.unzip(fc: (C) -> Pair<A, B>): Pair<Sequence<A>,
* ```kotlin
* import arrow.core.widen
*
* fun main(args: Array<String>) {
* fun main() {
* val original: Sequence<String> = sequenceOf("Hello World")
* val result: Sequence<CharSequence> = original.widen()
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public fun <K, A, B> Map<K, A>.zip(other: Map<K, B>): Map<K, Pair<A, B>> =
*
* fun test() {
* mapOf(1 to "A", 2 to "B").zip(mapOf(1 to "1", 2 to "2", 3 to "3")) {
* key, a, b -> "$a ~ $b"
* _, a, b -> "$a ~ $b"
* } shouldBe mapOf(1 to "A ~ 1", 2 to "B ~ 2")
* }
* ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package arrow.core
* else -> "Hello"
* }
*
* fun main(args: Array<String>) {
* fun main() {
* val nonFatal: Either<Throwable, String> =
* //sampleStart
* try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package arrow.core

@Suppress("NOTHING_TO_INLINE")
public inline fun <A> identity(a: A): A = a

/**
Expand All @@ -14,6 +15,7 @@ internal object EmptyValue {
inline fun <A> unbox(value: Any?): A =
if (value === this) null as A else value as A

@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
public inline fun <T> combine(first: Any?, second: T, combine: (T, T) -> T): T =
if (first === EmptyValue) second else combine(first as T, second)
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ import kotlin.jvm.JvmName
* ```kotlin
* val default5: Effect<String, Int> =
* foreign
* .catch { ex: RuntimeException -> -1 }
* .catch { ex: java.sql.SQLException -> -2 }
* .catch { _: RuntimeException -> -1 }
* .catch { _: java.sql.SQLException -> -2 }
* ```
*
* Finally, since `catch` also supports `suspend` we can safely call other `suspend` code and throw `Throwable` into the `suspend` system.
Expand Down Expand Up @@ -338,7 +338,7 @@ import kotlin.jvm.JvmName
* -->
* ```kotlin
* suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
* guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }
* guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
*
* ```
*
Expand Down Expand Up @@ -374,7 +374,7 @@ import kotlin.jvm.JvmName
* import kotlinx.coroutines.awaitCancellation
*
* suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
* guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }
* guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
*
* suspend fun <A> CompletableDeferred<A>.getOrNull(): A? =
* if (isCompleted) await() else null
Expand Down Expand Up @@ -413,7 +413,7 @@ import kotlin.jvm.JvmName
* import kotlinx.coroutines.awaitCancellation
*
* suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
* guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }
* guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
*
* suspend fun <A> CompletableDeferred<A>.getOrNull(): A? =
* if (isCompleted) await() else null
Expand Down Expand Up @@ -456,7 +456,7 @@ import kotlin.jvm.JvmName
* effect<String, Int> {
* bracketCase(
* acquire = { File("build.gradle.kts").bufferedReader() },
* use = { reader: BufferedReader -> raise(error) },
* use = { _: BufferedReader -> raise(error) },
* release = { reader, exitCase ->
* reader.close()
* exit.complete(exitCase)
Expand Down Expand Up @@ -552,7 +552,7 @@ import kotlin.jvm.JvmName
* }
*
* suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
* guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }
* guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
* -->
* ```kotlin
* suspend fun main() {
Expand Down Expand Up @@ -664,11 +664,13 @@ import kotlin.jvm.JvmName
*/
public typealias Effect<Error, A> = suspend Raise<Error>.() -> A

@Suppress("NOTHING_TO_INLINE")
public inline fun <Error, A> effect(@BuilderInference noinline block: suspend Raise<Error>.() -> A): Effect<Error, A> = block

/** The same behavior and API as [Effect] except without requiring _suspend_. */
public typealias EagerEffect<Error, A> = Raise<Error>.() -> A

@Suppress("NOTHING_TO_INLINE")
public inline fun <Error, A> eagerEffect(@BuilderInference noinline block: Raise<Error>.() -> A): EagerEffect<Error, A> = block

public suspend fun <A> Effect<A, A>.merge(): A = merge { invoke() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import kotlin.jvm.JvmName
*
* val error = effect<Error, User> { raise(Error) } // Raise(error)
*
* val a = error.recover<Error, Error, User> { error -> User } // Success(User)
* val b = error.recover<Error, String, User> { error -> raise("other-failure") } // Raise(other-failure)
* val c = error.recover<Error, Nothing, User> { error -> throw RuntimeException("BOOM") } // Exception(BOOM)
* val a = error.recover<Error, Error, User> { _ -> User } // Success(User)
* val b = error.recover<Error, String, User> { _ -> raise("other-failure") } // Raise(other-failure)
* val c = error.recover<Error, Nothing, User> { _ -> throw RuntimeException("BOOM") } // Exception(BOOM)
* ```
* <!--- KNIT example-effect-error-01.kt -->
*/
Expand Down Expand Up @@ -93,7 +93,7 @@ public fun <Error, A> Effect<Error, A>.catch(): Effect<Error, Result<A>> =
catch({ Result.success(invoke()) }, Result.Companion::failure)
}

public suspend inline infix fun <Error, A> Effect<Error, A>.getOrElse(recover: suspend (error: Error) -> A): A =
public suspend inline infix fun <Error, A> Effect<Error, A>.getOrElse(recover: (error: Error) -> A): A =
recover({ invoke() }) { recover(it) }

/**
Expand All @@ -110,9 +110,9 @@ public suspend inline infix fun <Error, A> Effect<Error, A>.getOrElse(recover: s
*
* val error = effect<Error, User> { raise(Error) } // Raise(error)
*
* val a = error.mapError<Error, String, User> { error -> "some-failure" } // Raise(some-failure)
* val a = error.mapError<Error, String, User> { _ -> "some-failure" } // Raise(some-failure)
* val b = error.mapError<Error, String, User>(Any::toString) // Raise(Error)
* val c = error.mapError<Error, Nothing, User> { error -> throw RuntimeException("BOOM") } // Exception(BOOM)
* val c = error.mapError<Error, Nothing, User> { _ -> throw RuntimeException("BOOM") } // Exception(BOOM)
* ```
* <!--- KNIT example-effect-error-04.kt -->
*/
Expand Down Expand Up @@ -147,7 +147,7 @@ public inline infix fun <Error, A> EagerEffect<Error, A>.getOrElse(recover: (err
*
* val error = eagerEffect<Error, User> { raise(Error) } // Raise(error)
*
* val a = error.mapError<Error, String, User> { error -> "some-failure" } // Raise(some-failure)
* val a = error.mapError<Error, String, User> { _ -> "some-failure" } // Raise(some-failure)
* val b = error.mapError<Error, String, User>(Any::toString) // Raise(Error)
* ```
* <!--- KNIT example-effect-error-05.kt -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public interface Raise<in Error> {
*
* either {
* val x = one.bind()
* val y = recover({ left.bind() }) { failure : String -> 1 }
* val y = recover({ left.bind() }) { _ : String -> 1 }
* x + y
* } shouldBe Either.Right(2)
* }
Expand Down Expand Up @@ -325,7 +325,7 @@ public interface Raise<in Error> {
* recover({ raise("failed") }) { str -> str.length } shouldBe 6
*
* either<Int, String> {
* recover({ raise("failed") }) { str -> raise(-1) }
* recover({ raise("failed") }) { _ -> raise(-1) }
* } shouldBe Either.Left(-1)
* }
* ```
Expand Down Expand Up @@ -421,7 +421,7 @@ public inline fun <reified T : Throwable, Error, A> recover(
* -->
* ```kotlin
* fun test() {
* catch({ throw RuntimeException("BOOM") }) { t ->
* catch({ throw RuntimeException("BOOM") }) { _ ->
* "fallback"
* } shouldBe "fallback"
*
Expand Down Expand Up @@ -460,7 +460,7 @@ public inline fun <A> catch(block: () -> A, catch: (throwable: Throwable) -> A):
* -->
* ```kotlin
* fun test() {
* catch({ throw RuntimeException("BOOM") }) { t ->
* catch({ throw RuntimeException("BOOM") }) { _ ->
* "fallback"
* } shouldBe "fallback"
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ object Error

val error = effect<Error, User> { raise(Error) } // Raise(error)

val a = error.recover<Error, Error, User> { error -> User } // Success(User)
val b = error.recover<Error, String, User> { error -> raise("other-failure") } // Raise(other-failure)
val c = error.recover<Error, Nothing, User> { error -> throw RuntimeException("BOOM") } // Exception(BOOM)
val a = error.recover<Error, Error, User> { _ -> User } // Success(User)
val b = error.recover<Error, String, User> { _ -> raise("other-failure") } // Raise(other-failure)
val c = error.recover<Error, Nothing, User> { _ -> throw RuntimeException("BOOM") } // Exception(BOOM)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ object Error

val error = effect<Error, User> { raise(Error) } // Raise(error)

val a = error.mapError<Error, String, User> { error -> "some-failure" } // Raise(some-failure)
val a = error.mapError<Error, String, User> { _ -> "some-failure" } // Raise(some-failure)
val b = error.mapError<Error, String, User>(Any::toString) // Raise(Error)
val c = error.mapError<Error, Nothing, User> { error -> throw RuntimeException("BOOM") } // Exception(BOOM)
val c = error.mapError<Error, Nothing, User> { _ -> throw RuntimeException("BOOM") } // Exception(BOOM)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ object Error

val error = eagerEffect<Error, User> { raise(Error) } // Raise(error)

val a = error.mapError<Error, String, User> { error -> "some-failure" } // Raise(some-failure)
val a = error.mapError<Error, String, User> { _ -> "some-failure" } // Raise(some-failure)
val b = error.mapError<Error, String, User>(Any::toString) // Raise(Error)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import io.kotest.matchers.shouldBe

fun test() {
mapOf(1 to "A", 2 to "B").zip(mapOf(1 to "1", 2 to "2", 3 to "3")) {
key, a, b -> "$a ~ $b"
_, a, b -> "$a ~ $b"
} shouldBe mapOf(1 to "A ~ 1", 2 to "B ~ 2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fun unsafeFunction(i: Int): String =
else -> "Hello"
}

fun main(args: Array<String>) {
fun main() {
val nonFatal: Either<Throwable, String> =
//sampleStart
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fun unsafeFunction(i: Int): String =
else -> "Hello"
}

fun main(args: Array<String>) {
fun main() {
val nonFatal: Either<Throwable, String> =
//sampleStart
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ val default4: Effect<Nothing, Int> =

val default5: Effect<String, Int> =
foreign
.catch { ex: RuntimeException -> -1 }
.catch { ex: java.sql.SQLException -> -2 }
.catch { _: RuntimeException -> -1 }
.catch { _: java.sql.SQLException -> -2 }

suspend fun java.sql.SQLException.isForeignKeyViolation(): Boolean = true

Expand Down
Loading

0 comments on commit ad08c57

Please sign in to comment.