@@ -153,7 +153,7 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV
153
153
if (unfoldedActualType != unfoldedExpectedType) {
154
154
if (reportError) {
155
155
context.error(
156
- " Type mismatch: '%s' was given but '%s' was expected " .format(
156
+ TYPE_MISMATCH_ERROR .format(
157
157
unfoldedActualType.representation,
158
158
unfoldedExpectedType.representation
159
159
)
@@ -511,6 +511,17 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV
511
511
512
512
o.right.typeHint = o.typeHint ? : RsPrimitiveType .INT
513
513
o.right.accept(this )
514
+
515
+ val leftType = o.left.type.unfold()
516
+ val rightType = o.right.type.unfold()
517
+
518
+ if (leftType == null || rightType == null || leftType is RsErrorType || rightType == RsErrorType ) return
519
+
520
+ val operator = o.arithmeticOp
521
+
522
+ if (leftType != rightType) {
523
+ o.error(INVALID_OPERATOR_ERROR .format(operator .text, leftType.representation, rightType.representation))
524
+ }
514
525
}
515
526
516
527
override fun visitArithmeticValueExpression (o : RsArithmeticValueExpression ) {
@@ -665,10 +676,8 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV
665
676
checkExpressionList(o, o.expressionList, expectedReturnList ? : emptyArray<RsType >())
666
677
}
667
678
companion object {
668
- private val ALLOWED_RELATIONAL_TYPES = arrayOf(
669
- RsPrimitiveType .INT ,
670
- RsPrimitiveType .LONG
671
- )
679
+ private const val TYPE_MISMATCH_ERROR = " Type mismatch: '%s' was given but '%s' was expected"
680
+ private const val INVALID_OPERATOR_ERROR = " Operator '%s' cannot be applied to '%s', '%s'"
672
681
}
673
682
}
674
683
0 commit comments