FIR: provide super-type as the self-type for anonymous objects

This commit is a temporary approximation useful before we have
symbols for local classes & objects
This commit is contained in:
Simon Ogorodnik
2019-04-25 15:48:53 +03:00
committed by Mikhail Glukhikh
parent 2f7ced2a8e
commit 99994e6c41
3 changed files with 10 additions and 16 deletions
@@ -105,12 +105,12 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
convert() convert()
private fun KtDeclaration.toFirDeclaration( private fun KtDeclaration.toFirDeclaration(
delegatedSuperType: FirTypeRef?, delegatedSelfType: FirTypeRef, owner: KtClassOrObject, hasPrimaryConstructor: Boolean delegatedSuperType: FirTypeRef?, delegatedSelfType: FirTypeRef?, owner: KtClassOrObject, hasPrimaryConstructor: Boolean
): FirDeclaration { ): FirDeclaration {
return when (this) { return when (this) {
is KtSecondaryConstructor -> toFirConstructor( is KtSecondaryConstructor -> toFirConstructor(
delegatedSuperType, delegatedSuperType,
delegatedSelfType, delegatedSelfType!!,
owner, owner,
hasPrimaryConstructor hasPrimaryConstructor
) )
@@ -322,7 +322,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
} }
private fun KtClassOrObject.extractSuperTypeListEntriesTo( private fun KtClassOrObject.extractSuperTypeListEntriesTo(
container: FirModifiableClass, delegatedSelfTypeRef: FirTypeRef container: FirModifiableClass, delegatedSelfTypeRef: FirTypeRef?
): FirTypeRef? { ): FirTypeRef? {
var superTypeCallEntry: KtSuperTypeCallEntry? = null var superTypeCallEntry: KtSuperTypeCallEntry? = null
var delegatedSuperTypeRef: FirTypeRef? = null var delegatedSuperTypeRef: FirTypeRef? = null
@@ -365,7 +365,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
val firPrimaryConstructor = primaryConstructor.toFirConstructor( val firPrimaryConstructor = primaryConstructor.toFirConstructor(
superTypeCallEntry, superTypeCallEntry,
delegatedSuperTypeRef, delegatedSuperTypeRef,
delegatedSelfTypeRef, delegatedSelfTypeRef ?: delegatedSuperTypeRef,
owner = this owner = this
) )
container.declarations += firPrimaryConstructor container.declarations += firPrimaryConstructor
@@ -450,12 +450,6 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
) )
} }
@Deprecated("TODO, proper type")
private fun KtObjectDeclaration.toDelegatedSelfType(): FirTypeRef {
return FirUserTypeRefImpl(session, this, isMarkedNullable = false).apply {
qualifier.add(FirQualifierPartImpl(nameAsSafeName))
}
}
override fun visitEnumEntry(enumEntry: KtEnumEntry, data: Unit): FirElement { override fun visitEnumEntry(enumEntry: KtEnumEntry, data: Unit): FirElement {
@@ -602,12 +596,12 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
val objectDeclaration = expression.objectDeclaration val objectDeclaration = expression.objectDeclaration
return FirAnonymousObjectImpl(session, expression).apply { return FirAnonymousObjectImpl(session, expression).apply {
objectDeclaration.extractAnnotationsTo(this) objectDeclaration.extractAnnotationsTo(this)
val delegatedSelfType = objectDeclaration.toDelegatedSelfType() objectDeclaration.extractSuperTypeListEntriesTo(this, null)
objectDeclaration.extractSuperTypeListEntriesTo(this, delegatedSelfType) this.typeRef = superTypeRefs.first() // TODO
for (declaration in objectDeclaration.declarations) { for (declaration in objectDeclaration.declarations) {
declarations += declaration.toFirDeclaration( declarations += declaration.toFirDeclaration(
delegatedSuperType = null, delegatedSelfType = delegatedSelfType, delegatedSuperType = null, delegatedSelfType = null,
owner = objectDeclaration, hasPrimaryConstructor = false owner = objectDeclaration, hasPrimaryConstructor = false
) )
} }
@@ -20,7 +20,7 @@ FILE: locals.kt
} }
lval code: <implicit> = object : Any { lval code: <implicit> = object : Any {
private constructor(): <no name provided> { private constructor(): Any {
super<Any>() super<Any>()
} }
@@ -1,7 +1,7 @@
FILE: localImplicitBodies.kt FILE: localImplicitBodies.kt
public final fun foo(): R|kotlin/Unit| { public final fun foo(): R|kotlin/Unit| {
lval x: <ERROR TYPE REF: No result type for initializer> = object : R|kotlin/Any| { lval x: R|kotlin/Any| = object : R|kotlin/Any| {
private constructor(): R|class error: Symbol not found, for `<no name provided>`| { private constructor(): R|kotlin/Any| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }