Merge pull request #9709 from igfoo/igfoo/isLocalFunction

Kotlin: Let useFunction worry about isLocalFunction for us
This commit is contained in:
Ian Lynagh
2022-06-24 19:22:43 +01:00
committed by GitHub
2 changed files with 8 additions and 12 deletions

View File

@@ -732,12 +732,9 @@ open class KotlinFileExtractor(
val id = val id =
idOverride idOverride
?: if (f.isLocalFunction()) ?: // If this is a class that would ordinarily be replaced by a Java equivalent (e.g. kotlin.Map -> java.util.Map),
getLocallyVisibleFunctionLabels(f).function // don't replace here, really extract the Kotlin version:
else useFunction<DbCallable>(f, parentId, classTypeArgsIncludingOuterClasses, noReplace = true)
// If this is a class that would ordinarily be replaced by a Java equivalent (e.g. kotlin.Map -> java.util.Map),
// don't replace here, really extract the Kotlin version:
useFunction<DbCallable>(f, parentId, classTypeArgsIncludingOuterClasses, noReplace = true)
val sourceDeclaration = val sourceDeclaration =
if (typeSubstitution != null && idOverride == null) if (typeSubstitution != null && idOverride == null)

View File

@@ -1201,15 +1201,14 @@ open class KotlinUsesExtractor(
} as IrFunction? ?: f } as IrFunction? ?: f
fun <T: DbCallable> useFunction(f: IrFunction, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>? = null, noReplace: Boolean = false): Label<out T> { fun <T: DbCallable> useFunction(f: IrFunction, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>? = null, noReplace: Boolean = false): Label<out T> {
if (f.isLocalFunction()) { return useFunction(f, null, classTypeArgsIncludingOuterClasses, noReplace)
val ids = getLocallyVisibleFunctionLabels(f)
return ids.function.cast<T>()
} else {
return useFunction(f, null, classTypeArgsIncludingOuterClasses, noReplace)
}
} }
fun <T: DbCallable> useFunction(f: IrFunction, parentId: Label<out DbElement>?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?, noReplace: Boolean = false): Label<out T> { fun <T: DbCallable> useFunction(f: IrFunction, parentId: Label<out DbElement>?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?, noReplace: Boolean = false): Label<out T> {
if (f.isLocalFunction()) {
val ids = getLocallyVisibleFunctionLabels(f)
return ids.function.cast<T>()
}
val javaFun = kotlinFunctionToJavaEquivalent(f, noReplace) val javaFun = kotlinFunctionToJavaEquivalent(f, noReplace)
val label = getFunctionLabel(javaFun, parentId, classTypeArgsIncludingOuterClasses) val label = getFunctionLabel(javaFun, parentId, classTypeArgsIncludingOuterClasses)
val id: Label<T> = tw.getLabelFor(label) val id: Label<T> = tw.getLabelFor(label)