Files
kotlin-fork/compiler/testData/codegen/box/regressions/arrayLengthNPE.kt
T
Denis Zharkov 0905bf3e38 Refine redundant null checks interpreter
The main change here is addition of a check that NotNullBasicValue instances
are not being created for non-reference types

Exactly this change should be used instead of f25f0db10e
The latter commit lead to problem described in the KT-14242 issue:
v.getType().getSort() == w.getType().getSort() && (v.getType().getSort() != Type.OBJECT || v.equals(w))

Problem is that the condition above returns true without calling `v.equals(w)`,
because the sort of type is ARRAY, not OBJECT, so testArray was being treated
as NotNullable erroneously

So the second part of this change is effectively revering mentioned commit

 #KT-14242 Fixed
2016-10-10 10:44:11 +03:00

14 lines
257 B
Kotlin
Vendored

// See KT-14242
var x = 1
fun box(): String {
val testArray: Array<String?>? = when (1) {
x -> null
else -> arrayOfNulls<String>(0)
}
// Must not be NPE here
val size = testArray?.size
return size?.toString() ?: "OK"
}