diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java index ccc201b48a3..78ca676c10b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java @@ -80,7 +80,9 @@ public class IntrinsicMethods { for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) { String typeName = type.getTypeName().asString(); declareIntrinsicFunction(typeName, "plus", 0, UNARY_PLUS); + declareIntrinsicFunction(typeName, "unaryPlus", 0, UNARY_PLUS); declareIntrinsicFunction(typeName, "minus", 0, UNARY_MINUS); + declareIntrinsicFunction(typeName, "unaryMinus", 0, UNARY_MINUS); declareIntrinsicFunction(typeName, "inv", 0, INV); declareIntrinsicFunction(typeName, "rangeTo", 1, RANGE_TO); declareIntrinsicFunction(typeName, "inc", 0, INC); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt index 6838be43dae..77ad32c7834 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt @@ -455,7 +455,7 @@ private class ConstantExpressionEvaluatorVisitor( return result } assert(isIntegerType(receiver.value)) { "Only integer constants should be checked for overflow" } - assert(name == "minus") { "Only negation should be checked for overflow" } + assert(name == "minus" || name == "unaryMinus") { "Only negation should be checked for overflow" } if (receiver.value == result) { trace.report(Errors.INTEGER_OVERFLOW.on(callExpression.getStrictParentOfType() ?: callExpression)) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/OperationsMapGenerated.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/OperationsMapGenerated.kt index b1b585f14a2..35c7f7a0553 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/OperationsMapGenerated.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/OperationsMapGenerated.kt @@ -37,6 +37,8 @@ internal val unaryOperations: HashMap, Pair a.toInt() }, emptyUnaryFun), unaryOperation(BYTE, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(BYTE, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(BYTE, "unaryMinus", { a -> a.minus() }, { a -> a.minus() }), + unaryOperation(BYTE, "unaryPlus", { a -> a.plus() }, emptyUnaryFun), unaryOperation(BYTE, "toString", { a -> a.toString() }, emptyUnaryFun), unaryOperation(CHAR, "toByte", { a -> a.toByte() }, emptyUnaryFun), unaryOperation(CHAR, "toChar", { a -> a.toChar() }, emptyUnaryFun), @@ -55,6 +57,8 @@ internal val unaryOperations: HashMap, Pair a.toInt() }, emptyUnaryFun), unaryOperation(DOUBLE, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(DOUBLE, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(DOUBLE, "unaryMinus", { a -> a.minus() }, emptyUnaryFun), + unaryOperation(DOUBLE, "unaryPlus", { a -> a.plus() }, emptyUnaryFun), unaryOperation(DOUBLE, "toString", { a -> a.toString() }, emptyUnaryFun), unaryOperation(FLOAT, "minus", { a -> a.minus() }, emptyUnaryFun), unaryOperation(FLOAT, "plus", { a -> a.plus() }, emptyUnaryFun), @@ -65,6 +69,8 @@ internal val unaryOperations: HashMap, Pair a.toInt() }, emptyUnaryFun), unaryOperation(FLOAT, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(FLOAT, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(FLOAT, "unaryMinus", { a -> a.minus() }, emptyUnaryFun), + unaryOperation(FLOAT, "unaryPlus", { a -> a.plus() }, emptyUnaryFun), unaryOperation(FLOAT, "toString", { a -> a.toString() }, emptyUnaryFun), unaryOperation(INT, "inv", { a -> a.inv() }, emptyUnaryFun), unaryOperation(INT, "minus", { a -> a.minus() }, { a -> a.minus() }), @@ -76,6 +82,8 @@ internal val unaryOperations: HashMap, Pair a.toInt() }, emptyUnaryFun), unaryOperation(INT, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(INT, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(INT, "unaryMinus", { a -> a.minus() }, { a -> a.minus() }), + unaryOperation(INT, "unaryPlus", { a -> a.plus() }, emptyUnaryFun), unaryOperation(INT, "toString", { a -> a.toString() }, emptyUnaryFun), unaryOperation(LONG, "inv", { a -> a.inv() }, emptyUnaryFun), unaryOperation(LONG, "minus", { a -> a.minus() }, { a -> a.minus() }), @@ -87,6 +95,8 @@ internal val unaryOperations: HashMap, Pair a.toInt() }, emptyUnaryFun), unaryOperation(LONG, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(LONG, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(LONG, "unaryMinus", { a -> a.minus() }, { a -> a.minus() }), + unaryOperation(LONG, "unaryPlus", { a -> a.plus() }, emptyUnaryFun), unaryOperation(LONG, "toString", { a -> a.toString() }, emptyUnaryFun), unaryOperation(SHORT, "minus", { a -> a.minus() }, { a -> a.minus() }), unaryOperation(SHORT, "plus", { a -> a.plus() }, emptyUnaryFun), @@ -97,6 +107,8 @@ internal val unaryOperations: HashMap, Pair a.toInt() }, emptyUnaryFun), unaryOperation(SHORT, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(SHORT, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(SHORT, "unaryMinus", { a -> a.minus() }, { a -> a.minus() }), + unaryOperation(SHORT, "unaryPlus", { a -> a.plus() }, emptyUnaryFun), unaryOperation(SHORT, "toString", { a -> a.toString() }, emptyUnaryFun), unaryOperation(STRING, "length", { a -> a.length() }, emptyUnaryFun), unaryOperation(STRING, "toString", { a -> a.toString() }, emptyUnaryFun) diff --git a/generators/src/org/jetbrains/kotlin/generators/evaluate/GenerateOperationsMap.kt b/generators/src/org/jetbrains/kotlin/generators/evaluate/GenerateOperationsMap.kt index 088437b4503..d1b20181973 100644 --- a/generators/src/org/jetbrains/kotlin/generators/evaluate/GenerateOperationsMap.kt +++ b/generators/src/org/jetbrains/kotlin/generators/evaluate/GenerateOperationsMap.kt @@ -129,7 +129,7 @@ fun renderCheckUnaryOperation(name: String, params: List): String { } return when(name) { - "minus" -> "{ a -> a.$name() }" + "unaryMinus", "minus" -> "{ a -> a.$name() }" else -> "emptyUnaryFun" } } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveUnaryOperationFIF.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveUnaryOperationFIF.java index bd861357a13..9e54d80e341 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveUnaryOperationFIF.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveUnaryOperationFIF.java @@ -165,6 +165,12 @@ public enum PrimitiveUnaryOperationFIF implements FunctionIntrinsicFactory { return null; } + if (pattern("Char.unaryPlus()").apply(descriptor)) { + return CHAR_PLUS; + } + if (pattern("Char.unaryMinus()").apply(descriptor)) { + return CHAR_MINUS; + } if (pattern("Char.plus()").apply(descriptor)) { return CHAR_PLUS; }