Generate equals/hashCode(): Use class literals when possible

#KT-18683 Fixed
This commit is contained in:
Alexey Sedunov
2017-06-22 20:17:23 +03:00
parent 50a38df8b1
commit e3e4c447fa
11 changed files with 196 additions and 7 deletions
@@ -0,0 +1,8 @@
// PLATFORM: Common
class A(val n: Int, val s: String) {<caret>
val f: Float = 1.0f
fun foo() {
}
}
@@ -0,0 +1,28 @@
// PLATFORM: Common
class A(val n: Int, val s: String) {
val f: Float = 1.0f
fun foo() {
}
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || other::class != this::class) return false
other as A
if (n != other.n) return false
if (s != other.s) return false
if (f != other.f) return false
return true
}
override fun hashCode(): Int {
var result = n
result = 31 * result + s.hashCode()
result = 31 * result + f.hashCode()
return result
}
}
@@ -0,0 +1,8 @@
// PLATFORM: JavaScript
class A(val n: Int, val s: String) {<caret>
val f: Float = 1.0f
fun foo() {
}
}
@@ -0,0 +1,28 @@
// PLATFORM: JavaScript
class A(val n: Int, val s: String) {
val f: Float = 1.0f
fun foo() {
}
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || other::class.js != this::class.js) return false
other as A
if (n != other.n) return false
if (s != other.s) return false
if (f != other.f) return false
return true
}
override fun hashCode(): Int {
var result = n
result = 31 * result + s.hashCode()
result = 31 * result + f.hashCode()
return result
}
}
@@ -0,0 +1,6 @@
// PLATFORM: Common
class A {<caret>
fun foo() {
}
}
@@ -0,0 +1,16 @@
// PLATFORM: Common
class A {
fun foo() {
}
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || other::class != this::class) return false
return true
}
override fun hashCode(): Int {
return this::class.hashCode()
}
}
@@ -0,0 +1,6 @@
// PLATFORM: JavaScript
class A {<caret>
fun foo() {
}
}
@@ -0,0 +1,16 @@
// PLATFORM: JavaScript
class A {
fun foo() {
}
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || other::class.js != this::class.js) return false
return true
}
override fun hashCode(): Int {
return this::class.js.hashCode()
}
}