Handling safe calls of multi-statement function

This commit is contained in:
Valentin Kipyatkov
2016-10-23 01:52:45 +03:00
parent 330d3a255a
commit 08c6a21ac1
4 changed files with 57 additions and 9 deletions
@@ -0,0 +1,11 @@
fun String.<caret>f(p: Int): Int {
println(p)
return hashCode() * p
}
fun f(s: String?) {
s?.f(1)
s?.substring(1)?.f(2)
val s1 = s?.f(3)
val s2 = s?.substring(1)?.f(4)
}
@@ -0,0 +1,19 @@
fun f(s: String?) {
if (s != null) {
println(1)
s.hashCode() * 1
}
val substring = s?.substring(1)
if (substring != null) {
println(2)
substring.hashCode() * 2
}
val s1 = s?.let {
println(3)
it.hashCode() * 3
}
val s2 = s?.substring(1)?.let {
println(4)
it.hashCode() * 4
}
}