Use identity equals in lazy unescape.
#KT-7474 Fixed
This commit is contained in:
@@ -158,7 +158,7 @@ private fun escape(value: Any?): Any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun unescape(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> {
|
private class LazyVal<T>(private val initializer: () -> T) : ReadOnlyProperty<Any?, T> {
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ class LazyValuesTest(): DelegationTestBase() {
|
|||||||
test fun testVolatileLazyVal() {
|
test fun testVolatileLazyVal() {
|
||||||
doTest(TestVolatileLazyVal())
|
doTest(TestVolatileLazyVal())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test fun testIdentityEqualsIsUsedToUnescapeLazyVal() {
|
||||||
|
doTest(TestIdentityEqualsIsUsedToUnescapeLazyVal())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestLazyVal: WithBox {
|
class TestLazyVal: WithBox {
|
||||||
@@ -142,3 +146,22 @@ class TestAtomicNullableLazyVal: WithBox {
|
|||||||
return null
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user