Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9611fea

Browse files
committed
Fix mistaking unspecialised for raw types, and failing to account for an empty declaration stack
1 parent 8553266 commit 9611fea

2 files changed

Lines changed: 26 additions & 24 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,13 @@ open class KotlinFileExtractor(
10711071
}
10721072
}
10731073

1074-
private fun signatureOrWarn(t: TypeResult<*>, associatedElement: IrElement) =
1075-
t.signature ?: "<signature unavailable>".also { logger.warnElement("Needed a signature for a type that doesn't have one", associatedElement) }
1074+
private fun signatureOrWarn(t: TypeResult<*>, associatedElement: IrElement?) =
1075+
t.signature ?: "<signature unavailable>".also {
1076+
if (associatedElement != null)
1077+
logger.warnElement("Needed a signature for a type that doesn't have one", associatedElement)
1078+
else
1079+
logger.warn("Needed a signature for a type that doesn't have one")
1080+
}
10761081

10771082
private fun forceExtractFunction(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, extractMethodAndParameterTypeAccesses: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?, extractOrigin: Boolean = true, overriddenAttributes: OverriddenFunctionAttributes? = null): Label<out DbCallable> {
10781083
with("function", f) {
@@ -4600,7 +4605,7 @@ open class KotlinFileExtractor(
46004605
Pair(paramId, paramType)
46014606
}
46024607

4603-
val paramsSignature = parameters.joinToString(separator = ",", prefix = "(", postfix = ")") { signatureOrWarn(it.second.javaResult, declarationStack.peek().first) }
4608+
val paramsSignature = parameters.joinToString(separator = ",", prefix = "(", postfix = ")") { signatureOrWarn(it.second.javaResult, declarationStack.tryPeek()?.first) }
46044609

46054610
val rt = useType(returnType, TypeContext.RETURN)
46064611
tw.writeMethods(methodId, name, "$name$paramsSignature", rt.javaResult.id, parentId, methodId)
@@ -5316,6 +5321,8 @@ open class KotlinFileExtractor(
53165321

53175322
fun peek() = stack.peek()
53185323

5324+
fun tryPeek() = if (stack.isEmpty()) null else stack.peek()
5325+
53195326
fun findOverriddenAttributes(f: IrFunction) =
53205327
stack.lastOrNull { it.first == f } ?.second
53215328

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,24 +1323,27 @@ open class KotlinUsesExtractor(
13231323
}
13241324
val javaFun = kotlinFunctionToJavaEquivalent(f, noReplace)
13251325
val label = getFunctionLabel(javaFun, parentId, classTypeArgsIncludingOuterClasses)
1326-
var labelSeenBefore = true
13271326
val id: Label<T> = tw.getLabelFor(label) {
1328-
labelSeenBefore = false
1327+
extractPrivateSpecialisedDeclaration(f, classTypeArgsIncludingOuterClasses)
13291328
}
13301329
if (isExternalDeclaration(javaFun)) {
13311330
extractFunctionLaterIfExternalFileMember(javaFun)
13321331
extractExternalEnclosingClassLater(javaFun)
1333-
} else if (!labelSeenBefore && classTypeArgsIncludingOuterClasses?.size != 0 && isPrivate(f)) {
1334-
// Private function call against a raw or instantiated generic class -- extract the prototype here, since the on-demand route via
1335-
// the class label only extracts the public interface. Note guarding this by `labelSeenBefore` is vital because `extractDeclarationPrototype`
1336-
// will call this function.
1337-
if (this is KotlinFileExtractor) {
1338-
useDeclarationParent(f.parent, false, classTypeArgsIncludingOuterClasses, inReceiverContext = true)?.let {
1339-
this.extractDeclarationPrototype(f, it.cast(), classTypeArgsIncludingOuterClasses)
1332+
}
1333+
return id
1334+
}
1335+
1336+
private fun extractPrivateSpecialisedDeclaration(d: IrDeclaration, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) {
1337+
// Note here `classTypeArgsIncludingOuterClasses` being null doesn't signify a raw receiver type but rather that no type args were supplied.
1338+
// This is because a call to a private method can only be observed inside Kotlin code, and Kotlin can't represent raw types.
1339+
if (this is KotlinFileExtractor && isPrivate(d) && classTypeArgsIncludingOuterClasses != null && classTypeArgsIncludingOuterClasses.isNotEmpty()) {
1340+
d.parent.let {
1341+
when(it) {
1342+
is IrClass -> this.extractDeclarationPrototype(d, useClassInstance(it, classTypeArgsIncludingOuterClasses).typeResult.id, classTypeArgsIncludingOuterClasses)
1343+
else -> logger.warnElement("Unable to extract specialised declaration that isn't a member of a class", d)
13401344
}
13411345
}
13421346
}
1343-
return id
13441347
}
13451348

13461349
fun getTypeArgumentLabel(
@@ -1688,18 +1691,10 @@ open class KotlinUsesExtractor(
16881691
}
16891692
}
16901693

1691-
fun useProperty(p: IrProperty, parentId: Label<out DbElement>, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?): Label<out DbKt_property> =
1692-
tw.getLabelFor<DbKt_property>(getPropertyLabel(p, parentId, classTypeArgsIncludingOuterClasses)).also {
1694+
fun useProperty(p: IrProperty, parentId: Label<out DbElement>, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
1695+
tw.getLabelFor<DbKt_property>(getPropertyLabel(p, parentId, classTypeArgsIncludingOuterClasses)) {
16931696
extractPropertyLaterIfExternalFileMember(p)
1694-
if (classTypeArgsIncludingOuterClasses?.size != 0 && isPrivate(p)) {
1695-
// Raw or constructed private property usage -- extract the prototype here, since the on-demand route via
1696-
// the class label only extracts the public interface.
1697-
if (this is KotlinFileExtractor) {
1698-
useDeclarationParent(p.parent, false, classTypeArgsIncludingOuterClasses, inReceiverContext = true)?.let {
1699-
this.extractDeclarationPrototype(p, it.cast(), classTypeArgsIncludingOuterClasses)
1700-
}
1701-
}
1702-
}
1697+
extractPrivateSpecialisedDeclaration(p, classTypeArgsIncludingOuterClasses)
17031698
}
17041699

17051700
fun getEnumEntryLabel(ee: IrEnumEntry): String {

0 commit comments

Comments
 (0)