FIR2IR: create local classes on the fly properly

This commit is contained in:
Mikhail Glukhikh
2021-10-29 16:27:19 +03:00
committed by teamcity
parent a05244eca1
commit 67a05883d6
17 changed files with 516 additions and 67 deletions
@@ -24,23 +24,20 @@ import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrEnumConstructorCallImpl
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrEnumEntrySymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeAliasSymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.symbols.impl.*
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.constructors
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.StandardClassIds
class Fir2IrClassifierStorage(
private val converter: Fir2IrConverter,
private val components: Fir2IrComponents
) : Fir2IrComponents by components {
private val firProvider = session.firProvider
@@ -168,16 +165,17 @@ class Fir2IrClassifierStorage(
}
}
private fun createLocalIrClass(klass: FirClass, parent: IrDeclarationParent? = null): IrClass {
// This function is called when we refer local class earlier than we reach its declaration
// This can happen e.g. when implicit return type has a local class constructor
private fun createLocalIrClassOnTheFly(klass: FirClass): IrClass {
// NB: klass can be either FirRegularClass or FirAnonymousObject
if (klass is FirAnonymousObject) {
return createIrAnonymousObject(klass, irParent = parent)
val result = when (klass) {
is FirAnonymousObject -> createIrAnonymousObject(klass, irParent = temporaryParent).apply {
converter.processAnonymousObjectMembers(klass, this)
}
is FirRegularClass -> converter.processLocalClassAndNestedClasses(klass, temporaryParent)
}
val regularClass = klass as FirRegularClass
val origin = regularClass.irOrigin(firProvider)
val irClass = registerIrClass(regularClass, parent, origin)
processClassHeader(regularClass, irClass)
return irClass
return result
}
fun processClassHeader(regularClass: FirRegularClass, irClass: IrClass = getCachedIrClass(regularClass)!!): IrClass {
@@ -434,7 +432,7 @@ class Fir2IrClassifierStorage(
val firClass = firClassSymbol.fir
getCachedIrClass(firClass)?.let { return it.symbol }
if (firClass is FirAnonymousObject || firClass is FirRegularClass && firClass.visibility == Visibilities.Local) {
return createLocalIrClass(firClass).symbol
return createLocalIrClassOnTheFly(firClass).symbol
}
val signature = signatureComposer.composeSignature(firClass)!!
symbolTable.referenceClassIfAny(signature)?.let { irClassSymbol ->
@@ -500,4 +498,16 @@ class Fir2IrClassifierStorage(
?: typeParameterCache[firTypeParameter]?.symbol
?: error("Cannot find cached type parameter by FIR symbol: ${firTypeParameterSymbol.name}")
}
private val temporaryParent by lazy {
irFactory.createFunction(
startOffset = UNDEFINED_OFFSET, endOffset = UNDEFINED_OFFSET,
IrDeclarationOrigin.DEFINED, IrSimpleFunctionSymbolImpl(),
Name.special("<stub>"), DescriptorVisibilities.PRIVATE, Modality.FINAL, irBuiltIns.unitType,
isInline = false, isExternal = false, isTailrec = false,
isSuspend = false, isOperator = false, isInfix = false, isExpect = false
).apply {
parent = IrExternalPackageFragmentImpl(IrExternalPackageFragmentSymbolImpl(), FqName.ROOT)
}
}
}
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi2ir.generators.GeneratorExtensions
@@ -53,24 +52,15 @@ class Fir2IrConverter(
private val generatorExtensions = session.extensionService.declarationGenerators
fun processLocalClassAndNestedClasses(regularClass: FirRegularClass, parent: IrDeclarationParent) {
fun processLocalClassAndNestedClasses(regularClass: FirRegularClass, parent: IrDeclarationParent): IrClass {
val irClass = registerClassAndNestedClasses(regularClass, parent)
processClassAndNestedClassHeaders(regularClass)
processClassMembers(regularClass, irClass)
bindFakeOverridesInClass(irClass)
return irClass
}
fun processRegisteredLocalClassAndNestedClasses(regularClass: FirRegularClass, irClass: IrClass) {
regularClass.declarations.forEach {
if (it is FirRegularClass) {
registerClassAndNestedClasses(it, irClass)
}
}
processClassAndNestedClassHeaders(regularClass)
processClassMembers(regularClass, irClass)
}
fun registerFileAndClasses(file: FirFile, moduleFragment: IrModuleFragment) {
private fun registerFileAndClasses(file: FirFile, moduleFragment: IrModuleFragment) {
val fileEntry = when (file.origin) {
FirDeclarationOrigin.Source -> PsiIrFileEntry(file.psi as KtFile)
FirDeclarationOrigin.Synthetic -> object : IrFileEntry {
@@ -117,7 +107,7 @@ class Fir2IrConverter(
}
}
fun processFileAndClassMembers(file: FirFile) {
private fun processFileAndClassMembers(file: FirFile) {
val irFile = declarationStorage.getIrFile(file)
for (declaration in file.declarations) {
val irDeclaration = processMemberDeclaration(declaration, null, irFile) ?: continue
@@ -129,40 +119,29 @@ class Fir2IrConverter(
anonymousObject: FirAnonymousObject,
irClass: IrClass = classifierStorage.getCachedIrClass(anonymousObject)!!
): IrClass {
registerNestedClasses(anonymousObject, irClass)
processNestedClassHeaders(anonymousObject)
anonymousObject.primaryConstructorIfAny(session)?.let {
irClass.declarations += declarationStorage.createIrConstructor(
it.fir, irClass, isLocal = true
)
}
val processedCallableNames = mutableSetOf<Name>()
val classes = mutableListOf<FirRegularClass>()
for (declaration in syntheticPropertiesLast(anonymousObject.declarations)) {
val irDeclaration = if (declaration is FirRegularClass) {
classes += declaration
registerClassAndNestedClasses(declaration, irClass)
} else {
when (declaration) {
is FirSimpleFunction -> processedCallableNames += declaration.name
is FirProperty -> processedCallableNames += declaration.name
else -> {}
}
processMemberDeclaration(declaration, anonymousObject, irClass) ?: continue
}
val irDeclaration = processMemberDeclaration(declaration, anonymousObject, irClass) ?: continue
irClass.declarations += irDeclaration
}
classes.forEach { processClassAndNestedClassHeaders(it) }
classes.forEach { processClassMembers(it) }
// Add delegated members *before* fake override generations.
// Otherwise, fake overrides for delegated members, which are redundant, will be added.
val realDeclarations = delegatedMembers(irClass) + anonymousObject.declarations
with(fakeOverrideGenerator) {
irClass.addFakeOverrides(anonymousObject, realDeclarations)
}
bindFakeOverridesInClass(irClass)
return irClass
}
private fun processClassMembers(
internal fun processClassMembers(
regularClass: FirRegularClass,
irClass: IrClass = classifierStorage.getCachedIrClass(regularClass)!!
): IrClass {
@@ -241,37 +220,44 @@ class Fir2IrConverter(
}
private fun registerClassAndNestedClasses(regularClass: FirRegularClass, parent: IrDeclarationParent): IrClass {
// Local classes might be referenced before they declared (see usages of Fir2IrClassifierStorage.createLocalIrClassOnTheFly)
// So, we only need to set its parent properly
val irClass =
// Local classes might be referenced before they declared (see usages of Fir2IrClassifierStorage.createLocalIrClass)
// So, we only need to set its parent properly
classifierStorage.getCachedIrClass(regularClass)?.apply {
this.parent = parent
}
?: classifierStorage.registerIrClass(regularClass, parent)
regularClass.declarations.forEach {
} ?: classifierStorage.registerIrClass(regularClass, parent)
registerNestedClasses(regularClass, irClass)
return irClass
}
private fun registerNestedClasses(klass: FirClass, irClass: IrClass) {
klass.declarations.forEach {
if (it is FirRegularClass) {
registerClassAndNestedClasses(it, irClass)
}
}
if (generatorExtensions.isNotEmpty()) {
regularClass.generatedNestedClassifiers(session).forEach {
klass.generatedNestedClassifiers(session).forEach {
if (it is FirRegularClass) {
registerClassAndNestedClasses(it, irClass)
}
}
}
return irClass
}
private fun processClassAndNestedClassHeaders(regularClass: FirRegularClass) {
classifierStorage.processClassHeader(regularClass)
regularClass.declarations.forEach {
processNestedClassHeaders(regularClass)
}
private fun processNestedClassHeaders(klass: FirClass) {
klass.declarations.forEach {
if (it is FirRegularClass) {
processClassAndNestedClassHeaders(it)
}
}
if (generatorExtensions.isNotEmpty()) {
regularClass.generatedNestedClassifiers(session).forEach {
klass.generatedNestedClassifiers(session).forEach {
if (it is FirRegularClass) {
processClassAndNestedClassHeaders(it)
}
@@ -349,7 +335,8 @@ class Fir2IrConverter(
val symbolTable = SymbolTable(signaturer, irFactory)
val signatureComposer = FirBasedSignatureComposer(mangler)
val components = Fir2IrComponentsStorage(session, scopeSession, symbolTable, irFactory, signatureComposer)
val classifierStorage = Fir2IrClassifierStorage(components)
val converter = Fir2IrConverter(moduleDescriptor, components)
val classifierStorage = Fir2IrClassifierStorage(converter, components)
components.classifierStorage = classifierStorage
components.delegatedMemberGenerator = DelegatedMemberGenerator(components)
val declarationStorage = Fir2IrDeclarationStorage(components, moduleDescriptor)
@@ -363,7 +350,6 @@ class Fir2IrConverter(
languageVersionSettings.getFlag(AnalysisFlags.builtInsFromSources)
)
components.irBuiltIns = irBuiltIns
val converter = Fir2IrConverter(moduleDescriptor, components)
val conversionScope = Fir2IrConversionScope()
val fir2irVisitor = Fir2IrVisitor(converter, components, conversionScope)
val builtIns = Fir2IrBuiltIns(components, specialSymbolProvider)
@@ -1171,8 +1171,7 @@ class Fir2IrDeclarationStorage(
dispatchReceiverIrClass.declarations.find {
it is IrSimpleFunction && it.isFakeOverride && it.name == fir.name &&
it.overrides(originalSymbol.owner as IrSimpleFunction)
}?.symbol as? IrFunctionSymbol
?: originalSymbol // Fallback (normally we should not be here, but f/o are bound too late for local classes)
}?.symbol as IrFunctionSymbol
} else {
originalSymbol
}
@@ -1227,8 +1226,7 @@ class Fir2IrDeclarationStorage(
classifierStorage.getIrClassSymbol(dispatchReceiverLookupTag.toSymbol(session) as FirClassSymbol).owner
dispatchReceiverIrClass.declarations.find {
it is IrProperty && it.isFakeOverride && it.name == fir.name && it.overrides(originalSymbol.owner as IrProperty)
}?.symbol as? IrPropertySymbol
?: originalSymbol // Fallback (normally we should not be here, but f/o are bound too late for local classes)
}?.symbol as IrPropertySymbol
} else {
originalSymbol
}
@@ -116,7 +116,6 @@ class Fir2IrVisitor(
classifierStorage.putEnumEntryClassInScope(enumEntry, correspondingClass)
val anonymousObject = (enumEntry.initializer as FirAnonymousObjectExpression).anonymousObject
converter.processAnonymousObjectMembers(anonymousObject, correspondingClass)
converter.bindFakeOverridesInClass(correspondingClass)
conversionScope.withParent(correspondingClass) {
conversionScope.withContainingFirClass(anonymousObject) {
memberGenerator.convertClassContent(correspondingClass, anonymousObject)
@@ -153,7 +152,6 @@ class Fir2IrVisitor(
// NB: for implicit types it is possible that local class is already cached
val irClass = classifierStorage.getCachedIrClass(regularClass)?.apply { this.parent = irParent }
if (irClass != null) {
converter.processRegisteredLocalClassAndNestedClasses(regularClass, irClass)
return conversionScope.withParent(irClass) {
memberGenerator.convertClassContent(irClass, regularClass)
}
@@ -179,9 +177,9 @@ class Fir2IrVisitor(
val irParent = conversionScope.parentFromStack()
// NB: for implicit types it is possible that anonymous object is already cached
val irAnonymousObject = classifierStorage.getCachedIrClass(anonymousObject)?.apply { this.parent = irParent }
?: classifierStorage.createIrAnonymousObject(anonymousObject, irParent = irParent)
converter.processAnonymousObjectMembers(anonymousObject, irAnonymousObject)
converter.bindFakeOverridesInClass(irAnonymousObject)
?: classifierStorage.createIrAnonymousObject(anonymousObject, irParent = irParent).also {
converter.processAnonymousObjectMembers(anonymousObject, it)
}
conversionScope.withParent(irAnonymousObject) {
conversionScope.withContainingFirClass(anonymousObject) {
memberGenerator.convertClassContent(irAnonymousObject, anonymousObject)
@@ -2296,6 +2296,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/firProblems/FirBuilder.kt");
}
@Test
@TestMetadata("FlushFromAnonymous.kt")
public void testFlushFromAnonymous() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/FlushFromAnonymous.kt");
}
@Test
@TestMetadata("ImplicitReceiverStack.kt")
public void testImplicitReceiverStack() throws Exception {
@@ -2332,6 +2338,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/firProblems/kt43342.kt");
}
@Test
@TestMetadata("localClassUsedBeforeDeclaration.kt")
public void testLocalClassUsedBeforeDeclaration() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
}
@Test
@TestMetadata("Modality.kt")
public void testModality() throws Exception {
@@ -0,0 +1,62 @@
FILE fqName:<root> fileName:/FlushFromAnonymous.kt
CLASS CLASS name:Serializer modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Serializer
CONSTRUCTOR visibility:public <> () returnType:<root>.Serializer [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Serializer modality:FINAL visibility:public superTypes:[kotlin.Any]'
FUN name:serialize visibility:public modality:FINAL <> ($this:<root>.Serializer) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.Serializer
BLOCK_BODY
VAR name:messageCollector type:<root>.Serializer.createMessageCollector.<no name provided> [val]
CALL 'private final fun createMessageCollector (): <root>.Serializer.createMessageCollector.<no name provided> declared in <root>.Serializer' type=<root>.Serializer.createMessageCollector.<no name provided> origin=null
$this: GET_VAR '<this>: <root>.Serializer declared in <root>.Serializer.serialize' type=<root>.Serializer origin=null
TRY type=kotlin.Unit
try: BLOCK type=kotlin.Unit origin=null
CATCH parameter=val e: kotlin.Throwable [val] declared in <root>.Serializer.serialize
VAR name:e type:kotlin.Throwable [val]
BLOCK type=kotlin.Unit origin=null
CALL 'public open fun flush (): kotlin.Unit [fake_override] declared in <root>.Serializer.createMessageCollector.<no name provided>' type=kotlin.Unit origin=null
$this: GET_VAR 'val messageCollector: <root>.Serializer.createMessageCollector.<no name provided> [val] declared in <root>.Serializer.serialize' type=<root>.Serializer.createMessageCollector.<no name provided> origin=null
FUN name:createMessageCollector visibility:private modality:FINAL <> ($this:<root>.Serializer) returnType:<root>.Serializer.createMessageCollector.<no name provided>
$this: VALUE_PARAMETER name:<this> type:<root>.Serializer
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun createMessageCollector (): <root>.Serializer.createMessageCollector.<no name provided> declared in <root>.Serializer'
BLOCK type=<root>.Serializer.createMessageCollector.<no name provided> origin=OBJECT_LITERAL
CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[<root>.Collector]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Serializer.createMessageCollector.<no name provided>
CONSTRUCTOR visibility:private <> () returnType:<root>.Serializer.createMessageCollector.<no name provided> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Collector'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[<root>.Collector]'
FUN FAKE_OVERRIDE name:flush visibility:public modality:OPEN <> ($this:<root>.Collector) returnType:kotlin.Unit [fake_override]
overridden:
public open fun flush (): kotlin.Unit declared in <root>.Collector
$this: VALUE_PARAMETER name:<this> type:<root>.Collector
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.Collector
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.Collector
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String [fake_override] declared in <root>.Collector
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CONSTRUCTOR_CALL 'private constructor <init> () [primary] declared in <root>.Serializer.createMessageCollector.<no name provided>' type=<root>.Serializer.createMessageCollector.<no name provided> origin=OBJECT_LITERAL
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -0,0 +1,33 @@
class Serializer {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
fun serialize() {
val messageCollector: <no name provided> = <this>.createMessageCollector()
try { // BLOCK
}
catch (e: Throwable){ // BLOCK
messageCollector.flush()
}
}
private fun createMessageCollector(): <no name provided> {
return { // BLOCK
local class <no name provided> : Collector {
private constructor() /* primary */ {
super/*Collector*/()
/* <init>() */
}
}
<no name provided>()
}
}
}
@@ -0,0 +1,62 @@
FILE fqName:<root> fileName:/FlushFromAnonymous.kt
CLASS CLASS name:Serializer modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Serializer
CONSTRUCTOR visibility:public <> () returnType:<root>.Serializer [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Serializer modality:FINAL visibility:public superTypes:[kotlin.Any]'
FUN name:serialize visibility:public modality:FINAL <> ($this:<root>.Serializer) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.Serializer
BLOCK_BODY
VAR name:messageCollector type:<root>.Serializer.createMessageCollector.<no name provided> [val]
CALL 'private final fun createMessageCollector (): <root>.Serializer.createMessageCollector.<no name provided> declared in <root>.Serializer' type=<root>.Serializer.createMessageCollector.<no name provided> origin=null
$this: GET_VAR '<this>: <root>.Serializer declared in <root>.Serializer.serialize' type=<root>.Serializer origin=null
TRY type=kotlin.Unit
try: BLOCK type=kotlin.Unit origin=null
CATCH parameter=val e: kotlin.Throwable [val] declared in <root>.Serializer.serialize
VAR CATCH_PARAMETER name:e type:kotlin.Throwable [val]
BLOCK type=kotlin.Unit origin=null
CALL 'public open fun flush (): kotlin.Unit [fake_override] declared in <root>.Serializer.createMessageCollector.<no name provided>' type=kotlin.Unit origin=null
$this: GET_VAR 'val messageCollector: <root>.Serializer.createMessageCollector.<no name provided> [val] declared in <root>.Serializer.serialize' type=<root>.Serializer.createMessageCollector.<no name provided> origin=null
FUN name:createMessageCollector visibility:private modality:FINAL <> ($this:<root>.Serializer) returnType:<root>.Serializer.createMessageCollector.<no name provided>
$this: VALUE_PARAMETER name:<this> type:<root>.Serializer
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun createMessageCollector (): <root>.Serializer.createMessageCollector.<no name provided> declared in <root>.Serializer'
BLOCK type=<root>.Serializer.createMessageCollector.<no name provided> origin=OBJECT_LITERAL
CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[<root>.Collector]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Serializer.createMessageCollector.<no name provided>
CONSTRUCTOR visibility:public <> () returnType:<root>.Serializer.createMessageCollector.<no name provided> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Collector'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[<root>.Collector]'
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.Collector
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.Collector
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String [fake_override] declared in <root>.Collector
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:flush visibility:public modality:OPEN <> ($this:<root>.Collector) returnType:kotlin.Unit [fake_override]
overridden:
public open fun flush (): kotlin.Unit declared in <root>.Collector
$this: VALUE_PARAMETER name:<this> type:<root>.Collector
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Serializer.createMessageCollector.<no name provided>' type=<root>.Serializer.createMessageCollector.<no name provided> origin=OBJECT_LITERAL
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -0,0 +1,21 @@
// SKIP_KLIB_TEST
// FILE: Collector.java
public class Collector {
public void flush() {}
}
// FILE: FlushFromAnonymous.kt
class Serializer() {
fun serialize() {
val messageCollector = createMessageCollector()
try {
} catch (e: Throwable) {
messageCollector.flush()
}
}
private fun createMessageCollector() = object : Collector() {}
}
@@ -0,0 +1,33 @@
class Serializer {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
fun serialize() {
val messageCollector: <no name provided> = <this>.createMessageCollector()
try { // BLOCK
}
catch (e: Throwable){ // BLOCK
messageCollector.flush()
}
}
private fun createMessageCollector(): <no name provided> {
return { // BLOCK
local class <no name provided> : Collector {
constructor() /* primary */ {
super/*Collector*/()
/* <init>() */
}
}
<no name provided>()
}
}
}
@@ -0,0 +1,72 @@
FILE fqName:<root> fileName:/localClassUsedBeforeDeclaration.kt
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
CALL 'public final fun <get-ok> (): kotlin.String declared in <root>.box.<no name provided>.A' type=kotlin.String origin=GET_PROPERTY
$this: CALL 'public final fun <get-a> (): <root>.box.<no name provided>.A declared in <root>.box.<no name provided>' type=<root>.box.<no name provided>.A origin=GET_PROPERTY
$this: BLOCK type=<root>.box.<no name provided> origin=OBJECT_LITERAL
CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.box.<no name provided>
CONSTRUCTOR visibility:private <> () returnType:<root>.box.<no name provided> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[kotlin.Any]'
PROPERTY name:a visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:a type:<root>.box.<no name provided>.A visibility:private [final]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> (ok: kotlin.String) [primary] declared in <root>.box.<no name provided>.A' type=<root>.box.<no name provided>.A origin=null
$outer: GET_VAR '<this>: <root>.box.<no name provided> declared in <root>.box.<no name provided>' type=<root>.box.<no name provided> origin=null
ok: CONST String type=kotlin.String value="OK"
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-a> visibility:public modality:FINAL <> ($this:<root>.box.<no name provided>) returnType:<root>.box.<no name provided>.A
correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.box.<no name provided>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-a> (): <root>.box.<no name provided>.A declared in <root>.box.<no name provided>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:<root>.box.<no name provided>.A visibility:private [final]' type=<root>.box.<no name provided>.A origin=null
receiver: GET_VAR '<this>: <root>.box.<no name provided> declared in <root>.box.<no name provided>.<get-a>' type=<root>.box.<no name provided> origin=null
CLASS CLASS name:A modality:FINAL visibility:local [inner] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.box.<no name provided>.A
CONSTRUCTOR visibility:public <> ($this:<root>.box.<no name provided>, ok:kotlin.String) returnType:<root>.box.<no name provided>.A [primary]
$outer: VALUE_PARAMETER name:<this> type:<root>.box.<no name provided>
VALUE_PARAMETER name:ok index:0 type:kotlin.String
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:local [inner] superTypes:[kotlin.Any]'
PROPERTY name:ok visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:ok type:kotlin.String visibility:private [final]
EXPRESSION_BODY
GET_VAR 'ok: kotlin.String declared in <root>.box.<no name provided>.A.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-ok> visibility:public modality:FINAL <> ($this:<root>.box.<no name provided>.A) returnType:kotlin.String
correspondingProperty: PROPERTY name:ok visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.box.<no name provided>.A
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-ok> (): kotlin.String declared in <root>.box.<no name provided>.A'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:ok type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.box.<no name provided>.A declared in <root>.box.<no name provided>.A.<get-ok>' type=<root>.box.<no name provided>.A origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CONSTRUCTOR_CALL 'private constructor <init> () [primary] declared in <root>.box.<no name provided>' type=<root>.box.<no name provided> origin=OBJECT_LITERAL
@@ -0,0 +1,31 @@
fun box(): String {
return { // BLOCK
local class <no name provided> {
private constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
val a: A
field = <this>.A(ok = "OK")
get
local inner class A {
constructor(ok: String) /* primary */ {
super/*Any*/()
/* <init>() */
}
val ok: String
field = ok
get
}
}
<no name provided>()
}.<get-a>().<get-ok>()
}
@@ -0,0 +1,72 @@
FILE fqName:<root> fileName:/localClassUsedBeforeDeclaration.kt
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
CALL 'public final fun <get-ok> (): kotlin.String declared in <root>.box.<no name provided>.A' type=kotlin.String origin=GET_PROPERTY
$this: CALL 'public final fun <get-a> (): <root>.box.<no name provided>.A declared in <root>.box.<no name provided>' type=<root>.box.<no name provided>.A origin=GET_PROPERTY
$this: BLOCK type=<root>.box.<no name provided> origin=OBJECT_LITERAL
CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.box.<no name provided>
CONSTRUCTOR visibility:public <> () returnType:<root>.box.<no name provided> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[kotlin.Any]'
PROPERTY name:a visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:a type:<root>.box.<no name provided>.A visibility:private [final]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> (ok: kotlin.String) [primary] declared in <root>.box.<no name provided>.A' type=<root>.box.<no name provided>.A origin=null
$outer: GET_VAR '<this>: <root>.box.<no name provided> declared in <root>.box.<no name provided>' type=<root>.box.<no name provided> origin=null
ok: CONST String type=kotlin.String value="OK"
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-a> visibility:public modality:FINAL <> ($this:<root>.box.<no name provided>) returnType:<root>.box.<no name provided>.A
correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.box.<no name provided>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-a> (): <root>.box.<no name provided>.A declared in <root>.box.<no name provided>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:<root>.box.<no name provided>.A visibility:private [final]' type=<root>.box.<no name provided>.A origin=null
receiver: GET_VAR '<this>: <root>.box.<no name provided> declared in <root>.box.<no name provided>.<get-a>' type=<root>.box.<no name provided> origin=null
CLASS CLASS name:A modality:FINAL visibility:local [inner] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.box.<no name provided>.A
CONSTRUCTOR visibility:public <> ($this:<root>.box.<no name provided>, ok:kotlin.String) returnType:<root>.box.<no name provided>.A [primary]
$outer: VALUE_PARAMETER name:<this> type:<root>.box.<no name provided>
VALUE_PARAMETER name:ok index:0 type:kotlin.String
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:local [inner] superTypes:[kotlin.Any]'
PROPERTY name:ok visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:ok type:kotlin.String visibility:private [final]
EXPRESSION_BODY
GET_VAR 'ok: kotlin.String declared in <root>.box.<no name provided>.A.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-ok> visibility:public modality:FINAL <> ($this:<root>.box.<no name provided>.A) returnType:kotlin.String
correspondingProperty: PROPERTY name:ok visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.box.<no name provided>.A
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-ok> (): kotlin.String declared in <root>.box.<no name provided>.A'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:ok type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.box.<no name provided>.A declared in <root>.box.<no name provided>.A.<get-ok>' type=<root>.box.<no name provided>.A origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.box.<no name provided>' type=<root>.box.<no name provided> origin=OBJECT_LITERAL
@@ -0,0 +1,6 @@
fun box(): String {
return object {
val a = A("OK")
inner class A(val ok: String)
}.a.ok
}
@@ -0,0 +1,31 @@
fun box(): String {
return { // BLOCK
local class <no name provided> {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
val a: A
field = <this>.A(ok = "OK")
get
local inner class A {
constructor(ok: String) /* primary */ {
super/*Any*/()
/* <init>() */
}
val ok: String
field = ok
get
}
}
<no name provided>()
}.<get-a>().<get-ok>()
}
@@ -2296,6 +2296,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest {
runTest("compiler/testData/ir/irText/firProblems/FirBuilder.kt");
}
@Test
@TestMetadata("FlushFromAnonymous.kt")
public void testFlushFromAnonymous() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/FlushFromAnonymous.kt");
}
@Test
@TestMetadata("ImplicitReceiverStack.kt")
public void testImplicitReceiverStack() throws Exception {
@@ -2332,6 +2338,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest {
runTest("compiler/testData/ir/irText/firProblems/kt43342.kt");
}
@Test
@TestMetadata("localClassUsedBeforeDeclaration.kt")
public void testLocalClassUsedBeforeDeclaration() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
}
@Test
@TestMetadata("Modality.kt")
public void testModality() throws Exception {
@@ -1738,6 +1738,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase {
runTest("compiler/testData/ir/irText/firProblems/FirBuilder.kt");
}
@TestMetadata("FlushFromAnonymous.kt")
public void testFlushFromAnonymous() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/FlushFromAnonymous.kt");
}
@TestMetadata("ImplicitReceiverStack.kt")
public void testImplicitReceiverStack() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/ImplicitReceiverStack.kt");
@@ -1758,6 +1763,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase {
runTest("compiler/testData/ir/irText/firProblems/kt43342.kt");
}
@TestMetadata("localClassUsedBeforeDeclaration.kt")
public void testLocalClassUsedBeforeDeclaration() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
}
@TestMetadata("readWriteProperty.kt")
public void testReadWriteProperty() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/readWriteProperty.kt");