FIR: Adjust override checker to definitely-not-nullable types
^KT-52201 Related
This commit is contained in:
+6
@@ -18374,6 +18374,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/OverrideVararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideWithErasure.kt")
|
||||
public void testOverrideWithErasure() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/overrideWithErasure.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideWithSamAndTypeParameter.kt")
|
||||
public void testOverrideWithSamAndTypeParameter() throws Exception {
|
||||
|
||||
+13
-4
@@ -4,10 +4,19 @@ SomeMap:
|
||||
[SubstitutionOverride]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 2]
|
||||
[Library]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
|
||||
[Library]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
|
||||
[SubstitutionOverride]: public abstract fun containsValue(value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Java enhancement scope for /SomeMap [id: 0]
|
||||
[SubstitutionOverride]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 1]
|
||||
[Library]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 2]
|
||||
[Library]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 2]
|
||||
[SubstitutionOverride]: public abstract fun containsKey(key: R|ft<kotlin/Any, kotlin/Any?>|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4]
|
||||
[Enhancement]: public abstract fun containsKey(key: R|ft<kotlin/Any, kotlin/Any?>|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 5]
|
||||
[SubstitutionOverride]: public abstract fun containsKey(key: R|ft<kotlin/Any, kotlin/Any?>|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyBaseMap] for type MyMap<K2, V2> [id: 6]
|
||||
[Enhancement]: public abstract fun containsKey(key: R|ft<kotlin/Any, kotlin/Any?>|): R|kotlin/Boolean| from Java enhancement scope for /MyBaseMap [id: 7]
|
||||
[SubstitutionOverride]: public abstract fun containsKey(key: R|ft<kotlin/Any, kotlin/Any?>|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyBaseMap] for type MyMap<K2, V2> [id: 6]
|
||||
[Enhancement]: public abstract fun containsKey(key: R|ft<kotlin/Any, kotlin/Any?>|): R|kotlin/Boolean| from Java enhancement scope for /MyBaseMap [id: 7]
|
||||
[IntersectionOverride]: public abstract fun containsValue(value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Java enhancement scope for /SomeMap [id: 0]
|
||||
[SubstitutionOverride]: public abstract fun containsValue(value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1]
|
||||
[SubstitutionOverride]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 2]
|
||||
[Library]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
|
||||
[Library]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
|
||||
[SubstitutionOverride]: public abstract fun containsValue(key: R|ft<kotlin/Any, kotlin/Any?>|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4]
|
||||
[Enhancement]: public abstract fun containsValue(key: R|ft<kotlin/Any, kotlin/Any?>|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 5]
|
||||
[IntersectionOverride]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|V3?| from Java enhancement scope for /SomeMap [id: 0]
|
||||
[SubstitutionOverride]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|V3?| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1]
|
||||
[SubstitutionOverride]: public abstract operator fun get(key: R|K|): R|V?| from Use site scope of kotlin/collections/MutableMap [id: 2]
|
||||
|
||||
+6
@@ -18374,6 +18374,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/OverrideVararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideWithErasure.kt")
|
||||
public void testOverrideWithErasure() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/overrideWithErasure.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideWithSamAndTypeParameter.kt")
|
||||
public void testOverrideWithSamAndTypeParameter() throws Exception {
|
||||
|
||||
+6
@@ -18374,6 +18374,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/OverrideVararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideWithErasure.kt")
|
||||
public void testOverrideWithErasure() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/overrideWithErasure.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideWithSamAndTypeParameter.kt")
|
||||
public void testOverrideWithSamAndTypeParameter() throws Exception {
|
||||
|
||||
@@ -153,12 +153,16 @@ class JavaOverrideChecker internal constructor(
|
||||
}
|
||||
|
||||
private fun FirTypeRef?.isTypeParameterDependent(): Boolean =
|
||||
this is FirResolvedTypeRef && type.lowerBoundIfFlexible().isTypeParameterDependent()
|
||||
this is FirResolvedTypeRef && type.isTypeParameterDependent()
|
||||
|
||||
private fun ConeKotlinType.isTypeParameterDependent(): Boolean =
|
||||
this is ConeTypeParameterType || this is ConeClassLikeType && typeArguments.any { argument ->
|
||||
private fun ConeKotlinType.isTypeParameterDependent(): Boolean {
|
||||
if (this is ConeFlexibleType) return lowerBound.isTypeParameterDependent()
|
||||
if (this is ConeDefinitelyNotNullType) return original.isTypeParameterDependent()
|
||||
|
||||
return this is ConeTypeParameterType || this is ConeClassLikeType && typeArguments.any { argument ->
|
||||
argument is ConeKotlinTypeProjection && argument.type.isTypeParameterDependent()
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirCallableDeclaration.isTypeParameterDependent(): Boolean =
|
||||
typeParameters.isNotEmpty() || returnTypeRef.isTypeParameterDependent() ||
|
||||
@@ -167,12 +171,14 @@ class JavaOverrideChecker internal constructor(
|
||||
|
||||
private fun FirTypeRef.extractTypeParametersTo(result: MutableCollection<FirTypeParameterRef>) {
|
||||
if (this is FirResolvedTypeRef) {
|
||||
type.lowerBoundIfFlexible().extractTypeParametersTo(result)
|
||||
type.extractTypeParametersTo(result)
|
||||
}
|
||||
}
|
||||
|
||||
private fun ConeKotlinType.extractTypeParametersTo(result: MutableCollection<FirTypeParameterRef>) {
|
||||
when (this) {
|
||||
is ConeFlexibleType -> lowerBound.extractTypeParametersTo(result)
|
||||
is ConeDefinitelyNotNullType -> original.extractTypeParametersTo(result)
|
||||
is ConeTypeParameterType -> {
|
||||
result += lookupTag.typeParameterSymbol.fir
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
// FILE: Base.java
|
||||
public class Base<T extends CharSequence> {
|
||||
public T foo(T t) { return t; }
|
||||
}
|
||||
|
||||
// FILE: Derived.java
|
||||
public class Derived<E extends CharSequence> extends Base<E> {
|
||||
@Override
|
||||
public E foo(CharSequence e) {
|
||||
return (E) "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun main(d: Derived<CharSequence>) {
|
||||
d.foo("")
|
||||
}
|
||||
-2
@@ -2,8 +2,6 @@ public abstract interface OverrideWithErasedParameter : R|kotlin/Any| {
|
||||
public abstract interface Sub<T : R|ft<kotlin/Any, kotlin/Any?>|> : R|test/OverrideWithErasedParameter.Super<ft<T & Any, T?>>| {
|
||||
public abstract fun foo(o: R|ft<kotlin/Any, kotlin/Any?>|): R|kotlin/Unit|
|
||||
|
||||
public abstract fun foo(t: R|ft<T & Any, T?>|): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
public abstract interface Super<T : R|ft<kotlin/Any, kotlin/Any?>|> : R|kotlin/Any| {
|
||||
public abstract fun foo(t: R|ft<T & Any, T?>|): R|kotlin/Unit|
|
||||
|
||||
Generated
+6
@@ -18380,6 +18380,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/OverrideVararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideWithErasure.kt")
|
||||
public void testOverrideWithErasure() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/overrideWithErasure.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideWithSamAndTypeParameter.kt")
|
||||
public void testOverrideWithSamAndTypeParameter() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user