diff --git a/libraries/stdlib/src/kotlin/properties/Delegation.kt b/libraries/stdlib/src/kotlin/properties/Delegation.kt index 90e03b515c1..9398428f9d2 100644 --- a/libraries/stdlib/src/kotlin/properties/Delegation.kt +++ b/libraries/stdlib/src/kotlin/properties/Delegation.kt @@ -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(private val initializer: () -> T) : ReadOnlyProperty { diff --git a/libraries/stdlib/test/properties/delegation/lazy/LazyValuesTest.kt b/libraries/stdlib/test/properties/delegation/lazy/LazyValuesTest.kt index 21b0c1f121f..6bec3bd385f 100644 --- a/libraries/stdlib/test/properties/delegation/lazy/LazyValuesTest.kt +++ b/libraries/stdlib/test/properties/delegation/lazy/LazyValuesTest.kt @@ -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) + } +} \ No newline at end of file