[FIR] Use proper directOverriddenFunctions fun in FirNativeThrowsChecker
Fix false positive `INCOMPATIBLE_THROWS_OVERRIDE` ^KT-65105 Fixed Merge-request: KT-MR-14937 Merged-by: Ivan Kochurkin <Ivan.Kochurkin@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
4941094521
commit
b24d5390a8
+2
-5
@@ -13,8 +13,8 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirBasicDeclarationChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.directOverriddenFunctions
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.hasModifier
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.unsubstitutedScope
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.native.FirNativeErrors
|
||||
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride
|
||||
import org.jetbrains.kotlin.fir.references.isError
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.scopes.getDirectOverriddenFunctions
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
@@ -136,9 +135,7 @@ sealed class FirNativeThrowsChecker(mppKind: MppCheckerKind) : FirBasicDeclarati
|
||||
val containingClassSymbol = localFunctionSymbol.containingClassLookupTag()?.toFirRegularClassSymbol(context.session)
|
||||
|
||||
if (containingClassSymbol != null) {
|
||||
val unsubstitutedScope = containingClassSymbol.unsubstitutedScope(context)
|
||||
unsubstitutedScope.processFunctionsByName(localFunctionSymbol.name) {}
|
||||
val overriddenFunctions = unsubstitutedScope.getDirectOverriddenFunctions(localFunctionSymbol)
|
||||
val overriddenFunctions = localFunctionSymbol.directOverriddenFunctions(context.session, context.scopeSession)
|
||||
if (localFunctionSymbol == function.symbol || localThrowsAnnotation == null && overriddenFunctions.isNotEmpty()) {
|
||||
for (overriddenFunction in overriddenFunctions) {
|
||||
val annotation = if (overriddenFunction.isSubstitutionOrIntersectionOverride) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// ISSUE: KT-65105
|
||||
|
||||
// FILE: kotlin.kt
|
||||
package kotlin
|
||||
|
||||
@@ -376,3 +378,13 @@ typealias ThrowableAlias = Throwable
|
||||
|
||||
@Throws(ThrowableAlias::class)
|
||||
suspend fun suspendThrowsThrowableTypealias() {}
|
||||
|
||||
interface Foo<T> {
|
||||
@Throws(IllegalArgumentException::class)
|
||||
public fun f(data: T) {}
|
||||
}
|
||||
|
||||
class Bar<K> : Foo<K> {
|
||||
@Throws(IllegalArgumentException::class)
|
||||
override fun f(data: K) {}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// ISSUE: KT-65105
|
||||
|
||||
// FILE: kotlin.kt
|
||||
package kotlin
|
||||
|
||||
@@ -376,3 +378,13 @@ typealias ThrowableAlias = Throwable
|
||||
|
||||
@Throws(ThrowableAlias::class)
|
||||
suspend fun suspendThrowsThrowableTypealias() {}
|
||||
|
||||
interface Foo<T> {
|
||||
@Throws(IllegalArgumentException::class)
|
||||
public fun f(data: T) {}
|
||||
}
|
||||
|
||||
class Bar<K> : Foo<K> {
|
||||
@Throws(IllegalArgumentException::class)
|
||||
override fun f(data: K) {}
|
||||
}
|
||||
@@ -47,6 +47,14 @@ package
|
||||
@kotlin.Throws(exceptionClasses = {}) public fun throwsUnresolved(): kotlin.Unit
|
||||
public fun withLocalClass(): kotlin.Unit
|
||||
|
||||
public final class Bar</*0*/ K> : Foo<K> {
|
||||
public constructor Bar</*0*/ K>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@kotlin.Throws(exceptionClasses = {kotlin.IllegalArgumentException::class}) public open override /*1*/ fun f(/*0*/ data: K): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface Base0 {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(): kotlin.Unit
|
||||
@@ -152,6 +160,13 @@ public final class Exception3 : kotlin.Throwable {
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface Foo</*0*/ T> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@kotlin.Throws(exceptionClasses = {kotlin.IllegalArgumentException::class}) public open fun f(/*0*/ data: T): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class HasThrowsWithEmptyListOnOverride : Base1 {
|
||||
public constructor HasThrowsWithEmptyListOnOverride()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
|
||||
Reference in New Issue
Block a user