[JS IR BE] Fix Ir Copier

* use symbol table to allocate classifier for IrType
This commit is contained in:
Roman Artemev
2018-09-13 16:26:17 +03:00
committed by romanart
parent 6bb77ba51d
commit a8b44c9e18
3 changed files with 17 additions and 13 deletions
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.impl.createValueSymbol
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.DeepCopyIrTree
import org.jetbrains.kotlin.ir.util.withScope
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
@@ -508,16 +509,19 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
//---------------------------------------------------------------------//
override fun visitFunction(declaration: IrFunction): IrFunction =
IrFunctionImpl(
startOffset = declaration.startOffset,
endOffset = declaration.endOffset,
origin = mapDeclarationOrigin(declaration.origin),
descriptor = mapFunctionDeclaration(declaration.descriptor),
body = declaration.body?.transform(this, null)
).also {
it.setOverrides(context.symbolTable)
}.transformParameters(declaration)
override fun visitFunction(declaration: IrFunction) =
context.symbolTable.withScope(mapFunctionDeclaration(declaration.descriptor)) { descriptor ->
IrFunctionImpl(
startOffset = declaration.startOffset,
endOffset = declaration.endOffset,
origin = mapDeclarationOrigin(declaration.origin),
descriptor = descriptor,
body = declaration.body?.transform(this@InlineCopyIr, null)
).also {
it.setOverrides(context.symbolTable)
it.transformParameters(declaration)
}
}
//---------------------------------------------------------------------//
@@ -145,6 +145,6 @@ fun KotlinType.toIrType(symbolTable: SymbolTable? = null): IrType? {
// TODO: this function creates unbound symbol which is the great source of problems
private fun ClassifierDescriptor.getSymbol(symbolTable: SymbolTable?): IrClassifierSymbol = when (this) {
is ClassDescriptor -> symbolTable?.referenceClass(this) ?: IrClassSymbolImpl(this)
is TypeParameterDescriptor -> /*symbolTable?.referenceTypeParameter(this) ?: */IrTypeParameterSymbolImpl(this)
is TypeParameterDescriptor -> symbolTable?.referenceTypeParameter(this) ?: IrTypeParameterSymbolImpl(this)
else -> TODO()
}
@@ -413,9 +413,9 @@ open class SymbolTable : ReferenceSymbolTable {
}
}
inline fun <T> SymbolTable.withScope(owner: DeclarationDescriptor, block: SymbolTable.() -> T): T {
inline fun <T, D: DeclarationDescriptor> SymbolTable.withScope(owner: D, block: SymbolTable.(D) -> T): T {
enterScope(owner)
val result = block(this)
val result = block(owner)
leaveScope(owner)
return result
}