[FIR-TEST] Add new testdata generated after changes in previous commit

This commit is contained in:
Dmitriy Novozhilov
2019-12-11 16:16:22 +03:00
parent e9c02a1cca
commit 2536fa0cd5
4578 changed files with 104067 additions and 1 deletions
@@ -0,0 +1,42 @@
// !LANGUAGE: +NewInference
class Obj
fun foo(): String? {
run {
if (true) return@run
if (true) Obj()
}
run {
if (true) return@run
if (true) return Obj() // correct error, type check against return type of function "foo"
}
run {
if (true)
return@run
else
if (true) 42
}
run {
if (true)
42
else
if (true) 42
}
run {
if (true) return@run
if (true) {
Obj()
} else
if (true) return null
}
return ""
}
@@ -0,0 +1,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun coerceToUnit(f: () -> Unit) {}
class Inv<T>
fun <K> builder(block: Inv<K>.() -> Unit): K = TODO()
fun test() {
coerceToUnit {
builder {}
}
}
@@ -0,0 +1,26 @@
// !WITH_NEW_INFERENCE
fun <T> materialize(): T = TODO()
val a: () -> Unit = l@{
// Expected type 'Unit' is used here for inference
if (true) return@l materialize()
// Expected type here is Unit, but it also implies coercion,
// so we can end lambda body with statement
if (true) 42
}
val b: () -> Unit = l@{
// Error, coercion can't be applied at this position!
if (true) return@l "hello"
// However, this is OK, because here coercion is applied
"hello"
}
val c: () -> Unit = {
// Interesting enough, for such expessions we use expected type Unit
// (compare that with the previous case, where we didn't used expected type Unit for "hello")
materialize()
}
@@ -0,0 +1,13 @@
// !WITH_NEW_INFERENCE
fun <T : Number> materializeNumber(): T = TODO()
fun a(): Unit = run {
materializeNumber()
}
fun b(): Unit = run {
run {
materializeNumber()
}
}
@@ -0,0 +1,10 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_VARIABLE
fun foo() {
val f = myRun<Unit> {
123
}
}
fun <R> myRun(block: () -> R): R = block()
@@ -0,0 +1,19 @@
// !WITH_NEW_INFERENCE
fun <T> materialize(): T = TODO()
fun implicitCoercion() {
val a = {
// Block is implicitly Unit-coerced, so it is allowed to place statement at the end of lambda
if (true) 42
}
val b = l@{
return@l
}
val c = l@{
// Error: block doesn't have an expected type, so call can't be inferred!
return@l materialize()
}
}
@@ -0,0 +1,36 @@
// !WITH_NEW_INFERENCE
fun <T> materialize(): T = TODO()
fun a(): Unit = run {
run {
// Ok, block is coerced, because it has (indirectly) Unit-expected type
"hello"
}
}
fun b(): Unit = run {
// Ok, expected type is applied
materialize()
}
fun c(): Unit = run {
run {
// Attention!
// In OI expected type 'Unit' isn't applied here because of implementation quirks (note that OI still applies Unit in case 'e')
// In NI, it is applied and call is correctly inferred, which is consistent with the previous case
materialize()
}
}
fun d(): Unit = run outer@{
run inner@{
return@inner materialize()
}
}
fun e(): Unit = run outer@{
run inner@{
return@outer materialize()
}
}
@@ -0,0 +1,64 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-30242
class A
fun println(s: String = "") {}
fun foo(f: () -> Any) {}
fun test1(b: Boolean) {
foo {
if (b) {
println("meh")
}
}
}
fun test2(b: Boolean) {
foo {
when {
b -> println("meh")
}
}
}
fun test3(b: Boolean) {
foo {
if (b) {
return@foo A()
}
}
}
fun test4(b: Boolean) {
foo {
if (b) {
return@foo println("meh")
}
if (b) {
println()
}
}
}
fun bar(block: () -> String) {}
fun test_5(b: Boolean) {
bar {
if (b) {
println("meh")
}
}
}
fun test_6(b: Boolean) {
foo {
if (b) {
return@foo Unit
}
if (b) {}
}
}
@@ -0,0 +1,26 @@
// !WITH_NEW_INFERENCE
// !CHECK_TYPE
fun noCoercionLastExpressionUsedAsReturnArgument() {
val a = {
42
}
a checkType { <!UNRESOLVED_REFERENCE!>_<!><() -> Int>() }
}
fun noCoercionBlockHasExplicitType() {
val b: () -> Int = {
if (true) 42
}
}
fun noCoercionBlockHasExplicitReturn() {
val c = l@{
if (true) return@l 42
if (true) 239
}
}
fun noCoercionInExpressionBody(): Unit = "hello"
@@ -0,0 +1,52 @@
// !LANGUAGE: +NewInference
class Obj
fun foo(): String? {
run {
if (true) return@run
run {
if (true) {
Obj()
} else
if (true) return null // Error, coercion to Unit doesn't propagate inside nested lambdas
}
if (true) {
Obj()
} else
if (true) return null // OK, no error
}
run {
if (true) return@run
run {
if (true) {
Obj()
} else
if (true) return null // Error, coercion to Unit doesn't propagate inside nested lambdas
}
}
run {
if (true) return@run
run nestedRun@{
if (true) return@nestedRun
if (true) {
Obj()
} else
if (true) return null // OK, additional empty labeled return helps
}
if (true) {
Obj()
} else
if (true) return null // OK, no error
}
return ""
}