mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
Get rid of redundant not-null assertion for parameter
The problem was that in `Function<T>.apply(T)` T is now not-platform, so when checking if not-null assertion is needed for parameter in SAM, it's defined by the upper bounds of T that is a platform (Any..Any?), and while it's definitely not marked as nullable it's still nullable in a sense that it can contain null as a value. So the solution is obvious #KT-16413 Fixed
This commit is contained in:
21
compiler/testData/codegen/java8/box/functionAssertion.kt
vendored
Normal file
21
compiler/testData/codegen/java8/box/functionAssertion.kt
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// FILE: F.java
|
||||
import java.util.function.Function;
|
||||
|
||||
public class F {
|
||||
public static <T, U> U passNull(Function<? super T, ? extends U> f) {
|
||||
return f.apply(null);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
fun test(f: (Int?) -> String): String {
|
||||
return F.passNull(f)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return test {
|
||||
it?.toString() ?: "OK"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user