Fix provided properties access generation

The presense of accessors in the descriptor led to the wrong code
generation in some cases.
#KT-43176 fixed
This commit is contained in:
Ilya Chernikov
2020-12-10 15:36:40 +01:00
parent ffdcda8914
commit 1bd6cc823c
4 changed files with 48 additions and 57 deletions
@@ -8,9 +8,6 @@ package org.jetbrains.kotlin.scripting.resolve
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.PropertySetterDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.name.Name
class ScriptProvidedPropertyDescriptor(
@@ -24,7 +21,7 @@ class ScriptProvidedPropertyDescriptor(
null,
Annotations.EMPTY,
Modality.FINAL,
DescriptorVisibilities.PRIVATE,
DescriptorVisibilities.PUBLIC,
isVar,
name,
CallableMemberDescriptor.Kind.SYNTHESIZED,
@@ -34,58 +31,7 @@ class ScriptProvidedPropertyDescriptor(
) {
init {
setType(typeDescriptor.defaultType, emptyList(), receiver, null)
initialize(
makePropertyGetterDescriptor(),
if (!isVar) null else makePropertySetterDescriptor()
)
// TODO: consider delegation instead
initialize(null, null, null, null)
}
}
private fun PropertyDescriptorImpl.makePropertyGetterDescriptor() =
PropertyGetterDescriptorImpl(
this,
Annotations.EMPTY,
this.modality,
this.visibility,
/* isDefault = */
false, /* isExternal = */
false, /* isInline = */
false,
this.kind,
null,
SourceElement.NO_SOURCE
).also {
it.initialize(returnType)
}
private fun PropertyDescriptorImpl.makePropertySetterDescriptor() =
PropertySetterDescriptorImpl(
this,
Annotations.EMPTY,
this.modality,
this.visibility,
/* isDefault = */
false, /* isExternal = */
false, /* isInline = */
false,
this.kind,
null,
SourceElement.NO_SOURCE
).also {
it.initialize(
ValueParameterDescriptorImpl(
this,
null,
0,
Annotations.EMPTY,
Name.special("<set-?>"),
returnType,
/* declaresDefaultValue = */
false, /* isCrossinline = */
false, /* isNoinline = */
false,
null,
SourceElement.NO_SOURCE
)
)
}