From 5e97517c8bc859cc06fe1981578561912bc9774f Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 29 Dec 2017 12:13:40 +0100 Subject: [PATCH] Fix bug in StringValue.equals Also simplify equals() implementations of other constant values --- .../resolve/constants/constantValues.kt | 33 +++---------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt index 9c6aed11b1b..ab016e64dc3 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt @@ -55,15 +55,7 @@ class ArrayValue( override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitArrayValue(this, data) - val elementType: KotlinType - get() = builtIns.getArrayElementType(type) - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - - return value == (other as ArrayValue).value - } + override fun equals(other: Any?): Boolean = this === other || value == (other as? ArrayValue)?.value override fun hashCode() = value.hashCode() } @@ -144,12 +136,7 @@ class EnumValue( override fun toString() = "$type.${value.name}" - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - - return value == (other as EnumValue).value - } + override fun equals(other: Any?): Boolean = this === other || value == (other as? EnumValue)?.value override fun hashCode() = value.hashCode() } @@ -196,14 +183,7 @@ class IntValue( override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitIntValue(this, data) - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - - val intValue = other as IntValue - - return value == intValue.value - } + override fun equals(other: Any?): Boolean = this === other || value == (other as? IntValue)?.value override fun hashCode() = value } @@ -261,12 +241,7 @@ class StringValue( override fun toString() = "\"$value\"" - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - - return value != (other as StringValue).value - } + override fun equals(other: Any?): Boolean = this === other || value == (other as? StringValue)?.value override fun hashCode() = value.hashCode() }