KT-37448 'this' in delegating constructor call may refer to outer object

This commit is contained in:
Dmitry Petrov
2020-03-12 11:32:57 +03:00
parent 2bd5872782
commit c0b15b1768
13 changed files with 266 additions and 2 deletions
@@ -368,10 +368,11 @@ class StatementGenerator(
override fun visitSafeQualifiedExpression(expression: KtSafeQualifiedExpression, data: Nothing?): IrStatement =
expression.selectorExpression!!.accept(this, data)
private fun isInsideClass(classDescriptor: ClassDescriptor): Boolean {
private fun isThisForClassPhysicallyAvailable(classDescriptor: ClassDescriptor): Boolean {
var scopeDescriptor: DeclarationDescriptor? = scopeOwner
while (scopeDescriptor != null) {
if (scopeDescriptor == classDescriptor) return true
if (scopeDescriptor is ClassDescriptor && !scopeDescriptor.isInner) return false
scopeDescriptor = scopeDescriptor.containingDeclaration
}
return false
@@ -381,7 +382,7 @@ class StatementGenerator(
val thisAsReceiverParameter = classDescriptor.thisAsReceiverParameter
val thisType = kotlinType.toIrType()
return if (DescriptorUtils.isObject(classDescriptor) && !isInsideClass(classDescriptor)) {
return if (DescriptorUtils.isObject(classDescriptor) && !isThisForClassPhysicallyAvailable(classDescriptor)) {
IrGetObjectValueImpl(
startOffset, endOffset,
thisType,