compareTo

This commit is contained in:
Andrey Breslav
2011-03-15 18:10:17 +03:00
parent 69f40ac81e
commit 469f02ef5a
3 changed files with 15 additions and 11 deletions
@@ -567,17 +567,17 @@ public class JetTypeInferrer {
result = null; // TODO : This is not an expression, in fact!
}
else if (comparisonOperations.contains(operationType)) {
JetExpression left = expression.getLeft();
JetExpression deparenthesized = deparenthesize(left);
if (deparenthesized instanceof JetArrayAccessExpression) {
JetArrayAccessExpression arrayAccessExpression = (JetArrayAccessExpression) deparenthesized;
resolveArrayAccessToLValue(arrayAccessExpression, expression.getRight(), expression.getOperationReference());
JetType compareToReturnType = getTypeForBinaryCall(expression, "compareTo", scope);
if (compareToReturnType != null) {
TypeConstructor constructor = compareToReturnType.getConstructor();
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
TypeConstructor intTypeConstructor = standardLibrary.getInt().getTypeConstructor();
if (constructor.equals(intTypeConstructor)) {
result = standardLibrary.getBooleanType();
} else {
semanticServices.getErrorHandler().structuralError(operationSign.getNode(), "compareTo must return Int, but returns " + compareToReturnType);
}
}
else {
getType(scope, expression.getRight(), false);
//throw new UnsupportedOperationException();
}
result = null; // TODO : This is not an expression, in fact!
} else {
semanticServices.getErrorHandler().structuralError(operationSign.getNode(), "Unknown operation");
}
@@ -59,5 +59,8 @@ fun <T> tt(t : T) : T {
`inc`++y
`dec`--y
y`dec`--
1 `std::Int.compareTo(Double)`> 2.0
1 `std::Int.compareTo(Double)`< 2.0
1 `std::Int.compareTo(Double)`>= 2.0
1 `std::Int.compareTo(Double)`<= 2.0
}
@@ -31,6 +31,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
nameToDescriptor.put("std::Int.plus(Int)", standardFunction(lib.getInt(), "plus", lib.getIntType()));
FunctionDescriptor descriptorForGet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "get", lib.getIntType());
nameToDescriptor.put("std::Array.get(Int)", descriptorForGet.getOriginal());
nameToDescriptor.put("std::Int.compareTo(Double)", standardFunction(lib.getInt(), "compareTo", lib.getDoubleType()));
@NotNull
FunctionDescriptor descriptorForSet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "set", lib.getIntType(), lib.getIntType());
nameToDescriptor.put("std::Array.set(Int, Int)", descriptorForSet.getOriginal());