diff --git a/arrow-libs/core/arrow-core/build.gradle.kts b/arrow-libs/core/arrow-core/build.gradle.kts index a5dc552212..4fcc2fc57a 100644 --- a/arrow-libs/core/arrow-core/build.gradle.kts +++ b/arrow-libs/core/arrow-core/build.gradle.kts @@ -7,8 +7,11 @@ plugins { @OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { - compilerOptions.freeCompilerArgs.add("-Xexpect-actual-classes") - compilerOptions.freeCompilerArgs.add("-Xcontext-parameters") + compilerOptions.freeCompilerArgs.addAll( + "-Xexpect-actual-classes", + "-Xcontext-parameters", + "-Xallow-contracts-on-more-functions" + ) sourceSets { val nonJvmAndJsMain by creating { dependsOn(nonJvmMain.get()) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index ca67c92570..36497d4fa7 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -490,8 +490,8 @@ public sealed class Either { */ public fun isLeft(): Boolean { contract { - returns(true) implies (this@Either is Left) - returns(false) implies (this@Either is Right) + returns(true) implies (this@Either is Left) + returns(false) implies (this@Either is Right) } return this@Either is Left } @@ -501,8 +501,8 @@ public sealed class Either { */ public fun isRight(): Boolean { contract { - returns(true) implies (this@Either is Right) - returns(false) implies (this@Either is Left) + returns(true) implies (this@Either is Right) + returns(false) implies (this@Either is Left) } return this@Either is Right } @@ -530,7 +530,7 @@ public sealed class Either { */ public inline fun isLeft(predicate: (A) -> Boolean): Boolean { contract { - returns(true) implies (this@Either is Left) + returns(true) implies (this@Either is Left) callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } return this@Either is Left && predicate(value) @@ -559,7 +559,7 @@ public sealed class Either { */ public inline fun isRight(predicate: (B) -> Boolean): Boolean { contract { - returns(true) implies (this@Either is Right) + returns(true) implies (this@Either is Right) callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } return this@Either is Right && predicate(value) @@ -725,7 +725,7 @@ public sealed class Either { */ public fun getOrNull(): B? { contract { - returnsNotNull() implies (this@Either is Right) + returnsNotNull() implies (this@Either is Right) } return getOrElse { null } } @@ -747,7 +747,7 @@ public sealed class Either { */ public fun leftOrNull(): A? { contract { - returnsNotNull() implies (this@Either is Left) + returnsNotNull() implies (this@Either is Left) } return fold(::identity) { null } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt index 0725978310..7260b86d68 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt @@ -51,8 +51,8 @@ public sealed class Ior { */ public fun isLeft(): Boolean { contract { - returns(true) implies (this@Ior is Left) - returns(false) implies (this@Ior is Right || this@Ior is Both) + returns(true) implies (this@Ior is Left) + returns(false) implies (this@Ior is Right || this@Ior is Both) } return this@Ior is Ior.Left } @@ -75,8 +75,8 @@ public sealed class Ior { */ public fun isRight(): Boolean { contract { - returns(true) implies (this@Ior is Right) - returns(false) implies (this@Ior is Left || this@Ior is Both) + returns(true) implies (this@Ior is Right) + returns(false) implies (this@Ior is Left || this@Ior is Both) } return this@Ior is Ior.Right } @@ -98,8 +98,8 @@ public sealed class Ior { */ public fun isBoth(): Boolean { contract { - returns(false) implies (this@Ior is Right || this@Ior is Left) - returns(true) implies (this@Ior is Both) + returns(false) implies (this@Ior is Right || this@Ior is Left) + returns(true) implies (this@Ior is Both) } return this@Ior is Ior.Both } @@ -263,7 +263,7 @@ public sealed class Ior { public fun getOrNull(): B? { contract { - returnsNotNull() implies (this@Ior is Right || this@Ior is Both) + returnsNotNull() implies (this@Ior is Right || this@Ior is Both) } return fold({ null }, { it }, { _, b -> b }) } @@ -289,7 +289,7 @@ public sealed class Ior { */ public fun leftOrNull(): A? { contract { - returnsNotNull() implies (this@Ior is Left || this@Ior is Both) + returnsNotNull() implies (this@Ior is Left || this@Ior is Both) } return fold({ it }, { null }, { a, _ -> a }) } @@ -335,8 +335,8 @@ public sealed class Ior { */ public inline fun isLeft(predicate: (A) -> Boolean): Boolean { contract { - returns(true) implies (this@Ior is Left) - returns(false) implies (this@Ior is Right || this@Ior is Both) + returns(true) implies (this@Ior is Left) + returns(false) implies (this@Ior is Right || this@Ior is Both) callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } return this@Ior is Left && predicate(value) @@ -361,8 +361,8 @@ public sealed class Ior { */ public inline fun isRight(predicate: (B) -> Boolean): Boolean { contract { - returns(true) implies (this@Ior is Right) - returns(false) implies (this@Ior is Left || this@Ior is Both) + returns(true) implies (this@Ior is Right) + returns(false) implies (this@Ior is Left || this@Ior is Both) callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } return this@Ior is Right && predicate(value) @@ -388,8 +388,8 @@ public sealed class Ior { */ public inline fun isBoth(leftPredicate: (A) -> Boolean, rightPredicate: (B) -> Boolean): Boolean { contract { - returns(true) implies (this@Ior is Both) - returns(false) implies (this@Ior is Left || this@Ior is Right) + returns(true) implies (this@Ior is Both) + returns(false) implies (this@Ior is Left || this@Ior is Right) callsInPlace(leftPredicate, InvocationKind.AT_MOST_ONCE) callsInPlace(rightPredicate, InvocationKind.AT_MOST_ONCE) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt index 9d18226208..eceacb3933 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt @@ -382,7 +382,7 @@ public sealed class Option { */ public fun isNone(): Boolean { contract { - returns(false) implies (this@Option is Some) + returns(false) implies (this@Option is Some) returns(true) implies (this@Option is None) } return this@Option is None @@ -394,7 +394,7 @@ public sealed class Option { */ public fun isSome(): Boolean { contract { - returns(true) implies (this@Option is Some) + returns(true) implies (this@Option is Some) returns(false) implies (this@Option is None) } return this@Option is Some @@ -426,7 +426,7 @@ public sealed class Option { public inline fun isSome(predicate: (A) -> Boolean): Boolean { contract { callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) - returns(true) implies (this@Option is Some) + returns(true) implies (this@Option is Some) } return this@Option is Some && predicate(value) } @@ -448,7 +448,7 @@ public sealed class Option { */ public fun getOrNull(): A? { contract { - returnsNotNull() implies (this@Option is Some) + returnsNotNull() implies (this@Option is Some) } return getOrElse { null } } diff --git a/buildSrc/src/main/kotlin/arrow.kotlin.gradle.kts b/buildSrc/src/main/kotlin/arrow.kotlin.gradle.kts index c6b9df2d18..b17ba40bc7 100644 --- a/buildSrc/src/main/kotlin/arrow.kotlin.gradle.kts +++ b/buildSrc/src/main/kotlin/arrow.kotlin.gradle.kts @@ -90,6 +90,7 @@ fun KotlinCommonCompilerOptions.commonCompilerOptions() { apiVersion = KotlinVersion.KOTLIN_2_0 languageVersion = KotlinVersion.KOTLIN_2_0 freeCompilerArgs.addAll( + "-Xdata-flow-based-exhaustiveness", "-Xreport-all-warnings", "-Xrender-internal-diagnostic-names", ) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index df47d3d64c..b760e836d4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ classgraph = "4.8.181" dokka = "2.1.0-Beta" kotest = "6.0.3" kover = "0.9.1" -kotlin = "2.2.10" +kotlin = "2.2.20" kotlinCompileTesting = "0.8.0" knit = "0.5.0" kspVersion = "2.2.10-2.0.2"