Add hashCode, equals and toString methods from String in builtin map

This commit is contained in:
Ivan Kylchik
2020-03-26 17:35:52 +03:00
parent 82acf7deb6
commit 900e78b39b
2 changed files with 5 additions and 2 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 JetBrains s.r.o.
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -116,6 +116,8 @@ val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
unaryOperation<Double>("unaryMinus", "Double") { a -> a.unaryMinus() },
unaryOperation<Double>("unaryPlus", "Double") { a -> a.unaryPlus() },
unaryOperation<String>("length", "String") { a -> a.length },
unaryOperation<String>("hashCode", "String") { a -> a.hashCode() },
unaryOperation<String>("toString", "String") { a -> a.toString() },
unaryOperation<BooleanArray>("size", "BooleanArray") { a -> a.size },
unaryOperation<BooleanArray>("iterator", "BooleanArray") { a -> a.iterator() },
unaryOperation<CharArray>("size", "CharArray") { a -> a.size },
@@ -404,6 +406,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any?>>(
binaryOperation<Double, Long>("times", "Double", "Long") { a, b -> a.times(b) },
binaryOperation<Double, Short>("times", "Double", "Short") { a, b -> a.times(b) },
binaryOperation<String, String>("compareTo", "String", "String") { a, b -> a.compareTo(b) },
binaryOperation<String, Any?>("equals", "String", "Any?") { a, b -> a.equals(b) },
binaryOperation<String, Int>("get", "String", "Int") { a, b -> a.get(b) },
binaryOperation<String, Any?>("plus", "String", "Any?") { a, b -> a.plus(b) },
binaryOperation<BooleanArray, Int>("get", "BooleanArray", "Int") { a, b -> a.get(b) },
+1 -1
View File
@@ -91,7 +91,7 @@ private fun getOperationMap(argumentsCount: Int): MutableMap<CallableDescriptor,
fun CallableDescriptor.isCompileTime(classDescriptor: ClassDescriptor): Boolean {
val thisIsCompileTime = this.annotations.hasAnnotation(compileTimeAnnotation)
val classIsCompileTime = classDescriptor.annotations.hasAnnotation(compileTimeAnnotation)
val isPrimitive = KotlinBuiltIns.isPrimitiveClass(classDescriptor)
val isPrimitive = KotlinBuiltIns.isPrimitiveClass(classDescriptor) || KotlinBuiltIns.isString(classDescriptor.defaultType)
val isFakeOverridden = (this as? FunctionDescriptor)?.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE
return when {
isPrimitive -> thisIsCompileTime || classIsCompileTime