@@ -1788,7 +1788,8 @@ open class KotlinFileExtractor(
1788
1788
1789
1789
private fun extractCall (c : IrCall , callable : Label <out DbCallable >, stmtExprParent : StmtExprParent ) {
1790
1790
with (" call" , c) {
1791
- val target = tryReplaceSyntheticFunction(c.symbol.owner)
1791
+ val owner = tryGetPossiblyUnboundSymbolOwner(c.symbol, c) ? : return
1792
+ val target = tryReplaceSyntheticFunction(owner)
1792
1793
1793
1794
// The vast majority of types of call want an expr context, so make one available lazily:
1794
1795
val exprParent by lazy {
@@ -2953,15 +2954,7 @@ open class KotlinFileExtractor(
2953
2954
tw.writeCallableEnclosingExpr(id, callable)
2954
2955
tw.writeStatementEnclosingExpr(id, exprParent.enclosingStmt)
2955
2956
2956
- val owner = if (e.symbol.isBound) {
2957
- e.symbol.owner
2958
- }
2959
- else {
2960
- logger.warnElement(" Unbound enum value, trying to use enum entry stub from descriptor" , e)
2961
-
2962
- @OptIn(ObsoleteDescriptorBasedAPI ::class )
2963
- getIrStubFromDescriptor() { it.generateEnumEntryStub(e.symbol.descriptor) }
2964
- } ? : return
2957
+ val owner = tryGetPossiblyUnboundSymbolOwner(e.symbol, e) ? : return
2965
2958
2966
2959
val vId = useEnumEntry(owner)
2967
2960
tw.writeVariableBinding(id, vId)
@@ -3138,15 +3131,7 @@ open class KotlinFileExtractor(
3138
3131
// automatically-generated `public static final MyObject INSTANCE`
3139
3132
// field that we are accessing here.
3140
3133
val exprParent = parent.expr(e, callable)
3141
- val c = if (e.symbol.isBound) {
3142
- e.symbol.owner
3143
- }
3144
- else {
3145
- logger.warnElement(" Unbound object value, trying to use class stub from descriptor" , e)
3146
-
3147
- @OptIn(ObsoleteDescriptorBasedAPI ::class )
3148
- getIrStubFromDescriptor() { it.generateClassStub(e.symbol.descriptor) }
3149
- } ? : return
3134
+ val c = tryGetPossiblyUnboundSymbolOwner(e.symbol, e) ? : return
3150
3135
3151
3136
val instance = if (c.isCompanion) useCompanionObjectClassInstance(c) else useObjectClassInstance(c)
3152
3137
@@ -3259,6 +3244,24 @@ open class KotlinFileExtractor(
3259
3244
}
3260
3245
}
3261
3246
3247
+ private inline fun <D : DeclarationDescriptor , reified B : IrSymbolOwner > tryGetPossiblyUnboundSymbolOwner (symbol : IrBindableSymbol <D , B >, e : IrElement ): B ? {
3248
+ if (symbol.isBound) {
3249
+ return symbol.owner
3250
+ }
3251
+
3252
+ logger.warnElement(" Unbound symbol, trying to use owner stub from descriptor" , e)
3253
+
3254
+ @OptIn(ObsoleteDescriptorBasedAPI ::class )
3255
+ val owner = getIrStubFromDescriptor() { it.generateMemberStub(symbol.descriptor) }
3256
+
3257
+ if (owner is B ) {
3258
+ return owner
3259
+ }
3260
+
3261
+ logger.errorElement(" Couldn't get owner of unbound symbol from its descriptor" , e)
3262
+ return null
3263
+ }
3264
+
3262
3265
private fun extractSuperAccess (irType : IrType , callable : Label <out DbCallable >, parent : Label <out DbExprparent >, idx : Int , enclosingStmt : Label <out DbStmt >, locId : Label <out DbLocation >) =
3263
3266
tw.getFreshIdLabel<DbSuperaccess >().also {
3264
3267
val type = useType(irType)
0 commit comments