Introduce new type checker.
This commit is contained in:
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.TypeUtils.noExpectedType
|
||||
import org.jetbrains.kotlin.types.checker.ErrorTypesAreEqualToAnything
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import java.util.*
|
||||
|
||||
@@ -178,7 +179,7 @@ class CandidateResolver(
|
||||
// TODO: use constraint system to check if candidateKCallableType can be a subtype of expectedType
|
||||
val substituteDontCare = makeConstantSubstitutor(candidateTypeParameters, TypeUtils.DONT_CARE)
|
||||
val subTypeSubstituted = substituteDontCare.substitute(subType, Variance.INVARIANT) ?: return true
|
||||
return KotlinTypeChecker.ERROR_TYPES_ARE_EQUAL_TO_ANYTHING.isSubtypeOf(subTypeSubstituted, superType)
|
||||
return ErrorTypesAreEqualToAnything.isSubtypeOf(subTypeSubstituted, superType)
|
||||
}
|
||||
|
||||
private fun CallCandidateResolutionContext<*>.checkVisibilityWithoutReceiver() = checkAndReport {
|
||||
|
||||
@@ -132,14 +132,14 @@ public class TypeIntersector {
|
||||
return TypeUtils.makeNullableAsSpecified(resultingTypes.get(0), allNullable);
|
||||
}
|
||||
|
||||
TypeConstructor constructor = new IntersectionTypeConstructor(Annotations.Companion.getEMPTY(), resultingTypes);
|
||||
IntersectionTypeConstructor constructor = new IntersectionTypeConstructor(resultingTypes);
|
||||
|
||||
return KotlinTypeFactory.simpleType(
|
||||
Annotations.Companion.getEMPTY(),
|
||||
constructor,
|
||||
Collections.<TypeProjection>emptyList(),
|
||||
allNullable,
|
||||
TypeIntersectionScope.create("member scope for intersection type " + constructor, resultingTypes)
|
||||
constructor.createScopeForKotlinType()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.ErrorTypesAreEqualToAnything
|
||||
|
||||
/**
|
||||
* This is temporary hack for type intersector.
|
||||
@@ -33,7 +33,7 @@ internal fun hackForTypeIntersector(types: Collection<KotlinType>): KotlinType?
|
||||
|
||||
return types.firstOrNull { candidate ->
|
||||
types.all {
|
||||
KotlinTypeChecker.ERROR_TYPES_ARE_EQUAL_TO_ANYTHING.isSubtypeOf(candidate, it)
|
||||
ErrorTypesAreEqualToAnything.isSubtypeOf(candidate, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// FILE: A.java
|
||||
public interface A<T> {
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
public class B implements A<String> {
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
class C: B()
|
||||
|
||||
class D: B(), A<String>
|
||||
class E: B(), A<String?>
|
||||
|
||||
fun eatAString(a: A<String>) {}
|
||||
fun eatAStringN(a: A<String?>) {}
|
||||
|
||||
fun test(b: B, c: C, d: D, e: E) {
|
||||
eatAString(b)
|
||||
eatAString(c)
|
||||
eatAString(d)
|
||||
eatAString(<!TYPE_MISMATCH!>e<!>)
|
||||
|
||||
eatAStringN(b)
|
||||
eatAStringN(c)
|
||||
eatAStringN(<!TYPE_MISMATCH!>d<!>)
|
||||
eatAStringN(e)
|
||||
}
|
||||
|
||||
// FILE: 3.kt
|
||||
|
||||
interface X : A<String>
|
||||
interface Y: X
|
||||
interface Z: X
|
||||
|
||||
class W: B(), Z
|
||||
|
||||
fun test2(w: W) {
|
||||
eatAString(w)
|
||||
eatAStringN(<!TYPE_MISMATCH!>w<!>)
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package
|
||||
|
||||
public fun eatAString(/*0*/ a: A<kotlin.String>): kotlin.Unit
|
||||
public fun eatAStringN(/*0*/ a: A<kotlin.String?>): kotlin.Unit
|
||||
public fun test(/*0*/ b: B, /*1*/ c: C, /*2*/ d: D, /*3*/ e: E): kotlin.Unit
|
||||
public fun test2(/*0*/ w: W): kotlin.Unit
|
||||
|
||||
public interface A</*0*/ T : kotlin.Any!> {
|
||||
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
|
||||
}
|
||||
|
||||
public open class B : A<kotlin.String!> {
|
||||
public constructor B()
|
||||
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
|
||||
}
|
||||
|
||||
public final class C : B {
|
||||
public constructor C()
|
||||
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
|
||||
}
|
||||
|
||||
public final class D : B, A<kotlin.String> {
|
||||
public constructor D()
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class E : B, A<kotlin.String?> {
|
||||
public constructor E()
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class W : B, Z {
|
||||
public constructor W()
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface X : A<kotlin.String> {
|
||||
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
|
||||
}
|
||||
|
||||
public interface Y : X {
|
||||
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
|
||||
}
|
||||
|
||||
public interface Z : X {
|
||||
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
|
||||
}
|
||||
@@ -18921,6 +18921,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaAndKotlinSuperType.kt")
|
||||
public void testJavaAndKotlinSuperType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/subtyping/javaAndKotlinSuperType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt2069.kt")
|
||||
public void testKt2069() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/subtyping/kt2069.kt");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -182,13 +182,13 @@ public class KotlinTypeCheckerTest extends KotlinTestWithEnvironment {
|
||||
assertCommonSupertype("Base_T<in Int>", "Base_T<Int>", "Base_T<in Int>");
|
||||
assertCommonSupertype("Base_T<in Int>", "Derived_T<Int>", "Base_T<in Int>");
|
||||
assertCommonSupertype("Base_T<in Int>", "Derived_T<in Int>", "Base_T<Int>");
|
||||
assertCommonSupertype("Base_T<*>", "Base_T<Int>", "Base_T<*>");
|
||||
assertCommonSupertype("Base_T<out Any?>", "Base_T<Int>", "Base_T<*>");
|
||||
|
||||
assertCommonSupertype("Base_T<out Parent>", "Base_T<A>", "Base_T<B>");
|
||||
}
|
||||
|
||||
public void testCommonSupertypesForRecursive() throws Exception {
|
||||
assertCommonSupertype("Rec<out Rec<out Rec<out Rec<out Rec<out Any?>>>>>", "ARec", "BRec");
|
||||
assertCommonSupertype("Rec<out Rec<out Rec<out Rec<out Rec<*>>>>>", "ARec", "BRec");
|
||||
}
|
||||
|
||||
public void testIntersect() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user