Add synthetic constructors to class member scope, so they won't fly 'in the air' in the backends
This is required mainly for Native compiler since it wont't work correctly on descriptors that are not present in the class.
This commit is contained in:
@@ -130,6 +130,8 @@ public class ConstructorCodegen {
|
||||
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor, typeMapper);
|
||||
|
||||
KtSecondaryConstructor constructor = (KtSecondaryConstructor) descriptorToDeclaration(constructorDescriptor);
|
||||
// Synthetic constructors don't have corresponding declarations
|
||||
if (constructor == null) return;
|
||||
|
||||
functionCodegen.generateMethod(
|
||||
JvmDeclarationOriginKt.OtherOrigin(constructor, constructorDescriptor),
|
||||
|
||||
+1
-2
@@ -44,6 +44,7 @@ class SyntheticClassOrObjectDescriptor(
|
||||
outerScope: LexicalScope,
|
||||
private val modality: Modality,
|
||||
private val visibility: Visibility,
|
||||
override val annotations: Annotations,
|
||||
constructorVisibility: Visibility,
|
||||
private val kind: ClassKind,
|
||||
private val isCompanionObject: Boolean
|
||||
@@ -71,8 +72,6 @@ class SyntheticClassOrObjectDescriptor(
|
||||
this.typeParameters = typeParameters
|
||||
}
|
||||
|
||||
override val annotations: Annotations get() = Annotations.EMPTY
|
||||
|
||||
override fun getModality() = modality
|
||||
override fun getVisibility() = visibility
|
||||
override fun getKind() = kind
|
||||
|
||||
+24
-4
@@ -17,10 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.extensions
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -113,6 +110,22 @@ interface SyntheticResolveExtension {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun generateSyntheticSecondaryConstructors(
|
||||
thisDescriptor: ClassDescriptor,
|
||||
bindingContext: BindingContext,
|
||||
result: MutableCollection<ClassConstructorDescriptor>
|
||||
) {
|
||||
instances.forEach {
|
||||
withLinkageErrorLogger(it) {
|
||||
generateSyntheticSecondaryConstructors(
|
||||
thisDescriptor,
|
||||
bindingContext,
|
||||
result
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,4 +173,11 @@ interface SyntheticResolveExtension {
|
||||
result: MutableSet<PropertyDescriptor>
|
||||
) {
|
||||
}
|
||||
|
||||
fun generateSyntheticSecondaryConstructors(
|
||||
thisDescriptor: ClassDescriptor,
|
||||
bindingContext: BindingContext,
|
||||
result: MutableCollection<ClassConstructorDescriptor>
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -444,7 +444,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
/* parentClassOrObject= */ classOrObject,
|
||||
this, syntheticCompanionName, getSource(),
|
||||
/* outerScope= */ getOuterScope(),
|
||||
Modality.FINAL, PUBLIC, PRIVATE, ClassKind.OBJECT, true);
|
||||
Modality.FINAL, PUBLIC, Annotations.Companion.getEMPTY(), PRIVATE, ClassKind.OBJECT, true);
|
||||
companionDescriptor.initialize();
|
||||
return companionDescriptor;
|
||||
}
|
||||
|
||||
+12
-1
@@ -415,7 +415,18 @@ open class LazyClassMemberScope(
|
||||
}
|
||||
|
||||
private val secondaryConstructors: NotNullLazyValue<Collection<ClassConstructorDescriptor>> =
|
||||
c.storageManager.createLazyValue { resolveSecondaryConstructors() }
|
||||
c.storageManager.createLazyValue { doGetConstructors() }
|
||||
|
||||
private fun doGetConstructors(): Collection<ClassConstructorDescriptor> {
|
||||
val result = mutableListOf<ClassConstructorDescriptor>()
|
||||
result.addAll(resolveSecondaryConstructors())
|
||||
addSyntheticSecondaryConstructors(result)
|
||||
return result
|
||||
}
|
||||
|
||||
private fun addSyntheticSecondaryConstructors(result: MutableCollection<ClassConstructorDescriptor>) {
|
||||
c.syntheticResolveExtension.generateSyntheticSecondaryConstructors(thisDescriptor, trace.bindingContext, result)
|
||||
}
|
||||
|
||||
fun getConstructors(): Collection<ClassConstructorDescriptor> {
|
||||
val result = secondaryConstructors()
|
||||
|
||||
Reference in New Issue
Block a user