[FIR] Unwrap definitely not null when matching overrides
#KT-41984 Fixed
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// ISSUE: KT-41984
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class A<T, V> {
|
||||
@NotNull
|
||||
public abstract String take(@NotNull V value);
|
||||
|
||||
@NotNull
|
||||
public abstract String takeInv(@NotNull Inv<@NotNull V> value);
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
class Inv<T>
|
||||
|
||||
open class B<V> : A<Any, V>() {
|
||||
override fun take(value: V): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun takeInv(value: Inv<V>): String = ""
|
||||
}
|
||||
|
||||
fun test_1(b: B<Int>, x: Int, inv: Inv<Int>) {
|
||||
b.take(x)
|
||||
b.<!INAPPLICABLE_CANDIDATE!>take<!>(null)
|
||||
b.takeInv(inv)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
FILE: main.kt
|
||||
public final class Inv<T> : R|kotlin/Any| {
|
||||
public constructor<T>(): R|Inv<T>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public open class B<V> : R|A<kotlin/Any, V>| {
|
||||
public constructor<V>(): R|B<V>| {
|
||||
super<R|A<kotlin/Any, V>|>()
|
||||
}
|
||||
|
||||
public open override fun take(value: R|V|): R|kotlin/String| {
|
||||
^take String()
|
||||
}
|
||||
|
||||
public open override fun takeInv(value: R|Inv<V>|): R|kotlin/String| {
|
||||
^takeInv String()
|
||||
}
|
||||
|
||||
}
|
||||
public final fun test_1(b: R|B<kotlin/Int>|, x: R|kotlin/Int|, inv: R|Inv<kotlin/Int>|): R|kotlin/Unit| {
|
||||
R|<local>/b|.R|FakeOverride</B.take: R|kotlin/String|>|(R|<local>/x|)
|
||||
R|<local>/b|.<Inapplicable(INAPPLICABLE): /B.take>#(Null(null))
|
||||
R|<local>/b|.R|FakeOverride</B.takeInv: R|kotlin/String|>|(R|<local>/inv|)
|
||||
}
|
||||
Generated
+5
@@ -243,6 +243,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/javaStaticScopeInheritance.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41984.kt")
|
||||
public void testKt41984() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt41984.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41990.kt")
|
||||
public void testKt41990() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt41990.kt");
|
||||
|
||||
+5
@@ -243,6 +243,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/javaStaticScopeInheritance.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41984.kt")
|
||||
public void testKt41984() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt41984.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41990.kt")
|
||||
public void testKt41990() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt41990.kt");
|
||||
|
||||
+7
-2
@@ -41,11 +41,16 @@ class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideCheck
|
||||
}
|
||||
|
||||
private fun isEqualTypes(candidateType: ConeKotlinType, baseType: ConeKotlinType, substitutor: ConeSubstitutor): Boolean {
|
||||
val substitutedCandidateType = substitutor.substituteOrSelf(candidateType)
|
||||
val substitutedBaseType = substitutor.substituteOrSelf(baseType)
|
||||
val substitutedCandidateType = substitutor.substituteOrSelf(candidateType).unwrapDefinitelyNotNullType()
|
||||
val substitutedBaseType = substitutor.substituteOrSelf(baseType).unwrapDefinitelyNotNullType()
|
||||
return isEqualTypes(substitutedCandidateType, substitutedBaseType)
|
||||
}
|
||||
|
||||
private fun ConeKotlinType.unwrapDefinitelyNotNullType(): ConeKotlinType = when (this) {
|
||||
is ConeDefinitelyNotNullType -> original
|
||||
else -> this
|
||||
}
|
||||
|
||||
override fun isEqualTypes(candidateTypeRef: FirTypeRef, baseTypeRef: FirTypeRef, substitutor: ConeSubstitutor) =
|
||||
isEqualTypes(candidateTypeRef.coneType, baseTypeRef.coneType, substitutor)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user