Introduce builder-like inference with an explicit opt-in for it
- Add marker for the experimental type inference features - Add annotation that will control builder-like inference - Require that annotation on corresponding parameters and extensions - Allow to use builder inference without suspendability Changes in tests and refactorings (rename mainly) are going to be introduced in further commits
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
// FILE: annotation.kt
|
||||
|
||||
package kotlin
|
||||
|
||||
annotation class BuilderInference
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class Builder<T> {
|
||||
fun add(t: T) {}
|
||||
}
|
||||
|
||||
fun <S> build(@BuilderInference g: Builder<S>.() -> Unit): List<S> = TODO()
|
||||
fun <S> wrongBuild(g: Builder<S>.() -> Unit): List<S> = TODO()
|
||||
|
||||
fun <S> Builder<S>.extensionAdd(s: S) {}
|
||||
|
||||
@BuilderInference
|
||||
fun <S> Builder<S>.safeExtensionAdd(s: S) {}
|
||||
|
||||
val member = build {
|
||||
add(42)
|
||||
}
|
||||
|
||||
val memberWithoutAnn = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>wrongBuild<!> {
|
||||
add(42)
|
||||
}
|
||||
|
||||
val extension = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
|
||||
extensionAdd("foo")
|
||||
}
|
||||
|
||||
val safeExtension = build {
|
||||
safeExtensionAdd("foo")
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package
|
||||
|
||||
public val extension: [ERROR : Type for build {
|
||||
extensionAdd("foo")
|
||||
}]
|
||||
public val member: kotlin.collections.List<kotlin.Int>
|
||||
public val memberWithoutAnn: [ERROR : Type for wrongBuild {
|
||||
add(42)
|
||||
}]
|
||||
public val safeExtension: kotlin.collections.List<kotlin.String>
|
||||
public fun </*0*/ S> build(/*0*/ @kotlin.BuilderInference g: Builder<S>.() -> kotlin.Unit): kotlin.collections.List<S>
|
||||
public fun </*0*/ S> wrongBuild(/*0*/ g: Builder<S>.() -> kotlin.Unit): kotlin.collections.List<S>
|
||||
public fun </*0*/ S> Builder<S>.extensionAdd(/*0*/ s: S): kotlin.Unit
|
||||
@kotlin.BuilderInference public fun </*0*/ S> Builder<S>.safeExtensionAdd(/*0*/ s: S): kotlin.Unit
|
||||
|
||||
public final class Builder</*0*/ T> {
|
||||
public constructor Builder</*0*/ T>()
|
||||
public final fun add(/*0*/ t: T): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
package kotlin {
|
||||
|
||||
public final annotation class BuilderInference : kotlin.Annotation {
|
||||
public constructor BuilderInference()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
// FILE: annotation.kt
|
||||
|
||||
package kotlin
|
||||
|
||||
annotation class BuilderInference
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class GenericController<T> {
|
||||
suspend fun yield(t: T) {}
|
||||
}
|
||||
|
||||
suspend fun <S> GenericController<S>.extensionYield(s: S) {}
|
||||
|
||||
@BuilderInference
|
||||
suspend fun <S> GenericController<S>.safeExtensionYield(s: S) {}
|
||||
|
||||
fun <S> generate(@BuilderInference g: suspend GenericController<S>.() -> Unit): List<S> = TODO()
|
||||
|
||||
val normal = generate {
|
||||
yield(42)
|
||||
}
|
||||
|
||||
val extension = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>generate<!> {
|
||||
extensionYield("foo")
|
||||
}
|
||||
|
||||
val safeExtension = generate {
|
||||
safeExtensionYield("foo")
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package
|
||||
|
||||
public val extension: [ERROR : Type for generate {
|
||||
extensionYield("foo")
|
||||
}]
|
||||
public val normal: kotlin.collections.List<kotlin.Int>
|
||||
public val safeExtension: kotlin.collections.List<kotlin.String>
|
||||
public fun </*0*/ S> generate(/*0*/ @kotlin.BuilderInference g: suspend GenericController<S>.() -> kotlin.Unit): kotlin.collections.List<S>
|
||||
public suspend fun </*0*/ S> GenericController<S>.extensionYield(/*0*/ s: S): kotlin.Unit
|
||||
@kotlin.BuilderInference public suspend fun </*0*/ S> GenericController<S>.safeExtensionYield(/*0*/ s: S): kotlin.Unit
|
||||
|
||||
public final class GenericController</*0*/ T> {
|
||||
public constructor GenericController</*0*/ T>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
public final suspend fun yield(/*0*/ t: T): kotlin.Unit
|
||||
}
|
||||
|
||||
package kotlin {
|
||||
|
||||
public final annotation class BuilderInference : kotlin.Annotation {
|
||||
public constructor BuilderInference()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user