diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index 639eb8f2ffd..c72043805a5 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -181,8 +181,8 @@ public final class Char : kotlin.Comparable { public final fun dec(): kotlin.Char public final fun inc(): kotlin.Char public final fun minus(/*0*/ other: kotlin.Char): kotlin.Int - kotlin.deprecated(value = "This operation will change return type to Char in M13. Either call toInt or toChar on return value or convert Char operand to Int.") public final fun minus(/*0*/ other: kotlin.Int): kotlin.Int - kotlin.deprecated(value = "This operation will change return type to Char in M13. Either call toInt or toChar on return value or convert Char operand to Int.") public final fun plus(/*0*/ other: kotlin.Int): kotlin.Int + public final fun minus(/*0*/ other: kotlin.Int): kotlin.Char + public final fun plus(/*0*/ other: kotlin.Int): kotlin.Char public final fun rangeTo(/*0*/ other: kotlin.Char): kotlin.CharRange public open fun toByte(): kotlin.Byte public open fun toChar(): kotlin.Char diff --git a/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt b/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt index dc7fce7169e..f6cf29b6555 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt @@ -151,8 +151,8 @@ private val binaryOperations: HashMap, Pair a.equals(b) }, emptyBinaryFun), binaryOperation(CHAR, CHAR, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), binaryOperation(CHAR, CHAR, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), - binaryOperation(CHAR, INT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), - binaryOperation(CHAR, INT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(CHAR, INT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(CHAR, INT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), binaryOperation(CHAR, ANY, "equals", { a, b -> a.equals(b) }, emptyBinaryFun), binaryOperation(DOUBLE, BYTE, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), binaryOperation(DOUBLE, DOUBLE, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), diff --git a/compiler/tests/org/jetbrains/kotlin/types/JetTypeCheckerTest.java b/compiler/tests/org/jetbrains/kotlin/types/JetTypeCheckerTest.java index 49afde88c79..0beede9467d 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/JetTypeCheckerTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/JetTypeCheckerTest.java @@ -434,8 +434,9 @@ public class JetTypeCheckerTest extends JetLiteFixture { assertType("1.plus(1.toLong())", "Long"); assertType("1.plus(1)", "Int"); - assertType("'1'.plus(1)", "Int"); - assertType("'1'.minus('1')", "Int"); // Plus is not available for char + assertType("'1'.plus(1)", "Char"); + assertType("'1'.minus(1)", "Char"); + assertType("'1'.minus('1')", "Int"); assertType("(1:Short).plus(1.toDouble())", "Double"); assertType("(1:Short).plus(1.toFloat())", "Float"); diff --git a/core/builtins/native/kotlin/Char.kt b/core/builtins/native/kotlin/Char.kt index ed2d8454d53..140094a91d3 100644 --- a/core/builtins/native/kotlin/Char.kt +++ b/core/builtins/native/kotlin/Char.kt @@ -30,15 +30,13 @@ public class Char private () : Comparable { */ public override fun compareTo(other: Char): Int - /** Adds the other value to this value. */ - deprecated("This operation will change return type to Char in M13. Either call toInt or toChar on return value or convert Char operand to Int.") - public fun plus(other: Int): Int + /** Adds the other Int value to this value resulting a Char. */ + public fun plus(other: Int): Char - /** Subtracts the other value from this value. */ + /** Subtracts the other Char value from this value resulting an Int. */ public fun minus(other: Char): Int - /** Subtracts the other value from this value. */ - deprecated("This operation will change return type to Char in M13. Either call toInt or toChar on return value or convert Char operand to Int.") - public fun minus(other: Int): Int + /** Subtracts the other Int value from this value resulting a Char. */ + public fun minus(other: Int): Char /** Increments this value. */ public fun inc(): Char diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveBinaryOperationFIF.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveBinaryOperationFIF.java index dddc90a77d0..90df880ebfa 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveBinaryOperationFIF.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveBinaryOperationFIF.java @@ -134,14 +134,6 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory { @Nullable @Override public FunctionIntrinsic getIntrinsic(@NotNull FunctionDescriptor descriptor) { - if (pattern("Int|Short|Byte|Double|Float.compareTo(Char)").apply(descriptor)) { - return new WithCharAsSecondOperandFunctionIntrinsic(PRIMITIVE_NUMBER_COMPARE_TO_INTRINSIC); - } - - if (pattern("Char.compareTo(Int|Short|Byte|Double|Float)").apply(descriptor)) { - return new WithCharAsFirstOperandFunctionIntrinsic(PRIMITIVE_NUMBER_COMPARE_TO_INTRINSIC); - } - if (pattern("Char.rangeTo(Char)").apply(descriptor)) { return CHAR_RANGE_TO_INTRINSIC; } @@ -161,13 +153,7 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory { if (pattern("Int|Short|Byte.div(Int|Short|Byte)").apply(descriptor)) { - return INTEGER_DIVISION_INTRINSIC; - } - if (pattern("Char.div(Int|Short|Byte)").apply(descriptor)) { - return new WithCharAsFirstOperandFunctionIntrinsic(INTEGER_DIVISION_INTRINSIC); - } - if (pattern("Int|Short|Byte.div(Char)").apply(descriptor)) { - return new WithCharAsSecondOperandFunctionIntrinsic(INTEGER_DIVISION_INTRINSIC); + return INTEGER_DIVISION_INTRINSIC; } if (descriptor.getName().equals(Name.identifier("rangeTo"))) { return RANGE_TO_INTRINSIC; @@ -181,11 +167,11 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory { JsBinaryOperator operator = getOperator(descriptor); BinaryOperationInstrinsicBase result = new PrimitiveBinaryOperationFunctionIntrinsic(operator); - if (pattern("Char.plus|minus|times|div|mod(Int|Short|Byte|Double|Float)").apply(descriptor)) { - return new WithCharAsFirstOperandFunctionIntrinsic(result); + if (pattern("Char.plus|minus(Int)").apply(descriptor)) { + return new CharAndIntBinaryOperationFunctionIntrinsic(result); } - if (pattern("Int|Short|Byte|Double|Float.plus|minus|times|div|mod(Char)").apply(descriptor)) { - return new WithCharAsSecondOperandFunctionIntrinsic(result); + if (pattern("Char.minus(Char)").apply(descriptor)) { + return new CharAndCharBinaryOperationFunctionIntrinsic(result); } return result; } @@ -219,35 +205,35 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory { } } - private static class WithCharAsFirstOperandFunctionIntrinsic extends BinaryOperationInstrinsicBase { + private static class CharAndIntBinaryOperationFunctionIntrinsic extends BinaryOperationInstrinsicBase { @NotNull private final BinaryOperationInstrinsicBase functionIntrinsic; - private WithCharAsFirstOperandFunctionIntrinsic(@NotNull BinaryOperationInstrinsicBase functionIntrinsic) { + private CharAndIntBinaryOperationFunctionIntrinsic(@NotNull BinaryOperationInstrinsicBase functionIntrinsic) { this.functionIntrinsic = functionIntrinsic; } @NotNull @Override public JsExpression doApply(@NotNull JsExpression left, @NotNull JsExpression right, @NotNull TranslationContext context) { - return functionIntrinsic.doApply(JsAstUtils.charToInt(left), right, context); + return JsAstUtils.toChar(functionIntrinsic.doApply(JsAstUtils.charToInt(left), right, context)); } } - private static class WithCharAsSecondOperandFunctionIntrinsic extends BinaryOperationInstrinsicBase { + private static class CharAndCharBinaryOperationFunctionIntrinsic extends BinaryOperationInstrinsicBase { @NotNull private final BinaryOperationInstrinsicBase functionIntrinsic; - private WithCharAsSecondOperandFunctionIntrinsic(@NotNull BinaryOperationInstrinsicBase functionIntrinsic) { + private CharAndCharBinaryOperationFunctionIntrinsic(@NotNull BinaryOperationInstrinsicBase functionIntrinsic) { this.functionIntrinsic = functionIntrinsic; } @NotNull @Override public JsExpression doApply(@NotNull JsExpression left, @NotNull JsExpression right, @NotNull TranslationContext context) { - return functionIntrinsic.doApply(left, JsAstUtils.charToInt(right), context); + return functionIntrinsic.doApply(JsAstUtils.charToInt(left), JsAstUtils.charToInt(right), context); } } } diff --git a/js/js.translator/testData/char/cases/charBinaryOperations.kt b/js/js.translator/testData/char/cases/charBinaryOperations.kt index 2845cf16db8..aaca3495760 100644 --- a/js/js.translator/testData/char/cases/charBinaryOperations.kt +++ b/js/js.translator/testData/char/cases/charBinaryOperations.kt @@ -2,10 +2,10 @@ package foo fun box(): String { - assertEquals(75, 'A' + 10) - assertEquals(55, 'A' - 10) + assertEquals('K', 'A' + 10) + assertEquals('7', 'A' - 10) - assertEquals(4, '4' - '0') + assertEquals(3, 'd' - 'a') return "OK" } \ No newline at end of file