Equality applicability check for === and !==
This commit is contained in:
@@ -19,7 +19,7 @@ class Boolean : Comparable<Boolean> {
|
|||||||
|
|
||||||
fun xor(other : Boolean) : Boolean
|
fun xor(other : Boolean) : Boolean
|
||||||
|
|
||||||
fun equals(other : Boolean?) : Boolean
|
fun equals(other : Any?) : Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
class String : Comparable<String> {
|
class String : Comparable<String> {
|
||||||
@@ -27,6 +27,7 @@ class String : Comparable<String> {
|
|||||||
val length : Int
|
val length : Int
|
||||||
|
|
||||||
fun plus(other : Any?) : String
|
fun plus(other : Any?) : String
|
||||||
|
fun equals(other : Any?) : Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
class Range<in T : Comparable<T>> {
|
class Range<in T : Comparable<T>> {
|
||||||
|
|||||||
@@ -959,17 +959,13 @@ public class JetTypeInferrer {
|
|||||||
JetType equalsType = getTypeForBinaryCall(expression, name, scope, true);
|
JetType equalsType = getTypeForBinaryCall(expression, name, scope, true);
|
||||||
result = assureBooleanResult(operationSign, name, equalsType);
|
result = assureBooleanResult(operationSign, name, equalsType);
|
||||||
|
|
||||||
// Assure that the types on the left and on the right have nonempty intersection
|
ensureNonemptyIntersectionOfOperandTypes(expression);
|
||||||
if (right != null) {
|
}
|
||||||
// TODO : duplicated effort
|
else if (operationType == JetTokens.EQEQEQ || operationType == JetTokens.EXCLEQEQEQ) {
|
||||||
JetType leftType = getType(scope, left, false);
|
ensureNonemptyIntersectionOfOperandTypes(expression);
|
||||||
JetType rightType = getType(scope, right, false);
|
|
||||||
|
|
||||||
JetType intersect = TypeUtils.intersect(semanticServices.getTypeChecker(), new HashSet<JetType>(Arrays.asList(leftType, rightType)));
|
// TODO : Check comparison pointlessness
|
||||||
if (intersect == null) {
|
result = semanticServices.getStandardLibrary().getBooleanType();
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "Operator " + operationSign.getReferencedName() + " cannot be applied to " + leftType + " and " + rightType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (inOperations.contains(operationType)) {
|
else if (inOperations.contains(operationType)) {
|
||||||
if (right == null) {
|
if (right == null) {
|
||||||
@@ -980,12 +976,6 @@ public class JetTypeInferrer {
|
|||||||
JetType containsType = getTypeForBinaryCall(scope, right, expression.getOperationReference(), expression.getLeft(), name, true);
|
JetType containsType = getTypeForBinaryCall(scope, right, expression.getOperationReference(), expression.getLeft(), name, true);
|
||||||
result = assureBooleanResult(operationSign, name, containsType);
|
result = assureBooleanResult(operationSign, name, containsType);
|
||||||
}
|
}
|
||||||
else if (operationType == JetTokens.EQEQEQ || operationType == JetTokens.EXCLEQEQEQ) {
|
|
||||||
JetType leftType = getType(scope, left, false);
|
|
||||||
JetType rightType = right == null ? null : getType(scope, right, false);
|
|
||||||
// TODO : Check comparison pointlessness
|
|
||||||
result = semanticServices.getStandardLibrary().getBooleanType();
|
|
||||||
}
|
|
||||||
else if (operationType == JetTokens.ANDAND || operationType == JetTokens.OROR) {
|
else if (operationType == JetTokens.ANDAND || operationType == JetTokens.OROR) {
|
||||||
JetType leftType = getType(scope, left, false);
|
JetType leftType = getType(scope, left, false);
|
||||||
JetType rightType = right == null ? null : getType(scope, right, false);
|
JetType rightType = right == null ? null : getType(scope, right, false);
|
||||||
@@ -1015,6 +1005,23 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureNonemptyIntersectionOfOperandTypes(JetBinaryExpression expression) {
|
||||||
|
JetSimpleNameExpression operationSign = expression.getOperationReference();
|
||||||
|
JetExpression left = expression.getLeft();
|
||||||
|
JetExpression right = expression.getRight();
|
||||||
|
|
||||||
|
// TODO : duplicated effort for == and !=
|
||||||
|
JetType leftType = getType(scope, left, false);
|
||||||
|
if (right != null) {
|
||||||
|
JetType rightType = getType(scope, right, false);
|
||||||
|
|
||||||
|
JetType intersect = TypeUtils.intersect(semanticServices.getTypeChecker(), new HashSet<JetType>(Arrays.asList(leftType, rightType)));
|
||||||
|
if (intersect == null) {
|
||||||
|
semanticServices.getErrorHandler().genericError(expression.getNode(), "Operator " + operationSign.getReferencedName() + " cannot be applied to " + leftType + " and " + rightType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void visitAssignmentOperation(JetBinaryExpression expression) {
|
protected void visitAssignmentOperation(JetBinaryExpression expression) {
|
||||||
assignmentIsNotAnExpressionError(expression);
|
assignmentIsNotAnExpressionError(expression);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user