JVM_IR KT-42758 don't use 'this' for object self-reference by name

This commit is contained in:
Dmitry Petrov
2020-11-19 12:51:03 +03:00
parent 118a7d4e34
commit e17158d961
11 changed files with 203 additions and 7 deletions
@@ -52,13 +52,6 @@ private class SingletonReferencesLowering(val context: JvmBackendContext) : File
}
override fun visitGetObjectValue(expression: IrGetObjectValue): IrExpression {
// When in an instance method of the object, use the dispatch receiver. Do not use the dispatch
// receiver in the constructor, as in the case of an `object` the only way it can be used is
// in a super constructor call argument (=> it has JVM type "uninitialized this" and is not usable)
// while for a `companion object` all initializers are in `<clinit>` and have no receiver at all.
thisOfClass(expression.symbol.owner, false)?.let {
return IrGetValueImpl(expression.startOffset, expression.endOffset, it.symbol)
}
val instanceField = if (allScopes.any { it.irElement == expression.symbol.owner })
context.cachedDeclarations.getPrivateFieldForObjectInstance(expression.symbol.owner) // Constructor or static method.
else