Forbade caching of KProperty for local delegated properties.

This commit is contained in:
Igor Chevdar
2017-03-07 20:23:33 +03:00
parent bc0772eab1
commit 1a5434bada
@@ -99,8 +99,9 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
val propertyDescriptor = expression.descriptor as? VariableDescriptorWithAccessors val propertyDescriptor = expression.descriptor as? VariableDescriptorWithAccessors
if (propertyDescriptor == null) return expression if (propertyDescriptor == null) return expression
val receiversCount = listOf(expression.dispatchReceiver, expression.extensionReceiver).count { it != null } val receiversCount = listOf(expression.dispatchReceiver, expression.extensionReceiver).count { it != null }
when (receiversCount) { if (receiversCount == 1 || propertyDescriptor !is PropertyDescriptor) // Has receiver or is local delegated.
0 -> { // Cache KProperties with no arguments. return createKProperty(expression, propertyDescriptor)
else if (receiversCount == 0) { // Cache KProperties with no arguments.
val field = kProperties.getOrPut(propertyDescriptor) { val field = kProperties.getOrPut(propertyDescriptor) {
createKProperty(expression, propertyDescriptor) to kProperties.size createKProperty(expression, propertyDescriptor) to kProperties.size
} }
@@ -110,9 +111,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
putValueArgument(0, IrConstImpl.int(startOffset, endOffset, context.builtIns.intType, field.second)) putValueArgument(0, IrConstImpl.int(startOffset, endOffset, context.builtIns.intType, field.second))
} }
} }
1 -> return createKProperty(expression, propertyDescriptor) else throw AssertionError("Callable reference to properties with two receivers is not allowed: $propertyDescriptor")
else -> throw AssertionError("Callable reference to properties with two receivers is not allowed: $propertyDescriptor")
}
} }
}) })