Skip to content

Commit

Permalink
Got rid of a few Kotlin type warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jlink committed Jun 10, 2024
1 parent 485960d commit af874dc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.util.function.BiFunction
* Convenience function for Kotlin to not use backticked `in` function.
*/
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
fun <B, T> BuilderCombinator<B>.use(arbitrary: Arbitrary<T>, combinator: (B, T) -> B): BuilderCombinator<B>
fun <B, T> BuilderCombinator<B>.use(arbitrary: Arbitrary<T & Any>, combinator: (B, T) -> B): BuilderCombinator<B>
where B : Any {
return this.use(arbitrary).`in`(combinator)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import org.apiguardian.api.API
* Convenience function to replace Arbitraries.subsetOf(..)
*/
@API(status = API.Status.EXPERIMENTAL, since = "1.6.5")
fun <T> Collection<T>.anySubset(): SetArbitrary<T> = Arbitraries.subsetOf(this)
fun <T: Any> Collection<T>.anySubset(): SetArbitrary<T> = Arbitraries.subsetOf(this)

/**
* Convenience function to replace Arbitraries.of(..)
*/
@API(status = API.Status.EXPERIMENTAL, since = "1.7.1")
fun <T> Collection<T>.anyValue(): Arbitrary<T> = Arbitraries.of(this)
fun <T: Any> Collection<T>.anyValue(): Arbitrary<T> = Arbitraries.of(this)
8 changes: 4 additions & 4 deletions kotlin/src/main/kotlin/net/jqwik/kotlin/api/CombinatorDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class CombinatorScope internal constructor(private val bindings: ValueBindings)
filters += filter
}

fun <R> combineAs(creator: () -> R): Combined<R> {
fun <R> combineAs(creator: () -> R): Combined<R> where R : Any {
check(!created.getAndSet(true)) { "'combineAs' must only be called once" }

return Combined.Regular(arbitraries.toList(), filters.toList(), creator)
}

fun <R> flatCombineAs(creator: () -> Arbitrary<R>): Combined<R> {
fun <R> flatCombineAs(creator: () -> Arbitrary<R>): Combined<R> where R : Any {
check(!created.getAndSet(true)) { "'flatCombineAs' must only be called once" }

return Combined.Flat(arbitraries.toList(), filters.toList(), creator)
Expand Down Expand Up @@ -102,7 +102,7 @@ sealed class Combined<R>(
arbitraries: List<Arbitrary<*>>,
filters: List<() -> Boolean>,
val creator: () -> R
) : Combined<R>(arbitraries, filters) {
) : Combined<R>(arbitraries, filters) where R : Any {
override fun ListCombinator<*>.asArbitrary(bindings: ValueBindings): Arbitrary<R> {
return `as` { values ->
bindings.withValues(values) {
Expand All @@ -116,7 +116,7 @@ sealed class Combined<R>(
arbitraries: List<Arbitrary<*>>,
filters: List<() -> Boolean>,
val creator: () -> Arbitrary<R>
) : Combined<R>(arbitraries, filters) {
) : Combined<R>(arbitraries, filters) where R: Any {
override fun ListCombinator<*>.asArbitrary(bindings: ValueBindings): Arbitrary<R> {
return flatAs { values ->
bindings.withValues(values) {
Expand Down
12 changes: 6 additions & 6 deletions kotlin/src/main/kotlin/net/jqwik/kotlin/api/JqwikGlobals.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun <A, B, C> anyTriple(firstArbitrary: Arbitrary<A>, secondArbitrary: Arbitrary


/**
* Function to create a [FunctionWrapper].
* Function to create a [Functions.FunctionWrapper].
*
* This is a Kotlin convenience for [Functions.function] which requires a Java class instead.
*/
Expand All @@ -41,39 +41,39 @@ fun anyFunction(kClass: KClass<*>): Functions.FunctionWrapper {
* Create a [FunctionArbitrary] for Kotlin function without parameters.
*/
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
fun <R> anyFunction0(returning: Arbitrary<R>): FunctionArbitrary<Function0<R>, R> {
fun <R> anyFunction0(returning: Arbitrary<out R>): FunctionArbitrary<Function0<R>, out R> {
return anyFunction(Function0::class).returning(returning)
}

/**
* Create a [FunctionArbitrary] for Kotlin function with 1 parameter.
*/
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
fun <A, R> anyFunction1(returning: Arbitrary<R>): FunctionArbitrary<Function1<A, R>, R> {
fun <A, R> anyFunction1(returning: Arbitrary<out R>): FunctionArbitrary<Function1<A, R>, out R> {
return anyFunction(Function1::class).returning(returning)
}

/**
* Create a [FunctionArbitrary] for Kotlin function with 2 parameters.
*/
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
fun <A, B, R> anyFunction2(returning: Arbitrary<R>): FunctionArbitrary<Function2<A, B, R>, R> {
fun <A, B, R> anyFunction2(returning: Arbitrary<out R>): FunctionArbitrary<Function2<A, B, R>, out R> {
return anyFunction(Function2::class).returning(returning)
}

/**
* Create a [FunctionArbitrary] for Kotlin function with 3 parameters.
*/
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
fun <A, B, C, R> anyFunction3(returning: Arbitrary<R>): FunctionArbitrary<Function3<A, B, C, R>, R> {
fun <A, B, C, R> anyFunction3(returning: Arbitrary<out R>): FunctionArbitrary<Function3<A, B, C, R>, out R> {
return anyFunction(Function3::class).returning(returning)
}

/**
* Create a [FunctionArbitrary] for Kotlin function with 4 parameters.
*/
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
fun <A, B, C, D, R> anyFunction4(returning: Arbitrary<R>): FunctionArbitrary<Function4<A, B, C, D, R>, R> {
fun <A, B, C, D, R> anyFunction4(returning: Arbitrary<out R>): FunctionArbitrary<Function4<A, B, C, D, R>, out R> {
return anyFunction(Function4::class).returning(returning)
}

Expand Down

0 comments on commit af874dc

Please sign in to comment.