Skip to content
Permalink
Browse files
STC: type of <, >, <=, >= and <=> even without compareTo
  • Loading branch information
eric-milles committed Mar 9, 2022
1 parent 4cbdc0f commit bdf98125cd0a1a19dfd28e09f206e9dcc9d82d70
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
@@ -4422,14 +4422,14 @@ protected ClassNode getResultType(ClassNode left, final int op, final ClassNode
if (method != null) {
storeTargetMethod(expr, method);
typeCheckMethodsWithGenericsOrFail(left, new ClassNode[]{right}, method, expr);

if (isAssignment(op)) return left;
if (isCompareToBoolean(op)) return boolean_TYPE;
if (op == COMPARE_TO) return int_TYPE;
return inferReturnTypeGenerics(left, method, args(rightExpression));
if (!isCompareToBoolean(op) && op != COMPARE_TO)
return inferReturnTypeGenerics(left, method, args(rightExpression));
}

// TODO: other cases

if (isCompareToBoolean(op)) return boolean_TYPE;
if (op == COMPARE_TO) return int_TYPE;
return null;
}

@@ -93,6 +93,15 @@ class STCnAryExpressionTest extends StaticTypeCheckingTestCase {
'''
}

void testOtherTypeComparison() {
shouldFailWithMessages '''
def that = new Object()
def test = (that >= this)
test.booleanValue() // no error
''',
'Cannot find matching method java.lang.Object#compareTo'
}

void testShiftOnPrimitives() {
assertScript '''
1 << 8

0 comments on commit bdf9812

Please sign in to comment.