Add expected type constraints in a builder inference call

This commit is contained in:
Victor Petukhov
2021-04-29 11:26:59 +03:00
parent 7da47dcde8
commit 90066d7e50
9 changed files with 165 additions and 4 deletions
@@ -0,0 +1,36 @@
// WITH_RUNTIME
interface A {
fun foo(): MutableList<String>
}
@ExperimentalStdlibApi
fun main() {
buildList {
add(3)
object : A {
override fun foo(): MutableList<String> = this@buildList
}
}
buildList {
add(3)
val x: String = get(0)
}
buildList {
add("3")
val x: MutableList<Int> = this@buildList
}
buildList {
val y: CharSequence = ""
add(y)
val x: MutableList<String> = this@buildList
}
buildList {
add("")
val x: MutableList<CharSequence> = this@buildList
}
buildList {
add("")
val x: StringBuilder = get(0)
}
}
@@ -0,0 +1,36 @@
// WITH_RUNTIME
interface A {
fun foo(): MutableList<String>
}
@ExperimentalStdlibApi
fun main() {
buildList {
add(<!CONSTANT_EXPECTED_TYPE_MISMATCH, CONSTANT_EXPECTED_TYPE_MISMATCH!>3<!>)
object : A {
override fun foo(): MutableList<String> = this@buildList
}
}
buildList {
add(<!CONSTANT_EXPECTED_TYPE_MISMATCH, CONSTANT_EXPECTED_TYPE_MISMATCH!>3<!>)
val x: String = get(0)
}
buildList {
add(<!TYPE_MISMATCH, TYPE_MISMATCH!>"3"<!>)
val x: MutableList<Int> = this@buildList
}
buildList {
val y: CharSequence = ""
add(<!TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>y<!>)
val x: MutableList<String> = this@buildList
}
buildList {
add("")
val x: MutableList<CharSequence> = this@buildList
}
buildList {
add(<!TYPE_MISMATCH, TYPE_MISMATCH!>""<!>)
val x: StringBuilder = get(0)
}
}
@@ -0,0 +1,10 @@
package
@kotlin.ExperimentalStdlibApi public fun main(): kotlin.Unit
public interface A {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(): kotlin.collections.MutableList<kotlin.String>
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}