Files
kotlin-fork/j2k/testData/fileOrElement/nullability/LocalValReassignment.kt
T
Simon Ogorodnik a6e153312c Prevent early deleting of not-null assertions
Before val to var conversion applied, smart-cast can cause
dropping not-null assertion, which will be required when val will
become var
2017-06-07 21:21:37 +03:00

32 lines
768 B
Kotlin
Vendored

import org.jetbrains.annotations.*
internal class A {
/* rare nullable, handle with caution */
fun nullableString(): String? {
return if (Math.random() > 0.999) {
"a string"
} else null
}
fun takesNotNullString(s: String) {
println(s.substring(1))
}
fun aVoid() {
var aString: String?
if (nullableString() != null) {
aString = nullableString()
if (aString != null) {
for (i in 0..9) {
takesNotNullString(aString!!) // Bang-bang here
aString = nullableString()
}
} else {
aString = "aaa"
}
} else {
aString = "bbbb"
}
}
}