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()
private fun KtDeclaration.toFirDeclaration(
delegatedSuperType: FirTypeRef?, delegatedSelfType: FirTypeRef, owner: KtClassOrObject, hasPrimaryConstructor: Boolean
delegatedSuperType: FirTypeRef?, delegatedSelfType: FirTypeRef?, owner: KtClassOrObject, hasPrimaryConstructor: Boolean
): FirDeclaration {
return when (this) {
is KtSecondaryConstructor -> toFirConstructor(
delegatedSuperType,
delegatedSelfType,
delegatedSelfType!!,
owner,
hasPrimaryConstructor
)
@@ -322,7 +322,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
}
private fun KtClassOrObject.extractSuperTypeListEntriesTo(
container: FirModifiableClass, delegatedSelfTypeRef: FirTypeRef
container: FirModifiableClass, delegatedSelfTypeRef: FirTypeRef?
): FirTypeRef? {
var superTypeCallEntry: KtSuperTypeCallEntry? = null
var delegatedSuperTypeRef: FirTypeRef? = null
@@ -365,7 +365,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
val firPrimaryConstructor = primaryConstructor.toFirConstructor(
superTypeCallEntry,
delegatedSuperTypeRef,
delegatedSelfTypeRef,
delegatedSelfTypeRef ?: delegatedSuperTypeRef,
owner = this
)
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 {
@@ -602,12 +596,12 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
val objectDeclaration = expression.objectDeclaration
return FirAnonymousObjectImpl(session, expression).apply {
objectDeclaration.extractAnnotationsTo(this)
val delegatedSelfType = objectDeclaration.toDelegatedSelfType()
objectDeclaration.extractSuperTypeListEntriesTo(this, delegatedSelfType)
objectDeclaration.extractSuperTypeListEntriesTo(this, null)
this.typeRef = superTypeRefs.first() // TODO
for (declaration in objectDeclaration.declarations) {
declarations += declaration.toFirDeclaration(
delegatedSuperType = null, delegatedSelfType = delegatedSelfType,
delegatedSuperType = null, delegatedSelfType = null,
owner = objectDeclaration, hasPrimaryConstructor = false
)
}
@@ -20,7 +20,7 @@ FILE: locals.kt
}
lval code: <implicit> = object : Any {
private constructor(): <no name provided> {
private constructor(): Any {
super<Any>()
}
@@ -1,7 +1,7 @@
FILE: localImplicitBodies.kt
public final fun foo(): R|kotlin/Unit| {
lval x: <ERROR TYPE REF: No result type for initializer> = object : R|kotlin/Any| {
private constructor(): R|class error: Symbol not found, for `<no name provided>`| {
lval x: R|kotlin/Any| = object : R|kotlin/Any| {
private constructor(): R|kotlin/Any| {
super<R|kotlin/Any|>()
}