FIR: set super type reference properly

This commit is contained in:
Mikhail Glukhikh
2019-06-17 14:24:41 +03:00
parent 65d14ff097
commit c8003518a5
4 changed files with 18 additions and 8 deletions
@@ -376,11 +376,15 @@ open class FirBodyResolveTransformer(val session: FirSession, val implicitTypeOn
qualifiedAccessExpression.resultType = FirResolvedTypeRefImpl(session, null, type, emptyList())
}
is FirSuperReference -> {
qualifiedAccessExpression.resultType =
callee.superTypeRef as? FirResolvedTypeRef
?: implicitReceiverStack.filterIsInstance<ImplicitDispatchReceiverValue>().lastOrNull()
?.boundSymbol?.fir?.superTypeRefs?.firstOrNull()
?: FirErrorTypeRefImpl(session, qualifiedAccessExpression.psi, "No super type")
if (callee.superTypeRef is FirResolvedTypeRef) {
qualifiedAccessExpression.resultType = callee.superTypeRef
} else {
val superTypeRef = implicitReceiverStack.filterIsInstance<ImplicitDispatchReceiverValue>().lastOrNull()
?.boundSymbol?.fir?.superTypeRefs?.firstOrNull()
?: FirErrorTypeRefImpl(session, qualifiedAccessExpression.psi, "No super type")
qualifiedAccessExpression.resultType = superTypeRef
callee.replaceSuperTypeRef(superTypeRef)
}
}
is FirResolvedCallableReference -> {
if (qualifiedAccessExpression.typeRef !is FirResolvedTypeRef) {
@@ -11,6 +11,8 @@ import org.jetbrains.kotlin.fir.visitors.FirVisitor
interface FirSuperReference : FirReference {
val superTypeRef: FirTypeRef
fun replaceSuperTypeRef(newSuperTypeRef: FirTypeRef)
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
visitor.visitSuperReference(this, data)
@@ -15,6 +15,10 @@ class FirExplicitSuperReference(
psi: PsiElement?,
override var superTypeRef: FirTypeRef
) : FirAbstractElement(session, psi), FirSuperReference {
override fun replaceSuperTypeRef(newSuperTypeRef: FirTypeRef) {
superTypeRef = newSuperTypeRef
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
superTypeRef = superTypeRef.transformSingle(transformer, data)
return this
+3 -3
View File
@@ -24,7 +24,7 @@ FILE fqName:<root> fileName:/superCalls.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun hashCode (): kotlin.Int declared in <root>.Base'
CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.Any' type=kotlin.Int origin=null
$this: ERROR_CALL 'Unresolved reference: super<<implicit>>' type=kotlin.Any
$this: ERROR_CALL 'Unresolved reference: super<R|kotlin/Any|>' type=kotlin.Any
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -44,7 +44,7 @@ FILE fqName:<root> fileName:/superCalls.kt
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
BLOCK_BODY
CALL 'public open fun foo (): kotlin.Unit declared in <root>.Base' type=kotlin.Unit origin=null
$this: ERROR_CALL 'Unresolved reference: super<<implicit>>' type=<root>.Base
$this: ERROR_CALL 'Unresolved reference: super<R|Base|>' type=<root>.Base
PROPERTY name:bar visibility:public modality:FINAL [val]
FUN name:<get-bar> visibility:public modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.String
correspondingProperty: PROPERTY name:bar visibility:public modality:FINAL [val]
@@ -52,7 +52,7 @@ FILE fqName:<root> fileName:/superCalls.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-bar> (): kotlin.String declared in <root>.Derived'
CALL 'public open fun <get-bar> (): kotlin.String declared in <root>.Base' type=kotlin.String origin=null
$this: ERROR_CALL 'Unresolved reference: super<<implicit>>' type=<root>.Base
$this: ERROR_CALL 'Unresolved reference: super<R|Base|>' type=<root>.Base
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:<root>.Base) returnType:kotlin.Int
overridden:
public open fun hashCode (): kotlin.Int declared in <root>.Base