Skip to content

Commit

Permalink
Fixed type attribution for cone captured types.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Oct 10, 2023
1 parent abc7ddc commit d400070
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
13 changes: 8 additions & 5 deletions src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit d400070

Please sign in to comment.