diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt index f51fb70581d..0ad89f852b5 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt @@ -973,13 +973,13 @@ class KotlinTypeMapper @JvmOverloads constructor( fun writeFieldSignature( backingFieldType: KotlinType, - propertyDescriptor: PropertyDescriptor, + variableDescriptor: VariableDescriptor, sw: JvmSignatureWriter ) { - if (!propertyDescriptor.isVar) { - mapReturnType(propertyDescriptor, sw, backingFieldType) + if (!variableDescriptor.isVar) { + mapReturnType(variableDescriptor, sw, backingFieldType) } else { - writeParameterType(sw, backingFieldType, propertyDescriptor) + writeParameterType(sw, backingFieldType, variableDescriptor) } } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt index 16b29a4db2b..41562d27439 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt @@ -20,6 +20,8 @@ import org.jetbrains.kotlin.asJava.elements.KtUltraLightSimpleModifierList import org.jetbrains.kotlin.codegen.PropertyCodegen import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor +import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.lexer.KtTokens @@ -35,7 +37,7 @@ private class KtUltraLightSimpleModifierListField( private val support: KtUltraLightSupport, private val declaration: KtNamedDeclaration, owner: KtLightElement, - private val modifiers: Set + private val modifiers: Set, ) : KtUltraLightSimpleModifierList(owner, modifiers, support) { override fun hasModifierProperty(name: String): Boolean = when (name) { PsiModifier.VOLATILE -> hasFieldAnnotation(VOLATILE_ANNOTATION_FQ_NAME) @@ -60,7 +62,7 @@ internal class KtUltraLightFieldForSourceDeclaration( name: String, containingClass: KtLightClass, support: KtUltraLightSupport, - modifiers: Set + modifiers: Set, ) : KtUltraLightFieldImpl(declaration, name, containingClass, support, modifiers), KtLightFieldForSourceDeclarationSupport @@ -69,7 +71,7 @@ internal open class KtUltraLightFieldImpl protected constructor( name: String, private val containingClass: KtLightClass, private val support: KtUltraLightSupport, - modifiers: Set + modifiers: Set, ) : LightFieldBuilder(name, PsiType.NULL, declaration), KtLightField, KtUltraLightElementWithNullabilityAnnotation { @@ -87,12 +89,14 @@ internal open class KtUltraLightFieldImpl protected constructor( override fun getLanguage(): Language = KotlinLanguage.INSTANCE - private val propertyDescriptor: PropertyDescriptor? get() = declaration.resolve() as? PropertyDescriptor + private val variableDescriptor: VariableDescriptor? + get() = declaration.resolve() + ?.let { it as? PropertyDescriptor ?: it as? ValueParameterDescriptor } private val kotlinType: KotlinType? get() = when { declaration is KtProperty && declaration.hasDelegate() -> - propertyDescriptor?.let { + (variableDescriptor as? PropertyDescriptor)?.let { val context = LightClassGenerationSupport.getInstance(project).analyze(declaration) PropertyCodegen.getDelegateTypeForProperty(it, context) } @@ -127,7 +131,7 @@ internal open class KtUltraLightFieldImpl protected constructor( ?: nonExistent() else -> { val kotlinType = declaration.getKotlinType() ?: return@lazyPub PsiType.NULL - val descriptor = propertyDescriptor ?: return@lazyPub PsiType.NULL + val descriptor = variableDescriptor ?: return@lazyPub PsiType.NULL support.mapType(this) { typeMapper, sw -> typeMapper.writeFieldSignature(kotlinType, descriptor, sw) @@ -155,7 +159,7 @@ internal open class KtUltraLightFieldImpl protected constructor( if (!declaration.hasInitializer()) return@lazyPub null if (!hasModifierProperty(PsiModifier.FINAL)) return@lazyPub null if (!TypeConversionUtil.isPrimitiveAndNotNull(_type) && !_type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) return@lazyPub null - propertyDescriptor?.compileTimeInitializer + variableDescriptor?.compileTimeInitializer } override fun computeConstantValue(): Any? = _constantInitializer?.value diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightMembersCreator.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightMembersCreator.kt index 6e8e53462bf..ff8d8b4e24f 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightMembersCreator.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightMembersCreator.kt @@ -58,11 +58,12 @@ internal class UltraLightMembersCreator( usedPropertyNames: HashSet, forceStatic: Boolean ): KtLightField? { - val property = variable as? KtProperty - if (property != null && !hasBackingField(property)) return null + + if (!hasBackingField(variable)) return null if (variable.hasAnnotation(JVM_SYNTHETIC_ANNOTATION_FQ_NAME) || variable.hasExpectModifier()) return null + val property = variable as? KtProperty val hasDelegate = property?.hasDelegate() == true val fieldName = generateUniqueFieldName((variable.name ?: "") + (if (hasDelegate) "\$delegate" else ""), usedPropertyNames) @@ -93,9 +94,11 @@ internal class UltraLightMembersCreator( return KtUltraLightFieldForSourceDeclaration(variable, fieldName, containingClass, support, modifiers) } - private fun hasBackingField(property: KtProperty): Boolean { + private fun hasBackingField(property: KtCallableDeclaration): Boolean { if (property.hasModifier(ABSTRACT_KEYWORD)) return false - if (property.hasModifier(LATEINIT_KEYWORD) || property.accessors.isEmpty()) return true + if (property.hasModifier(LATEINIT_KEYWORD)) return true + if (property is KtParameter) return true + if ((property as? KtProperty)?.accessors?.isEmpty() == true) return true val context = LightClassGenerationSupport.getInstance(containingClass.project).analyze(property) val descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, property) @@ -237,7 +240,7 @@ internal class UltraLightMembersCreator( ) return PsiType.VOID val desc = - ktDeclaration.resolve()?.getterIfProperty() as? FunctionDescriptor + ktDeclaration.resolve()?.getterIfProperty() as? CallableDescriptor ?: return PsiType.NULL return support.mapType(wrapper) { typeMapper, signatureWriter ->