diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt b/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt index 92b2ed41703..c16999784fa 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt @@ -157,7 +157,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet val argumentsEntrySet = resolvedCall.getValueArguments().entrySet() if (argumentsEntrySet.isEmpty()) { - val function = unaryOperations[UnaryOperation(argumentForReceiver.ctcType, resultingDescriptorName)] + val function = unaryOperations[UnaryOperationKey(argumentForReceiver.ctcType, resultingDescriptorName)] if (function == null) return null return function(argumentForReceiver.value) } @@ -167,7 +167,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet val argumentForParameter = createOperationArgumentForFristParameter(argument, parameter) if (argumentForParameter == null) return null - val function = binaryOperations[BinaryOperation(argumentForReceiver.ctcType, argumentForParameter.ctcType, resultingDescriptorName)] + val function = binaryOperations[BinaryOperationKey(argumentForReceiver.ctcType, argumentForParameter.ctcType, resultingDescriptorName)] if (function == null) return null return function(argumentForReceiver.value, argumentForParameter.value) } @@ -399,3 +399,50 @@ private fun getReceiverExpressionType(resolvedCall: ResolvedCall<*>): JetType? { } } +private fun getCompileTimeType(c: JetType): CompileTimeType? { + val builtIns = KotlinBuiltIns.getInstance() + return when (TypeUtils.makeNotNullable(c)) { + builtIns.getIntType() -> INT + builtIns.getByteType() -> BYTE + builtIns.getShortType() -> SHORT + builtIns.getLongType() -> LONG + builtIns.getDoubleType() -> DOUBLE + builtIns.getFloatType() -> FLOAT + builtIns.getCharType() -> CHAR + builtIns.getBooleanType() -> BOOLEAN + builtIns.getStringType() -> STRING + builtIns.getAnyType() -> ANY + else -> null + } +} + +private class CompileTimeType + +private val BYTE = CompileTimeType() +private val SHORT = CompileTimeType() +private val INT = CompileTimeType() +private val LONG = CompileTimeType() +private val DOUBLE = CompileTimeType() +private val FLOAT = CompileTimeType() +private val CHAR = CompileTimeType() +private val BOOLEAN = CompileTimeType() +private val STRING = CompileTimeType() +private val ANY = CompileTimeType() + +[suppress("UNCHECKED_CAST")] +private fun binaryOperationKey( + a: CompileTimeType, + b: CompileTimeType, + functionName: String, + f: (A, B) -> Any +) = BinaryOperationKey(a, b, functionName) to f as Function2 + +[suppress("UNCHECKED_CAST")] +private fun unaryOperationKey( + a: CompileTimeType, + functionName: String, + f: (A) -> Any +) = UnaryOperationKey(a, functionName) to f as Function1 + +private data class BinaryOperationKey(val f: CompileTimeType, val s: CompileTimeType, val functionName: String) +private data class UnaryOperationKey(val f: CompileTimeType, val functionName: String) diff --git a/generators/src/org/jetbrains/jet/generators/evaluate/GenerateOperationsMap.kt b/generators/src/org/jetbrains/jet/generators/evaluate/GenerateOperationsMap.kt index 32377865fc0..8d19ea73d80 100644 --- a/generators/src/org/jetbrains/jet/generators/evaluate/GenerateOperationsMap.kt +++ b/generators/src/org/jetbrains/jet/generators/evaluate/GenerateOperationsMap.kt @@ -67,7 +67,7 @@ fun generate(): String { } } - p.println("private val unaryOperations = hashMapOf, (Any?) -> Any>(") + p.println("private val unaryOperations = hashMapOf, (Any?) -> Any>(") p.pushIndent() val unaryOperationsMapIterator = unaryOperationsMap.iterator() @@ -91,7 +91,7 @@ fun generate(): String { p.println() - p.println("private val binaryOperations = hashMapOf, (Any?, Any?) -> Any>(") + p.println("private val binaryOperations = hashMapOf, (Any?, Any?) -> Any>(") p.pushIndent() val binaryOperationsMapIterator = binaryOperationsMap.iterator()