Change return type of Char plus Int and Char minus Int binary operations.
JS: Remove unnecessary intrinsic binary operation patterns, adjust intrinsics for binary operations with char.
This commit is contained in:
+2
-2
@@ -181,8 +181,8 @@ public final class Char : kotlin.Comparable<kotlin.Char> {
|
||||
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
|
||||
|
||||
+2
-2
@@ -151,8 +151,8 @@ private val binaryOperations: HashMap<BinaryOperationKey<*, *>, Pair<Function2<A
|
||||
binaryOperation(BYTE, ANY, "equals", { a, b -> 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.<!DEPRECATED_SYMBOL_WITH_MESSAGE!>minus<!>(b) }, emptyBinaryFun),
|
||||
binaryOperation(CHAR, INT, "plus", { a, b -> a.<!DEPRECATED_SYMBOL_WITH_MESSAGE!>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),
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -30,15 +30,13 @@ public class Char private () : Comparable<Char> {
|
||||
*/
|
||||
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
|
||||
|
||||
+11
-25
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user