Do not allow compareTo() to return Int?
This commit is contained in:
+1
-3
@@ -1015,10 +1015,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetType compareToReturnType = typeInfo.getType();
|
||||
JetType type = null;
|
||||
if (compareToReturnType != null && !compareToReturnType.isError()) {
|
||||
TypeConstructor constructor = compareToReturnType.getConstructor();
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
TypeConstructor intTypeConstructor = builtIns.getInt().getTypeConstructor();
|
||||
if (constructor.equals(intTypeConstructor)) {
|
||||
if (JetTypeChecker.DEFAULT.equalTypes(builtIns.getIntType(), compareToReturnType)) {
|
||||
type = builtIns.getBooleanType();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class C {
|
||||
fun compareTo(c: C): Int? = null
|
||||
}
|
||||
|
||||
fun test(c: C) {
|
||||
c <!COMPARE_TO_TYPE_MISMATCH!><<!> c
|
||||
c <!COMPARE_TO_TYPE_MISMATCH!><=<!> c
|
||||
c <!COMPARE_TO_TYPE_MISMATCH!>>=<!> c
|
||||
c <!COMPARE_TO_TYPE_MISMATCH!>><!> c
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
internal fun test(/*0*/ c: C): kotlin.Unit
|
||||
|
||||
internal final class C {
|
||||
public constructor C()
|
||||
internal final fun compareTo(/*0*/ c: C): kotlin.Int?
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -7493,6 +7493,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compareToNullable.kt")
|
||||
public void testCompareToNullable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/operatorsOverloading/compareToNullable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IteratorAmbiguity.kt")
|
||||
public void testIteratorAmbiguity() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/operatorsOverloading/IteratorAmbiguity.kt");
|
||||
|
||||
Reference in New Issue
Block a user