JS backend: fixed compiler crash when use compareTo in infix call.
#EA-54661 fixed
This commit is contained in:
@@ -87,6 +87,10 @@ public final class OperatorOverloadingTest extends SingleFileTranslationTest {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testCompareToByName() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
|
||||
public void testPlusAndMinusAsAnExpression() throws Exception {
|
||||
fooBoxTest();
|
||||
|
||||
+14
-5
@@ -27,13 +27,18 @@ import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getCallableDescriptorForOperationExpression;
|
||||
import static org.jetbrains.k2js.translate.utils.ErrorReportingUtils.message;
|
||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.isCompareTo;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getOperationToken;
|
||||
|
||||
public final class CompareToTranslator extends AbstractTranslator {
|
||||
|
||||
public static boolean isCompareToCall(@NotNull JetBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
public static boolean isCompareToCall(
|
||||
@NotNull JetBinaryExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
if (!OperatorConventions.COMPARISON_OPERATIONS.contains(getOperationToken(expression))) return false;
|
||||
|
||||
CallableDescriptor operationDescriptor =
|
||||
getCallableDescriptorForOperationExpression(context.bindingContext(), expression);
|
||||
|
||||
@@ -51,13 +56,17 @@ public final class CompareToTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private final JetBinaryExpression expression;
|
||||
|
||||
private CompareToTranslator(@NotNull JetBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
private CompareToTranslator(
|
||||
@NotNull JetBinaryExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
super(context);
|
||||
this.expression = expression;
|
||||
CallableDescriptor descriptor = getCallableDescriptorForOperationExpression(context.bindingContext(), expression);
|
||||
assert descriptor != null : "CompareTo should always have a descriptor";
|
||||
assert (OperatorConventions.COMPARISON_OPERATIONS.contains(getOperationToken(expression)));
|
||||
assert (OperatorConventions.COMPARISON_OPERATIONS.contains(getOperationToken(expression))) :
|
||||
message(expression, "CompareToTranslator supported only expressions with operation token from COMPARISON_OPERATIONS, " +
|
||||
"expression: " + expression.getText());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
|
||||
class A(t: Int) {
|
||||
var i = t
|
||||
fun compareTo(other: A) = (this.i - other.i)
|
||||
}
|
||||
|
||||
fun box(): Boolean =
|
||||
(A(3) compareTo A(2) > 0) &&
|
||||
(A(2) compareTo A(2) == 0) &&
|
||||
(A(1) compareTo A(0) > 0) &&
|
||||
(A(3) compareTo A(4) < 0) &&
|
||||
(A(0) compareTo A(100) < 0)
|
||||
Reference in New Issue
Block a user