Use identity equals in lazy unescape.

#KT-7474 Fixed
This commit is contained in:
Ilya Gorbunov
2015-06-10 21:25:58 +03:00
parent 3266d8c29a
commit fb6c7e20de
2 changed files with 24 additions and 1 deletions
@@ -158,7 +158,7 @@ private fun escape(value: Any?): Any {
}
private fun unescape(value: Any?): Any? {
return if (value == NULL_VALUE) null else value
return if (value === NULL_VALUE) null else value
}
private class LazyVal<T>(private val initializer: () -> T) : ReadOnlyProperty<Any?, T> {
@@ -30,6 +30,10 @@ class LazyValuesTest(): DelegationTestBase() {
test fun testVolatileLazyVal() {
doTest(TestVolatileLazyVal())
}
test fun testIdentityEqualsIsUsedToUnescapeLazyVal() {
doTest(TestIdentityEqualsIsUsedToUnescapeLazyVal())
}
}
class TestLazyVal: WithBox {
@@ -142,3 +146,22 @@ class TestAtomicNullableLazyVal: WithBox {
return null
}
}
class TestIdentityEqualsIsUsedToUnescapeLazyVal: WithBox {
var equalsCalled = 0
val a by Delegates.lazy { ClassWithCustomEquality { equalsCalled++ } }
override fun box(): String {
a
a
if (equalsCalled > 0) return "fail: equals called $equalsCalled times."
return "OK"
}
}
private class ClassWithCustomEquality(private val onEqualsCalled: () -> Unit) {
override fun equals(other: Any?): Boolean {
onEqualsCalled()
return super.equals(other)
}
}