Move OverridingUtil#getUpperBound to OverloadUtil, add tests on overloads
This commit is contained in:
@@ -21,8 +21,9 @@ import org.jetbrains.kotlin.descriptors.*
|
|||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.*
|
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.INCOMPATIBLE
|
||||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
import org.jetbrains.kotlin.types.oneMoreSpecificThanAnother
|
import org.jetbrains.kotlin.types.oneMoreSpecificThanAnother
|
||||||
|
|
||||||
@@ -47,11 +48,12 @@ object OverloadUtil {
|
|||||||
val aValueParameters = OverridingUtil.compiledValueParameters(a)
|
val aValueParameters = OverridingUtil.compiledValueParameters(a)
|
||||||
val bValueParameters = OverridingUtil.compiledValueParameters(b)
|
val bValueParameters = OverridingUtil.compiledValueParameters(b)
|
||||||
|
|
||||||
for (i in aValueParameters.indices) {
|
for ((aType, bType) in aValueParameters.zip(bValueParameters)) {
|
||||||
val superValueParameterType = OverridingUtil.getUpperBound(aValueParameters[i])
|
// TODO: check type parameters, create a substitution and compare parameter types according to it, like in OverridingUtil
|
||||||
val subValueParameterType = OverridingUtil.getUpperBound(bValueParameters[i])
|
val superValueParameterType = aType.upperBound
|
||||||
|
val subValueParameterType = bType.upperBound
|
||||||
if (!KotlinTypeChecker.DEFAULT.equalTypes(superValueParameterType, subValueParameterType) ||
|
if (!KotlinTypeChecker.DEFAULT.equalTypes(superValueParameterType, subValueParameterType) ||
|
||||||
oneMoreSpecificThanAnother(subValueParameterType, superValueParameterType)) {
|
oneMoreSpecificThanAnother(subValueParameterType, superValueParameterType)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,6 +69,16 @@ object OverloadUtil {
|
|||||||
else -> throw IllegalStateException()
|
else -> throw IllegalStateException()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val KotlinType.upperBound: KotlinType
|
||||||
|
get() {
|
||||||
|
val classifier = constructor.declarationDescriptor
|
||||||
|
return when (classifier) {
|
||||||
|
is ClassDescriptor -> this
|
||||||
|
is TypeParameterDescriptor -> classifier.upperBoundsAsType
|
||||||
|
else -> error("Unknown type constructor: $this")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public @JvmStatic fun groupModulePackageMembersByFqName(
|
public @JvmStatic fun groupModulePackageMembersByFqName(
|
||||||
c: BodiesResolveContext,
|
c: BodiesResolveContext,
|
||||||
constructorsInPackages: MultiMap<FqNameUnsafe, ConstructorDescriptor>
|
constructorsInPackages: MultiMap<FqNameUnsafe, ConstructorDescriptor>
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
|
interface Test1 {
|
||||||
|
<!CONFLICTING_OVERLOADS!>fun <T> foo(t: T)<!> where T : Cloneable, T : Serializable
|
||||||
|
<!CONFLICTING_OVERLOADS!>fun <T> foo(t: T)<!> where T : Serializable, T : Cloneable
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface I1
|
||||||
|
interface I2 : I1
|
||||||
|
|
||||||
|
interface Test2 {
|
||||||
|
<!CONFLICTING_OVERLOADS!>fun <T> foo(t: T)<!> where T : I1, T : I2
|
||||||
|
<!CONFLICTING_OVERLOADS!>fun <T> foo(t: T)<!> where T : I2, T : I1
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public interface I1 {
|
||||||
|
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 I2 : I1 {
|
||||||
|
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 Test1 {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public abstract fun </*0*/ T : kotlin.Cloneable> foo(/*0*/ t: T): kotlin.Unit where T : java.io.Serializable
|
||||||
|
public abstract fun </*0*/ T : java.io.Serializable> foo(/*0*/ t: T): kotlin.Unit where T : kotlin.Cloneable
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Test2 {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public abstract fun </*0*/ T : I1> foo(/*0*/ t: T): kotlin.Unit where T : I2
|
||||||
|
public abstract fun </*0*/ T : I2> foo(/*0*/ t: T): kotlin.Unit where T : I1
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
interface Foo
|
||||||
|
interface Bar
|
||||||
|
|
||||||
|
<!CONFLICTING_JVM_DECLARATIONS!>fun <T> foo(x: T): T<!> where T: Foo, T: Bar {null!!}
|
||||||
|
<!CONFLICTING_JVM_DECLARATIONS!>fun foo(x: Foo): Foo<!> {null!!}
|
||||||
|
fun foo(x: Bar): Bar {null!!}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun foo(/*0*/ x: Bar): Bar
|
||||||
|
public fun foo(/*0*/ x: Foo): Foo
|
||||||
|
public fun </*0*/ T : Foo> foo(/*0*/ x: T): T where T : Bar
|
||||||
|
|
||||||
|
public interface Bar {
|
||||||
|
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 Foo {
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -10697,6 +10697,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/overload/SyntheticAndNotSynthetic.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/overload/SyntheticAndNotSynthetic.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("TypeParameterMultipleBounds.kt")
|
||||||
|
public void testTypeParameterMultipleBounds() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/overload/TypeParameterMultipleBounds.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/override")
|
@TestMetadata("compiler/testData/diagnostics/tests/override")
|
||||||
@@ -12017,6 +12023,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/redeclarations/SingletonAndFunctionSameName.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/redeclarations/SingletonAndFunctionSameName.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeParameterWithTwoBounds.kt")
|
||||||
|
public void testTypeParameterWithTwoBounds() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/redeclarations/typeParameterWithTwoBounds.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/reflection")
|
@TestMetadata("compiler/testData/diagnostics/tests/reflection")
|
||||||
|
|||||||
@@ -237,18 +237,6 @@ public class OverridingUtil {
|
|||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
static KotlinType getUpperBound(KotlinType type) {
|
|
||||||
if (type.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
else if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) {
|
|
||||||
return ((TypeParameterDescriptor) type.getConstructor().getDeclarationDescriptor()).getUpperBoundsAsType();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalStateException("unknown type constructor: " + type.getConstructor().getClass().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void generateOverridesInFunctionGroup(
|
public static void generateOverridesInFunctionGroup(
|
||||||
@SuppressWarnings("UnusedParameters")
|
@SuppressWarnings("UnusedParameters")
|
||||||
@NotNull Name name, //DO NOT DELETE THIS PARAMETER: needed to make sure all descriptors have the same name
|
@NotNull Name name, //DO NOT DELETE THIS PARAMETER: needed to make sure all descriptors have the same name
|
||||||
|
|||||||
Reference in New Issue
Block a user