diff --git a/compiler/src/prog8/ast/expressions/AstExpressions.kt b/compiler/src/prog8/ast/expressions/AstExpressions.kt index 82d18c349..470165321 100644 --- a/compiler/src/prog8/ast/expressions/AstExpressions.kt +++ b/compiler/src/prog8/ast/expressions/AstExpressions.kt @@ -18,6 +18,7 @@ import prog8.compiler.target.c64.Petscii import prog8.functions.BuiltinFunctions import prog8.functions.NotConstArgumentException import prog8.functions.builtinFunctionReturnType +import java.util.* import kotlin.math.abs @@ -316,7 +317,7 @@ class NumericLiteralValue(val type: DataType, // only numerical types allowed override fun inferType(program: Program) = type - override fun hashCode(): Int = type.hashCode() * 31 xor number.hashCode() + override fun hashCode(): Int = Objects.hash(type, number) override fun equals(other: Any?): Boolean { if(other==null || other !is NumericLiteralValue) @@ -457,11 +458,7 @@ class ReferenceLiteralValue(val type: DataType, // only reference types allo override fun inferType(program: Program) = type - override fun hashCode(): Int { - val sh = str?.hashCode() ?: 0x00014567 - val ah = array?.hashCode() ?: 0x11119876 - return sh * 31 xor ah xor type.hashCode() - } + override fun hashCode(): Int = Objects.hash(str, array, type) override fun equals(other: Any?): Boolean { if(other==null || other !is ReferenceLiteralValue) diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 87083170d..e1197f6f3 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -83,13 +83,7 @@ class HeapValues { return type==other.type && str==other.str && Arrays.equals(array, other.array) && Arrays.equals(doubleArray, other.doubleArray) } - override fun hashCode(): Int { - var result = type.hashCode() - result = 31 * result + (str?.hashCode() ?: 0) - result = 31 * result + (array?.let { Arrays.hashCode(it) } ?: 0) - result = 31 * result + (doubleArray?.let { Arrays.hashCode(it) } ?: 0) - return result - } + override fun hashCode(): Int = Objects.hash(str, array, doubleArray) val arraysize: Int = array?.size ?: doubleArray?.size ?: 0 } diff --git a/compiler/src/prog8/vm/RuntimeValue.kt b/compiler/src/prog8/vm/RuntimeValue.kt index ee9d054b3..67f5c52af 100644 --- a/compiler/src/prog8/vm/RuntimeValue.kt +++ b/compiler/src/prog8/vm/RuntimeValue.kt @@ -5,6 +5,7 @@ import prog8.ast.expressions.NumericLiteralValue import prog8.ast.expressions.ReferenceLiteralValue import prog8.compiler.HeapValues import prog8.compiler.target.c64.Petscii +import java.util.* import kotlin.math.abs import kotlin.math.pow @@ -154,12 +155,7 @@ open class RuntimeValue(val type: DataType, num: Number?=null, val str: String?= } } - override fun hashCode(): Int { - val bh = byteval?.hashCode() ?: 0x10001234 - val wh = wordval?.hashCode() ?: 0x01002345 - val fh = floatval?.hashCode() ?: 0x00103456 - return bh xor wh xor fh xor heapId.hashCode() xor type.hashCode() - } + override fun hashCode(): Int = Objects.hash(byteval, wordval, floatval, type) override fun equals(other: Any?): Boolean { if(other==null || other !is RuntimeValue)