diff --git a/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt b/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt index d4f025c56..6aeee2127 100644 --- a/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt +++ b/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClassSymbol import org.jetbrains.kotlin.fir.containingClassLookupTag import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.isLocal @@ -878,11 +879,13 @@ class KotlinTypeMapping(typeCache: JavaTypeCache, firSession: FirSession) : Java val annotations = listAnnotations(symbol.annotations) var resolvedOwner: JavaType? = owner if (owner == null) { - val lookupTag: ConeClassLikeLookupTag? = symbol.containingClassLookupTag() - if (lookupTag != null && lookupTag.toSymbol(firSession) !is FirAnonymousObjectSymbol) { - // TODO check type attribution for `FirAnonymousObjectSymbol` case - resolvedOwner = - type(lookupTag.toFirRegularClassSymbol(firSession)!!.fir) as JavaType.FullyQualified? + // TODO: fix type attribution for anonymous objects. Currently, returns JavaType.Unknown. + if (symbol.dispatchReceiverType != null) { + resolvedOwner = type(symbol.dispatchReceiverType) + } else if (symbol.getContainingClassSymbol(firSession) != null) { + if (symbol.getContainingClassSymbol(firSession) !is FirAnonymousObjectSymbol) { + resolvedOwner = type(symbol.getContainingClassSymbol(firSession)!!.fir) + } } } if (resolvedOwner == null && ownerFallBack != null) { diff --git a/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeSignatureBuilder.kt b/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeSignatureBuilder.kt index 54cb71634..11e5c0841 100644 --- a/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeSignatureBuilder.kt +++ b/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeSignatureBuilder.kt @@ -345,11 +345,6 @@ class KotlinTypeSignatureBuilder(private val firSession: FirSession) : JavaTypeS s.append("Generic{in ") s.append(signature(type1)) s.append("}") - } else if (type is ConeCapturedType) { - val (type1) = type - s.append("Generic{in ") - s.append(signature(type1)) - s.append("}") } else if (type is ConeKotlinTypeProjectionOut) { val (type1) = type s.append("Generic{out ") @@ -394,8 +389,8 @@ class KotlinTypeSignatureBuilder(private val firSession: FirSession) : JavaTypeS } s.append(boundSigs) s.append("}") - } else if (type is ConeCapturedType && type.lowerType == null) { - s.append("*") + } else if (type is ConeCapturedType) { + s.append("Generic{*}") } else if (type is ConeStubTypeForChainInference) { if (type.typeArguments.isNotEmpty()) { throw UnsupportedOperationException("Unsupported ConeTypeProjection contains type arguments" + type.javaClass.getName())