[FIR] Add NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY diagnostic
This commit is contained in:
committed by
teamcityserver
parent
151478aa27
commit
a6984c5198
+1
-1
@@ -268,7 +268,7 @@ class Main<L>(x: L?, y: L) {
|
||||
}
|
||||
|
||||
fun <T : Comparable<T>> nullsLast() = null as Foo<T?>
|
||||
fun <K> take(x: Foo<K>, comparator: Foo<K>): Foo<K> {}
|
||||
fun <K> take(x: Foo<K>, comparator: Foo<K>): Foo<K> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
fun <L> test() {
|
||||
take(null as Foo<String?>, nullsLast())
|
||||
}
|
||||
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package b
|
||||
//+JDK
|
||||
|
||||
import java.util.*
|
||||
import java.util.Collections.*
|
||||
|
||||
fun foo(list: List<String>) : String {
|
||||
val w : String = max(list, comparator<String?> {o1, o2 -> 1
|
||||
})
|
||||
return w
|
||||
}
|
||||
|
||||
//from library
|
||||
fun <T> comparator(fn: (T,T) -> Int): Comparator<T> {}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
package b
|
||||
//+JDK
|
||||
|
||||
|
||||
@@ -31,6 +31,6 @@ fun foo() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||
|
||||
infix fun <T, R> Array<T>.map(transform : (T) -> R) : List<R> {}
|
||||
infix fun <T, R> Array<T>.map(transform : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
infix fun <T, R> Iterable<T>.map(transform : (T) -> R) : List<R> {}
|
||||
infix fun <T, R> Iterable<T>.map(transform : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
+2
-2
@@ -6,8 +6,8 @@ package i
|
||||
import java.util.*
|
||||
import checkSubtype
|
||||
|
||||
fun <T, R> Collection<T>.map1(f : (T) -> R) : List<R> {}
|
||||
fun <T, R> java.lang.Iterable<T>.map1(f : (T) -> R) : List<R> {}
|
||||
fun <T, R> Collection<T>.map1(f : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
fun <T, R> java.lang.Iterable<T>.map1(f : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
fun test(list: List<Int>) {
|
||||
val res = list.map1 { it }
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package a
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun <T> g (f: () -> List<T>) : T {}
|
||||
fun <T> g (f: () -> List<T>) : T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
fun test() {
|
||||
//here possibly can be a cycle on constraints
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-1029 Wrong type inference
|
||||
package i
|
||||
|
||||
import checkSubtype
|
||||
|
||||
public fun<T> from(yielder: ()->Iterable<T>) : Iterable<T> {
|
||||
}
|
||||
|
||||
public infix fun<T> Iterable<T>.where(predicate : (T)->Boolean) : ()->Iterable<T> {
|
||||
}
|
||||
|
||||
fun a() {
|
||||
val x = 0..200
|
||||
val odd = from (x where {it%2==0}) // I believe it should infer here
|
||||
|
||||
checkSubtype<Iterable<Int>>(odd)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-1029 Wrong type inference
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-1031 Can't infer type of `it` with two lambdas
|
||||
package i
|
||||
|
||||
import java.util.ArrayList
|
||||
import checkSubtype
|
||||
|
||||
public infix fun<TItem> Iterable<TItem>.where(predicate : (TItem)->Boolean) : ()->Iterable<TItem> {
|
||||
}
|
||||
|
||||
public fun<TItem, TResult> select(yielder: ()->Iterable<TItem>, selector : (TItem)->TResult) : ()->Iterable<TResult> {
|
||||
}
|
||||
|
||||
fun a() {
|
||||
val x = 0..200
|
||||
val z = x where { i: Int -> i % 2 == 0 }
|
||||
val yielder = select(x where { it%2==0 }, { it.toString() })
|
||||
|
||||
checkSubtype<() -> Iterable<Int>>(z)
|
||||
checkSubtype<() -> Iterable<String>>(yielder)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-1031 Can't infer type of `it` with two lambdas
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
package d
|
||||
|
||||
fun <T> asList(t: T) : List<T>? {}
|
||||
fun <T> asList(t: T) : List<T>? {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
fun main() {
|
||||
val list : List<String> = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>asList("")<!>
|
||||
|
||||
@@ -12,6 +12,6 @@ fun test(numbers: Iterable<Int>) {
|
||||
}
|
||||
|
||||
//from library
|
||||
fun <T, R> Iterable<T>.map(transform : (T) -> R) : List<R> {}
|
||||
fun <T, R> Iterable<T>.map(transform : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {}
|
||||
fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
// KT-1410 Compiler does automatically infer type argument when using variance
|
||||
//+JDK
|
||||
package d
|
||||
|
||||
import checkSubtype
|
||||
|
||||
public fun <T> MutableCollection<out T>.filterToMy(result : MutableList<in T>, filter : (T) -> Boolean) : MutableCollection<out T> {
|
||||
for (t in this){
|
||||
if (filter(t)){
|
||||
result.add(t)
|
||||
}
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun foo(result: MutableList<in String>, collection: MutableCollection<String>, prefix : String){
|
||||
collection.filterToMy(result, {it.startsWith(prefix)})
|
||||
}
|
||||
|
||||
fun test(result: MutableList<in Any>, collection: MutableCollection<String>, prefix : String){
|
||||
val c = collection.filterToMy(result, {it.startsWith(prefix)})
|
||||
checkSubtype<MutableCollection<out String>>(c)
|
||||
}
|
||||
|
||||
//from library
|
||||
fun String.startsWith(prefix: String) : Boolean {}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !CHECK_TYPE
|
||||
|
||||
// KT-1410 Compiler does automatically infer type argument when using variance
|
||||
|
||||
@@ -14,5 +14,5 @@ fun test() {
|
||||
}
|
||||
|
||||
//from library
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> {}
|
||||
operator fun <T> Iterable<T>.plus(elements: Iterable<T>): List<T> {}
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
operator fun <T> Iterable<T>.plus(elements: Iterable<T>): List<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
@@ -24,4 +24,4 @@ abstract class Buggy {
|
||||
}
|
||||
|
||||
//from library
|
||||
fun <T: Any> Iterable<T>.find(predicate: (T) -> Boolean) : T? {}
|
||||
fun <T: Any> Iterable<T>.find(predicate: (T) -> Boolean) : T? {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
@@ -12,8 +12,8 @@ fun test() {
|
||||
}
|
||||
|
||||
//from library
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> {}
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
fun <T, R> Collection<T>.map(transform : (T) -> R) : List<R> {}
|
||||
fun <T, R> Collection<T>.map(transform : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {}
|
||||
fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
//KT-2459 Type inference error
|
||||
package b
|
||||
|
||||
import java.util.*
|
||||
|
||||
class B<T>(val x: List<T>)
|
||||
fun <T> f(x: T): B<T> = B(arrayList(x))
|
||||
|
||||
// from standard library
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> {}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//KT-2459 Type inference error
|
||||
package b
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package c
|
||||
|
||||
interface A<T>
|
||||
|
||||
fun test(a: A<Int>?) {
|
||||
a<!UNSAFE_CALL!>.<!>foo() //no error
|
||||
}
|
||||
|
||||
fun <R> A<R>.foo() {}
|
||||
|
||||
//------------
|
||||
fun test(nullabilityInfoMap: Map<Int, Any>?) {
|
||||
nullabilityInfoMap<!UNSAFE_CALL!>.<!>iterator() //no error
|
||||
}
|
||||
|
||||
//resolves to
|
||||
public fun <K,V> Map<K,V>.iterator(): Iterator<Map.Entry<K,V>> {}
|
||||
|
||||
|
||||
//-------------
|
||||
fun foo() : Boolean {
|
||||
val nullableList = getNullableList()
|
||||
return nullableList<!UNSAFE_CALL!>.<!>contains("")
|
||||
|
||||
}
|
||||
|
||||
fun getNullableList(): List<String>? = null
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
package c
|
||||
|
||||
interface A<T>
|
||||
|
||||
@@ -8,7 +8,7 @@ class Y<TItem>(val itemToString: (TItem) -> String){
|
||||
}
|
||||
|
||||
fun <TItem> bar(context : Y<TItem>) : TItem{
|
||||
}
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
fun foo(){
|
||||
val stringToString : (String) -> String = { it }
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
//KT-3007 Kotlin plugin 0.4.126 does not compile KAnnotator revision ba0a93eb
|
||||
package a
|
||||
|
||||
enum class SomeEnum {
|
||||
FIRST,
|
||||
SECOND
|
||||
}
|
||||
|
||||
// Doesn't work
|
||||
fun Iterable<Int>.some() {
|
||||
this.fold(SomeEnum.FIRST, {res : SomeEnum, value ->
|
||||
if (res == SomeEnum.FIRST) SomeEnum.FIRST else SomeEnum.SECOND
|
||||
})
|
||||
}
|
||||
|
||||
fun tempFun() : SomeEnum {
|
||||
return SomeEnum.FIRST
|
||||
}
|
||||
|
||||
// Doesn't work
|
||||
fun Iterable<Int>.someSimpleWithFun() {
|
||||
this.fold(SomeEnum.FIRST, {res : SomeEnum, value ->
|
||||
tempFun()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// Works
|
||||
fun Iterable<Int>.someSimple() {
|
||||
this.fold(SomeEnum.FIRST, {res : SomeEnum, value ->
|
||||
SomeEnum.FIRST
|
||||
})
|
||||
}
|
||||
|
||||
// Works
|
||||
fun Iterable<Int>.someInt() {
|
||||
this.fold(0, {res : Int, value ->
|
||||
if (res == 0) 1 else 0
|
||||
})
|
||||
}
|
||||
|
||||
//from standard library
|
||||
fun <T,R> Iterable<T>.fold(initial: R, operation: (R, T) -> R): R {}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//KT-3007 Kotlin plugin 0.4.126 does not compile KAnnotator revision ba0a93eb
|
||||
package a
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
//KT-3301 Inference with several supertypes fails
|
||||
|
||||
package arrays
|
||||
|
||||
interface A
|
||||
interface B
|
||||
|
||||
object CAB : A, B
|
||||
object DAB : A, B
|
||||
|
||||
fun m(args : Array<A>) {
|
||||
|
||||
}
|
||||
|
||||
fun test122() {
|
||||
m(array(CAB, DAB)) // Wrong error here: Array<Any> is inferred while expected Array<A> is satisfied
|
||||
}
|
||||
|
||||
//from library
|
||||
fun <T> array(vararg t: T): Array<T> {}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//KT-3301 Inference with several supertypes fails
|
||||
|
||||
package arrays
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package a
|
||||
//+JDK
|
||||
|
||||
fun <T> getJavaClass() : java.lang.Class<T> { }
|
||||
fun <T> getJavaClass() : java.lang.Class<T> { <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
public class Throwables() {
|
||||
companion object {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-943 Type inference failed
|
||||
package maze
|
||||
|
||||
//+JDK
|
||||
import java.util.Collections.*
|
||||
import java.util.*
|
||||
import checkSubtype
|
||||
|
||||
fun foo(lines: List<String>) {
|
||||
val w = max(lines, comparator {o1, o2 ->
|
||||
val l1 : Int = o1.length // Types of o1 and o2 are ERROR
|
||||
val l2 = o2.length
|
||||
l1 - l2
|
||||
}).sure()
|
||||
checkSubtype<String>(w)
|
||||
}
|
||||
|
||||
//standard library
|
||||
fun <T : Any> T?.sure() : T = this!!
|
||||
|
||||
public inline fun <T> comparator(fn: (T,T) -> Int): Comparator<T> {}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-943 Type inference failed
|
||||
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package a
|
||||
|
||||
fun <R> foo (f: ()->R, r: MutableList<R>) = r.add(f())
|
||||
fun <R> bar (r: MutableList<R>, f: ()->R) = r.add(f())
|
||||
|
||||
fun test() {
|
||||
val a = foo({1}, arrayListOf("")) //no type inference error on 'arrayListOf'
|
||||
val b = bar(arrayListOf(""), {1})
|
||||
}
|
||||
|
||||
// from standard library
|
||||
fun <T> arrayListOf(vararg values: T) : MutableList<T> {}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
package a
|
||||
|
||||
fun <R> foo (f: ()->R, r: MutableList<R>) = r.add(f())
|
||||
|
||||
Vendored
+1
-1
@@ -19,4 +19,4 @@ fun test(a: Any, s: MutableSet<String>) {
|
||||
}
|
||||
|
||||
//from standard library
|
||||
fun <T> arrayListOf(vararg t: T): MutableList<T> {}
|
||||
fun <T> arrayListOf(vararg t: T): MutableList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
Reference in New Issue
Block a user