K2: show all Java function with suspend view if possible

This commit fixes two tests related to removed workaround of KT-59818,
and also makes processing suspend functions in J/K hierarchy more consistent.
Before this commit, when we had Java class "suspend" method
(implemented with the help of Continuation) overriding Kotlin suspend fun,
the Kotlin suspend fun was visible in outer use-site scope,
and the Java method was invisible.
Also, we used a special "Java suspend view" just to determine
that Java method overrides Kotlin suspend fun and no more.
After this commit, Java class "suspend" method will be visible
in this hierarchy and Kotlin suspend fun will not.
Also, the "suspend" is visible as a synthetic Kotlin suspend fun
which is more correct.

Related to KT-63233
#KT-59818 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-12-20 11:33:08 +01:00
committed by Space Team
parent 5409a51ce9
commit 1ebf0f5376
3 changed files with 10 additions and 14 deletions
@@ -23,8 +23,8 @@ import org.jetbrains.kotlin.fir.java.declarations.FirJavaMethod
import org.jetbrains.kotlin.fir.java.declarations.buildJavaMethodCopy
import org.jetbrains.kotlin.fir.java.declarations.buildJavaValueParameterCopy
import org.jetbrains.kotlin.fir.java.resolveIfJavaType
import org.jetbrains.kotlin.fir.java.syntheticPropertiesStorage
import org.jetbrains.kotlin.fir.java.symbols.FirJavaOverriddenSyntheticPropertySymbol
import org.jetbrains.kotlin.fir.java.syntheticPropertiesStorage
import org.jetbrains.kotlin.fir.java.toConeKotlinTypeProbablyFlexible
import org.jetbrains.kotlin.fir.resolve.defaultType
import org.jetbrains.kotlin.fir.resolve.toSymbol
@@ -273,8 +273,7 @@ class JavaClassUseSiteMemberScope(
if (hasCorrespondingProperty) return false
return !doesOverrideRenamedBuiltins() &&
!shouldBeVisibleAsOverrideOfBuiltInWithErasedValueParameters() &&
!doesOverrideSuspendFunction()
!shouldBeVisibleAsOverrideOfBuiltInWithErasedValueParameters()
}
private fun FirNamedFunctionSymbol.doesOverrideRenamedBuiltins(): Boolean {
@@ -334,14 +333,7 @@ class JavaClassUseSiteMemberScope(
}
}
private fun FirNamedFunctionSymbol.doesOverrideSuspendFunction(): Boolean {
val suspendView = createSuspendView() ?: return false
return superTypeScopes.any { scope ->
scope.getFunctions(name).any { it.isSuspend && overrideChecker.isOverriddenFunction(suspendView, it.fir) }
}
}
private fun FirNamedFunctionSymbol.createSuspendView(): FirSimpleFunction? {
override fun FirNamedFunctionSymbol.createSuspendView(): FirSimpleFunction? {
val continuationParameter = fir.valueParameters.lastOrNull() ?: return null
val owner = ownerClassLookupTag.toSymbol(session)?.fir as? FirJavaClass ?: return null
val continuationParameterType = continuationParameter
@@ -6,6 +6,8 @@
package org.jetbrains.kotlin.fir.scopes.impl
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
import org.jetbrains.kotlin.fir.declarations.isJavaOrEnhancement
import org.jetbrains.kotlin.fir.declarations.utils.isStatic
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import org.jetbrains.kotlin.fir.scopes.*
@@ -75,7 +77,7 @@ abstract class AbstractFirUseSiteMemberScope(
if (!symbol.isVisibleInCurrentClass()) return@processFunctionsByName
val directOverridden = computeDirectOverriddenForDeclaredFunction(symbol)
directOverriddenFunctions[symbol] = directOverridden
destination += symbol
destination += (symbol.takeIf { it.isJavaOrEnhancement }?.createSuspendView()?.symbol ?: symbol)
}
}
@@ -216,4 +218,8 @@ abstract class AbstractFirUseSiteMemberScope(
override fun getClassifierNames(): Set<Name> {
return classifierNamesCached
}
protected open fun FirNamedFunctionSymbol.createSuspendView(): FirSimpleFunction? {
return null
}
}
@@ -1,5 +1,3 @@
// IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: wrong ABSTRACT_SUPER_CALL
// TARGET_BACKEND: JVM
// WITH_STDLIB
// WITH_COROUTINES