diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedClassDescriptor.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedClassDescriptor.kt index 79f60312099..60dc8297f0a 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedClassDescriptor.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedClassDescriptor.kt @@ -92,8 +92,12 @@ class CommonizedClassDescriptor( if (isExpect && kind.isSingleton) { check(constructors.isEmpty()) - primaryConstructor = createPrimaryConstructorForObject(this, SourceElement.NO_SOURCE).apply { returnType = getDefaultType() } - this.constructors = listOf(primaryConstructor!!) + primaryConstructor = if (kind == ClassKind.ENUM_ENTRY) + createPrimaryConstructorForObject(this, SourceElement.NO_SOURCE).apply { returnType = getDefaultType() } + else + null + + this.constructors = listOfNotNull(primaryConstructor) } else { constructors.forEach { it.returnType = getDefaultType() } diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedTypeAliasDescriptor.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedTypeAliasDescriptor.kt index e08755b067c..4c90a97eb66 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedTypeAliasDescriptor.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedTypeAliasDescriptor.kt @@ -40,8 +40,8 @@ class CommonizedTypeAliasDescriptor( override fun isActual() = isActual - fun initialize(underlyingType: SimpleType, expandedType: SimpleType) { - super.initialize(emptyList()) + fun initialize(declaredTypeParameters: List, underlyingType: SimpleType, expandedType: SimpleType) { + super.initialize(declaredTypeParameters) this.underlyingType = underlyingType this.expandedType = expandedType typeConstructorParameters = computeConstructorTypeParameters() @@ -60,6 +60,7 @@ class CommonizedTypeAliasDescriptor( isActual = isActual ) substituted.initialize( + declaredTypeParameters, substitutor.safeSubstitute(underlyingType, Variance.INVARIANT).asSimpleType(), substitutor.safeSubstitute(expandedType, Variance.INVARIANT).asSimpleType() ) diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt index 37f0e0741f8..69817d509d8 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt @@ -5,10 +5,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder -import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroup import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.indexOfCommon @@ -20,9 +17,10 @@ internal fun ClassNode.buildDescriptors( storageManager: StorageManager ) { val commonClass = common() + val markAsActual = commonClass != null && commonClass.kind != ClassKind.ENUM_ENTRY target.forEachIndexed { index, clazz -> - clazz?.buildDescriptor(output, index, containingDeclarations, storageManager, isActual = commonClass != null) + clazz?.buildDescriptor(output, index, containingDeclarations, storageManager, isActual = markAsActual) } commonClass?.buildDescriptor(output, indexOfCommon, containingDeclarations, storageManager, isExpect = true) @@ -67,13 +65,13 @@ internal fun ClassConstructorNode.buildDescriptors( containingDeclarations: List ) { val commonConstructor = common() + val markAsActual = commonConstructor != null target.forEachIndexed { index, constructor -> - constructor?.buildDescriptor(output, index, containingDeclarations, isActual = commonConstructor != null) + constructor?.buildDescriptor(output, index, containingDeclarations, isActual = markAsActual) } commonConstructor?.buildDescriptor(output, indexOfCommon, containingDeclarations, isExpect = true) - } private fun ClassConstructor.buildDescriptor( diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt index 9c8e39f53f8..6bdb5024826 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.descriptors.SourceElement @@ -19,12 +20,13 @@ internal fun FunctionNode.buildDescriptors( containingDeclarations: List ) { val commonFunction = common() + val markAsExpectAndActual = commonFunction != null && commonFunction.kind != CallableMemberDescriptor.Kind.SYNTHESIZED target.forEachIndexed { index, function -> - function?.buildDescriptor(output, index, containingDeclarations, isActual = commonFunction != null) + function?.buildDescriptor(output, index, containingDeclarations, isActual = markAsExpectAndActual) } - commonFunction?.buildDescriptor(output, indexOfCommon, containingDeclarations, isExpect = true) + commonFunction?.buildDescriptor(output, indexOfCommon, containingDeclarations, isExpect = markAsExpectAndActual) } private fun Function.buildDescriptor( diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt index 4c5ef4e92a4..5d703a1abc5 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.SourceElement @@ -23,12 +24,16 @@ internal fun PropertyNode.buildDescriptors( storageManager: StorageManager ) { val commonProperty = common() + val markAsExpectAndActual = commonProperty != null && commonProperty.kind != CallableMemberDescriptor.Kind.SYNTHESIZED target.forEachIndexed { index, property -> - property?.buildDescriptor(output, index, containingDeclarations, storageManager, isActual = commonProperty != null) + // target property is DELEGATION + // AND + // the property it overrides is actual + property?.buildDescriptor(output, index, containingDeclarations, storageManager, isActual = markAsExpectAndActual) } - commonProperty?.buildDescriptor(output, indexOfCommon, containingDeclarations, storageManager, isExpect = true) + commonProperty?.buildDescriptor(output, indexOfCommon, containingDeclarations, storageManager, isExpect = markAsExpectAndActual) } private fun Property.buildDescriptor( diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt index 61b0789092a..f6acf009d29 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt @@ -20,9 +20,10 @@ internal fun TypeAliasNode.buildDescriptors( storageManager: StorageManager ) { val commonClass: ClassDeclaration? = common() + val markAsActual = commonClass != null target.forEachIndexed { index, typeAlias -> - typeAlias?.buildDescriptor(output, index, containingDeclarations, storageManager, isActual = commonClass != null) + typeAlias?.buildDescriptor(output, index, containingDeclarations, storageManager, isActual = markAsActual) } commonClass?.buildDescriptor(output, indexOfCommon, containingDeclarations, storageManager, isExpect = true) @@ -46,7 +47,11 @@ private fun TypeAlias.buildDescriptor( isActual = isActual ) - typeAliasDescriptor.initialize(underlyingType, expandedType) + typeAliasDescriptor.initialize( + declaredTypeParameters = typeParameters.buildDescriptors(typeAliasDescriptor), + underlyingType = underlyingType, + expandedType = expandedType + ) output[index] = typeAliasDescriptor } diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt index ac7b641f1b5..11a29c2f7de 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt @@ -5,8 +5,12 @@ package org.jetbrains.kotlin.descriptors.commonizer.core +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DELEGATION +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.FunctionOrProperty +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.isNonAbstractMemberInInterface import org.jetbrains.kotlin.name.Name abstract class AbstractFunctionOrPropertyCommonizer(cache: ClassifiersCache) : AbstractStandardCommonizer() { @@ -15,14 +19,19 @@ abstract class AbstractFunctionOrPropertyCommonizer(cach protected val visibility = VisibilityCommonizer.lowering() protected val extensionReceiver = ExtensionReceiverCommonizer.default(cache) protected val returnType = TypeCommonizer.default(cache) + protected lateinit var kind: CallableMemberDescriptor.Kind protected val typeParameters = TypeParameterListCommonizer.default(cache) override fun initialize(first: T) { name = first.name + kind = first.kind } - override fun doCommonizeWith(next: T) = - !next.isNonAbstractCallableMemberInInterface // non-abstract callable members declared in interface can't be commonized + override fun doCommonizeWith(next: T): Boolean = + !next.isNonAbstractMemberInInterface() // non-abstract callable members declared in interface can't be commonized + && next.kind != DELEGATION // delegated members should not be commonized + && (next.kind != SYNTHESIZED || next.containingClassIsData != true) // synthesized members of data classes should not be commonized + && kind == next.kind && modality.commonizeWith(next.modality) && visibility.commonizeWith(next) && extensionReceiver.commonizeWith(next.extensionReceiver) diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractListCommonizer.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractListCommonizer.kt index 9f411320703..7ce2cae2c57 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractListCommonizer.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractListCommonizer.kt @@ -41,7 +41,7 @@ abstract class AbstractListCommonizer( if (commonizers.size != next.size) // lists must be of the same size error = true else - for (index in 0 until next.size) { + for (index in next.indices) { val commonizer = commonizers[index] val nextElement = next[index] diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt index c9296a08d47..05df9913d2e 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt @@ -45,7 +45,6 @@ class ClassCommonizer(cache: ClassifiersCache) : AbstractStandardCommonizer { } private class DefaultModalityCommonizer : ModalityCommonizer { - private enum class State { - EMPTY { - override fun getNext(modality: Modality) = when (modality) { - Modality.ABSTRACT -> CAN_HAVE_ONLY_ABSTRACT - Modality.SEALED -> CAN_HAVE_ONLY_SEALED - Modality.FINAL -> HAS_FINAL - Modality.OPEN -> HAS_OPEN - } - }, - ERROR { - override fun getNext(modality: Modality) = ERROR - }, - CAN_HAVE_ONLY_SEALED { - override fun getNext(modality: Modality) = if (modality == Modality.SEALED) this else ERROR - }, - CAN_HAVE_ONLY_ABSTRACT { - override fun getNext(modality: Modality) = if (modality == Modality.ABSTRACT) this else ERROR - }, - HAS_FINAL { - override fun getNext(modality: Modality) = when (modality) { - Modality.FINAL -> this - Modality.OPEN -> HAS_FINAL_AND_OPEN - else -> ERROR - } - }, - HAS_OPEN { - override fun getNext(modality: Modality) = when (modality) { - Modality.FINAL -> HAS_FINAL_AND_OPEN - Modality.OPEN -> this - else -> ERROR - } - }, - HAS_FINAL_AND_OPEN { - override fun getNext(modality: Modality) = when (modality) { - Modality.FINAL, Modality.OPEN -> this - else -> ERROR - } - }; - - abstract fun getNext(modality: Modality): State - } - - private var state = State.EMPTY + private var temp: Modality? = null + private var error = false override val result: Modality - get() = when (state) { - State.CAN_HAVE_ONLY_SEALED -> Modality.SEALED - State.CAN_HAVE_ONLY_ABSTRACT -> Modality.ABSTRACT - State.HAS_FINAL, State.HAS_FINAL_AND_OPEN -> Modality.FINAL - State.HAS_OPEN -> Modality.OPEN - else -> throw IllegalCommonizerStateException() - } + get() = temp?.takeIf { !error } ?: throw IllegalCommonizerStateException() override fun commonizeWith(next: Modality): Boolean { - state = state.getNext(next) - return state != State.ERROR + if (error) + return false + + val temp = temp + this.temp = if (temp != null) getNext(temp, next) else next + error = this.temp == null + + return !error + } + + private fun getNext(current: Modality, next: Modality): Modality? = when { + current == Modality.FINAL && next == Modality.OPEN -> Modality.FINAL + current == Modality.OPEN && next == Modality.FINAL -> Modality.FINAL + current == next -> current + else -> null } } diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertyCommonizer.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertyCommonizer.kt index 78f22a352a4..c60c931998b 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertyCommonizer.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertyCommonizer.kt @@ -21,6 +21,7 @@ class PropertyCommonizer(cache: ClassifiersCache) : AbstractFunctionOrPropertyCo isExternal = isExternal, extensionReceiver = extensionReceiver.result?.toReceiverNoAnnotations(), returnType = returnType.result, + kind = kind, setter = setter.result, typeParameters = typeParameters.result ) diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/VisibilityCommonizer.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/VisibilityCommonizer.kt index 5e71e7109a5..f28ff62b1d1 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/VisibilityCommonizer.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/VisibilityCommonizer.kt @@ -7,7 +7,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.DeclarationWithVisibility -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.MaybeVirtualCallableMember +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.FunctionOrProperty +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.isVirtual abstract class VisibilityCommonizer(private val allowPrivate: Boolean) : Commonizer { @@ -19,9 +20,7 @@ abstract class VisibilityCommonizer(private val allowPrivate: Boolean) : Commoni private var temp: Visibility? = null override val result: Visibility - get() { - return temp?.takeIf { it != Visibilities.UNKNOWN } ?: throw IllegalCommonizerStateException() - } + get() = temp?.takeIf { it != Visibilities.UNKNOWN } ?: throw IllegalCommonizerStateException() override fun commonizeWith(next: DeclarationWithVisibility): Boolean { if (temp == Visibilities.UNKNOWN) @@ -52,7 +51,7 @@ private class LoweringVisibilityCommonizer(allowPrivate: Boolean) : VisibilityCo override fun canBeCommonized(next: DeclarationWithVisibility): Boolean { if (!atLeastOneVirtualCallableMet) - atLeastOneVirtualCallableMet = (next as? MaybeVirtualCallableMember)?.isVirtual == true + atLeastOneVirtualCallableMet = (next as? FunctionOrProperty)?.isVirtual() == true return !atLeastOneVirtualCallableMet || !atLeastTwoVisibilitiesMet } diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/facade.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/facade.kt index 190db97da9a..d2bae3b165c 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/facade.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/facade.kt @@ -12,11 +12,6 @@ import org.jetbrains.kotlin.descriptors.commonizer.core.CommonizationVisitor import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.mergeRoots import org.jetbrains.kotlin.storage.LockBasedStorageManager -class CommonizationSession { - // TODO (???): add progress tracker - // TODO (???): add logger -} - class CommonizationParameters { private val modulesByTargets = LinkedHashMap>() diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/ClassDeclaration.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/ClassDeclaration.kt index 23e17ce4ded..581b58d7a85 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/ClassDeclaration.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/ClassDeclaration.kt @@ -13,22 +13,23 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.types.KotlinType import kotlin.LazyThreadSafetyMode.PUBLICATION -interface ClassDeclaration : AnnotatedDeclaration, NamedDeclaration, DeclarationWithTypeParameters, DeclarationWithVisibility { +interface ClassDeclaration : AnnotatedDeclaration, NamedDeclaration, DeclarationWithTypeParameters, DeclarationWithVisibility, DeclarationWithModality { val companion: FqName? // null means no companion object val kind: ClassKind - val modality: Modality val isCompanion: Boolean val isData: Boolean val isInline: Boolean val isInner: Boolean val isExternal: Boolean - val sealedSubclasses: Collection val supertypes: Collection } -interface ClassConstructor : AnnotatedDeclaration, DeclarationWithTypeParameters, DeclarationWithVisibility, CallableMemberWithParameters { +interface ClassConstructor : AnnotatedDeclaration, DeclarationWithTypeParameters, DeclarationWithVisibility, MaybeCallableMemberOfClass, CallableMemberWithParameters { val isPrimary: Boolean val kind: CallableMemberDescriptor.Kind + override val containingClassKind: ClassKind + override val containingClassModality: Modality + override val containingClassIsData: Boolean } data class CommonClassDeclaration( @@ -45,7 +46,6 @@ data class CommonClassDeclaration( override val isData get() = false override val isExternal get() = false override var companion: FqName? = null - override val sealedSubclasses: Collection get() = emptyList() override val supertypes: MutableCollection = ArrayList() } @@ -59,6 +59,9 @@ data class CommonClassConstructor( override val hasSynthesizedParameterNames: Boolean ) : ClassConstructor { override val annotations: Annotations get() = Annotations.EMPTY + override val containingClassKind: ClassKind get() = unsupported() + override val containingClassModality: Modality get() = unsupported() + override val containingClassIsData: Boolean get() = unsupported() } class TargetClassDeclaration(private val descriptor: ClassDescriptor) : ClassDeclaration { @@ -74,13 +77,15 @@ class TargetClassDeclaration(private val descriptor: ClassDescriptor) : ClassDec override val isInline get() = descriptor.isInline override val isInner get() = descriptor.isInner override val isExternal get() = descriptor.isExternal - override val sealedSubclasses by lazy(PUBLICATION) { descriptor.sealedSubclasses.map { it.fqNameSafe } } override val supertypes: Collection get() = descriptor.typeConstructor.supertypes } class TargetClassConstructor(private val descriptor: ClassConstructorDescriptor) : ClassConstructor { override val isPrimary: Boolean get() = descriptor.isPrimary override val kind: CallableMemberDescriptor.Kind get() = descriptor.kind + override val containingClassKind: ClassKind get() = descriptor.containingDeclaration.kind + override val containingClassModality: Modality get() = descriptor.containingDeclaration.modality + override val containingClassIsData: Boolean get() = descriptor.containingDeclaration.isData override val annotations: Annotations get() = descriptor.annotations override val visibility: Visibility get() = descriptor.visibility override val typeParameters: List by lazy(PUBLICATION) { descriptor.typeParameters.map(::TargetTypeParameter) } @@ -98,7 +103,6 @@ object ClassDeclarationRecursionMarker : ClassDeclaration, RecursionMarker { override val isInline: Boolean get() = unsupported() override val isInner: Boolean get() = unsupported() override val isExternal: Boolean get() = unsupported() - override val sealedSubclasses: Collection get() = unsupported() override val supertypes: Collection get() = unsupported() override val annotations: Annotations get() = unsupported() override val name: Name get() = unsupported() diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Declaration.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Declaration.kt index eb75c600ef2..3f0b1b790de 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Declaration.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Declaration.kt @@ -36,8 +36,14 @@ interface DeclarationWithVisibility : Declaration { val visibility: Visibility } -interface MaybeVirtualCallableMember : DeclarationWithVisibility { - val isVirtual: Boolean +interface DeclarationWithModality : Declaration { + val modality: Modality +} + +interface MaybeCallableMemberOfClass : Declaration { + val containingClassKind: ClassKind? // null assumes no containing class + val containingClassModality: Modality? // null assumes no containing class + val containingClassIsData: Boolean? // null assumes no containing class } interface DeclarationWithTypeParameters : Declaration { @@ -47,5 +53,5 @@ interface DeclarationWithTypeParameters : Declaration { /** Indicates presence of recursion in lazy calculations. */ interface RecursionMarker : Declaration -@Suppress("unused") -internal fun Declaration.unsupported(): Nothing = error("This method should never be called") +@Suppress("unused", "NOTHING_TO_INLINE") +internal inline fun Declaration.unsupported(): Nothing = error("This method should never be called") diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Function.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Function.kt index ba5be2966aa..916cb79eb07 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Function.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Function.kt @@ -5,10 +5,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir -import org.jetbrains.kotlin.descriptors.Modality -import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor -import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.UnwrappedType @@ -37,6 +34,7 @@ data class CommonFunction( override val visibility: Visibility, override val extensionReceiver: ExtensionReceiver?, override val returnType: UnwrappedType, + override val kind: CallableMemberDescriptor.Kind, private val modifiers: FunctionModifiers, override val valueParameters: List, override val typeParameters: List, diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/FunctionOrProperty.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/FunctionOrProperty.kt index 897afcd96bc..413ad23baca 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/FunctionOrProperty.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/FunctionOrProperty.kt @@ -11,20 +11,18 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiv import org.jetbrains.kotlin.types.UnwrappedType import kotlin.LazyThreadSafetyMode.PUBLICATION -interface FunctionOrProperty : AnnotatedDeclaration, NamedDeclaration, DeclarationWithTypeParameters, MaybeVirtualCallableMember { - val modality: Modality +interface FunctionOrProperty : AnnotatedDeclaration, NamedDeclaration, DeclarationWithTypeParameters, DeclarationWithVisibility, DeclarationWithModality, MaybeCallableMemberOfClass { val isExternal: Boolean val extensionReceiver: ExtensionReceiver? val returnType: UnwrappedType val kind: CallableMemberDescriptor.Kind - val isNonAbstractCallableMemberInInterface: Boolean } abstract class CommonFunctionOrProperty : FunctionOrProperty { final override val annotations get() = Annotations.EMPTY - final override val kind get() = CallableMemberDescriptor.Kind.DECLARATION - final override val isVirtual get() = unsupported() - final override val isNonAbstractCallableMemberInInterface get() = unsupported() + final override val containingClassKind: ClassKind? get() = unsupported() + final override val containingClassModality: Modality? get() = unsupported() + final override val containingClassIsData: Boolean? get() = unsupported() } abstract class TargetFunctionOrProperty(protected val descriptor: T) : FunctionOrProperty { @@ -36,10 +34,11 @@ abstract class TargetFunctionOrProperty(protected final override val extensionReceiver by lazy(PUBLICATION) { descriptor.extensionReceiverParameter?.toReceiver() } final override val returnType by lazy(PUBLICATION) { descriptor.returnType!!.unwrap() } final override val kind get() = descriptor.kind - final override val isVirtual get() = descriptor.isOverridable - final override val isNonAbstractCallableMemberInInterface - get() = modality != Modality.ABSTRACT && (descriptor.containingDeclaration as? ClassDescriptor)?.kind == ClassKind.INTERFACE + final override val containingClassKind: ClassKind? get() = containingClass?.kind + final override val containingClassModality: Modality? get() = containingClass?.modality + final override val containingClassIsData: Boolean? get() = containingClass?.isData final override val typeParameters by lazy(PUBLICATION) { descriptor.typeParameters.map(::TargetTypeParameter) } + private val containingClass: ClassDescriptor? get() = descriptor.containingDeclaration as? ClassDescriptor } data class ExtensionReceiver( @@ -51,3 +50,11 @@ data class ExtensionReceiver( fun ReceiverParameterDescriptor.toReceiver() = ExtensionReceiver(annotations, type.unwrap()) } } + +fun FunctionOrProperty.isNonAbstractMemberInInterface() = + modality != Modality.ABSTRACT && containingClassKind == ClassKind.INTERFACE + +fun FunctionOrProperty.isVirtual() = + visibility != Visibilities.PRIVATE + && modality != Modality.FINAL + && !(containingClassModality == Modality.FINAL && containingClassKind != ClassKind.ENUM_CLASS) diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Property.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Property.kt index b3db717f50e..54c9c37a2df 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Property.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/Property.kt @@ -33,6 +33,7 @@ data class CommonProperty( override val isExternal: Boolean, override val extensionReceiver: ExtensionReceiver?, override val returnType: UnwrappedType, + override val kind: CallableMemberDescriptor.Kind, override val setter: Setter?, override val typeParameters: List ) : CommonFunctionOrProperty(), Property { @@ -89,9 +90,7 @@ data class Setter( override val isDefault: Boolean, override val isExternal: Boolean, override val isInline: Boolean -) : PropertyAccessor, MaybeVirtualCallableMember { - override val isVirtual get() = false - +) : PropertyAccessor, DeclarationWithVisibility { companion object { fun createDefaultNoAnnotations(visibility: Visibility) = Setter( Annotations.EMPTY, diff --git a/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/commonized/js/package_root.kt b/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/commonized/js/package_root.kt index 658d08e94bd..2172b933838 100644 --- a/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/commonized/js/package_root.kt +++ b/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/commonized/js/package_root.kt @@ -24,9 +24,9 @@ actual val T.propertyWithTypeParameter1 get() = 42 actual val T.propertyWithTypeParameter2 get() = 42 val T.propertyWithTypeParameter3 get() = 42 actual val T.propertyWithTypeParameter4 get() = length -val T.propertyWithTypeParameter5 get() = length -val T.propertyWithTypeParameter6 get() = length -val T.propertyWithTypeParameter7 get() = length +val T.propertyWithTypeParameter5: Int get() = length +val T.propertyWithTypeParameter6: Int get() = length +val T.propertyWithTypeParameter7: Int get() = length val T.propertyWithTypeParameter8 get() = 42 val T.propertyWithTypeParameter9 get() = 42 diff --git a/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/commonized/jvm/package_root.kt b/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/commonized/jvm/package_root.kt index bd1e9f617ab..f6a39280c23 100644 --- a/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/commonized/jvm/package_root.kt +++ b/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/commonized/jvm/package_root.kt @@ -24,9 +24,9 @@ actual val T.propertyWithTypeParameter1 get() = 42 actual val T.propertyWithTypeParameter2 get() = 42 val T.propertyWithTypeParameter3 get() = 42 actual val T.propertyWithTypeParameter4 get() = length -val T.propertyWithTypeParameter5 get() = length -val T.propertyWithTypeParameter6 get() = length -val String.propertyWithTypeParameter7 get() = length +val T.propertyWithTypeParameter5: Int get() = length +val T.propertyWithTypeParameter6: Int get() = length +val String.propertyWithTypeParameter7: Int get() = length val Q.propertyWithTypeParameter8 get() = 42 val T.propertyWithTypeParameter9 get() = 42 diff --git a/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/original/js/package_root.kt b/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/original/js/package_root.kt index 2cf7c3b4436..cd276808fac 100644 --- a/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/original/js/package_root.kt +++ b/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/original/js/package_root.kt @@ -23,10 +23,10 @@ fun mismatchedFunction2() = 42 val T.propertyWithTypeParameter1 get() = 42 val T.propertyWithTypeParameter2 get() = 42 val T.propertyWithTypeParameter3 get() = 42 -val T.propertyWithTypeParameter4 get() = length -val T.propertyWithTypeParameter5 get() = length -val T.propertyWithTypeParameter6 get() = length -val T.propertyWithTypeParameter7 get() = length +val T.propertyWithTypeParameter4: Int get() = length +val T.propertyWithTypeParameter5: Int get() = length +val T.propertyWithTypeParameter6: Int get() = length +val T.propertyWithTypeParameter7: Int get() = length val T.propertyWithTypeParameter8 get() = 42 val T.propertyWithTypeParameter9 get() = 42 diff --git a/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/original/jvm/package_root.kt b/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/original/jvm/package_root.kt index df3ce507794..d9ac4bf2025 100644 --- a/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/original/jvm/package_root.kt +++ b/konan/commonizer/testData/callableMemberCommonization/extensionReceivers/original/jvm/package_root.kt @@ -23,10 +23,10 @@ fun Double.mismatchedFunction2() = 42 val T.propertyWithTypeParameter1 get() = 42 val T.propertyWithTypeParameter2 get() = 42 val T.propertyWithTypeParameter3 get() = 42 -val T.propertyWithTypeParameter4 get() = length -val T.propertyWithTypeParameter5 get() = length -val T.propertyWithTypeParameter6 get() = length -val String.propertyWithTypeParameter7 get() = length +val T.propertyWithTypeParameter4: Int get() = length +val T.propertyWithTypeParameter5: Int get() = length +val T.propertyWithTypeParameter6: Int get() = length +val String.propertyWithTypeParameter7: Int get() = length val Q.propertyWithTypeParameter8 get() = 42 val T.propertyWithTypeParameter9 get() = 42 diff --git a/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/common/package_root.kt b/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/common/package_root.kt index 1b77a8601d9..509f554ea74 100644 --- a/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/common/package_root.kt +++ b/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/common/package_root.kt @@ -3,5 +3,41 @@ expect internal val publicOrInternalProperty: Int expect internal val internalProperty: Int expect public fun publicFunction(): Int -expect internal val internalFunction(): Int expect internal fun publicOrInternalFunction(): Int +expect internal fun internalFunction(): Int + +expect open class Outer1() { + public val publicProperty: Int + internal val publicOrInternalProperty: Int + internal val internalProperty: Int + + public fun publicFunction(): Int + internal fun publicOrInternalFunction(): Int + internal fun internalFunction(): Int + + open class Inner1() { + public val publicProperty: Int + internal val publicOrInternalProperty: Int + internal val internalProperty: Int + + public fun publicFunction(): Int + internal fun publicOrInternalFunction(): Int + internal fun internalFunction(): Int + } +} + +expect open class Outer2() { + public open val publicProperty: Int + internal open val internalProperty: Int + + public open fun publicFunction(): Int + internal open fun internalFunction(): Int + + open class Inner2() { + public open val publicProperty: Int + internal open val internalProperty: Int + + public open fun publicFunction(): Int + internal open fun internalFunction(): Int + } +} diff --git a/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/js/package_root.kt b/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/js/package_root.kt index 371a876a036..c8d7bcfe264 100644 --- a/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/js/package_root.kt +++ b/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/js/package_root.kt @@ -6,6 +6,62 @@ private val privateProperty = 1 actual public fun publicFunction() = 1 actual public fun publicOrInternalFunction() = 1 -actual internal val internalFunction() = 1 -internal val internalOrPrivateFunction() = 1 -private val privateFunction() = 1 +actual internal fun internalFunction() = 1 +internal fun internalOrPrivateFunction() = 1 +private fun privateFunction() = 1 + +actual open class Outer1 actual constructor() { + actual public val publicProperty = 1 + actual public val publicOrInternalProperty = 1 + actual internal val internalProperty = 1 + internal val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + actual public fun publicFunction() = 1 + actual public fun publicOrInternalFunction() = 1 + actual internal fun internalFunction() = 1 + internal fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + + actual open class Inner1 actual constructor() { + actual public val publicProperty = 1 + actual public val publicOrInternalProperty = 1 + actual internal val internalProperty = 1 + internal val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + actual public fun publicFunction() = 1 + actual public fun publicOrInternalFunction() = 1 + actual internal fun internalFunction() = 1 + internal fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + } +} + +actual open class Outer2 actual constructor() { + actual public open val publicProperty = 1 + public open val publicOrInternalProperty = 1 + actual internal open val internalProperty = 1 + internal open val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + actual public open fun publicFunction() = 1 + public open fun publicOrInternalFunction() = 1 + actual internal open fun internalFunction() = 1 + internal open fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + + actual open class Inner2 actual constructor() { + actual public open val publicProperty = 1 + public open val publicOrInternalProperty = 1 + actual internal open val internalProperty = 1 + internal open val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + actual public open fun publicFunction() = 1 + public open fun publicOrInternalFunction() = 1 + actual internal open fun internalFunction() = 1 + internal open fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + } +} diff --git a/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/jvm/package_root.kt b/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/jvm/package_root.kt index 00a96a0fda0..3ba5c9344bc 100644 --- a/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/jvm/package_root.kt +++ b/konan/commonizer/testData/callableMemberCommonization/visibility/commonized/jvm/package_root.kt @@ -6,6 +6,62 @@ private val privateProperty = 1 actual public fun publicFunction() = 1 actual internal fun publicOrInternalFunction() = 1 -actual internal val internalFunction() = 1 -private val internalOrPrivateFunction() = 1 -private val privateFunction() = 1 +actual internal fun internalFunction() = 1 +private fun internalOrPrivateFunction() = 1 +private fun privateFunction() = 1 + +actual open class Outer1 actual constructor() { + actual public val publicProperty = 1 + actual internal val publicOrInternalProperty = 1 + actual internal val internalProperty = 1 + private val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + actual public fun publicFunction() = 1 + actual internal fun publicOrInternalFunction() = 1 + actual internal fun internalFunction() = 1 + private fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + + actual open class Inner1 actual constructor() { + actual public val publicProperty = 1 + actual internal val publicOrInternalProperty = 1 + actual internal val internalProperty = 1 + private val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + actual public fun publicFunction() = 1 + actual internal fun publicOrInternalFunction() = 1 + actual internal fun internalFunction() = 1 + private fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + } +} + +actual open class Outer2 actual constructor() { + actual public open val publicProperty = 1 + internal open val publicOrInternalProperty = 1 + actual internal open val internalProperty = 1 + private val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + actual public open fun publicFunction() = 1 + internal open fun publicOrInternalFunction() = 1 + actual internal open fun internalFunction() = 1 + private fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + + actual open class Inner2 actual constructor() { + actual public open val publicProperty = 1 + internal open val publicOrInternalProperty = 1 + actual internal open val internalProperty = 1 + private val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + actual public open fun publicFunction() = 1 + internal open fun publicOrInternalFunction() = 1 + actual internal open fun internalFunction() = 1 + private fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + } +} diff --git a/konan/commonizer/testData/callableMemberCommonization/visibility/original/js/package_root.kt b/konan/commonizer/testData/callableMemberCommonization/visibility/original/js/package_root.kt index b816e7716ec..d8f54a5e514 100644 --- a/konan/commonizer/testData/callableMemberCommonization/visibility/original/js/package_root.kt +++ b/konan/commonizer/testData/callableMemberCommonization/visibility/original/js/package_root.kt @@ -6,6 +6,62 @@ private val privateProperty = 1 public fun publicFunction() = 1 public fun publicOrInternalFunction() = 1 -internal val internalFunction() = 1 -internal val internalOrPrivateFunction() = 1 -private val privateFunction() = 1 +internal fun internalFunction() = 1 +internal fun internalOrPrivateFunction() = 1 +private fun privateFunction() = 1 + +open class Outer1 { + public val publicProperty = 1 + public val publicOrInternalProperty = 1 + internal val internalProperty = 1 + internal val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + public fun publicFunction() = 1 + public fun publicOrInternalFunction() = 1 + internal fun internalFunction() = 1 + internal fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + + open class Inner1 { + public val publicProperty = 1 + public val publicOrInternalProperty = 1 + internal val internalProperty = 1 + internal val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + public fun publicFunction() = 1 + public fun publicOrInternalFunction() = 1 + internal fun internalFunction() = 1 + internal fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + } +} + +open class Outer2 { + public open val publicProperty = 1 + public open val publicOrInternalProperty = 1 + internal open val internalProperty = 1 + internal open val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + public open fun publicFunction() = 1 + public open fun publicOrInternalFunction() = 1 + internal open fun internalFunction() = 1 + internal open fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + + open class Inner2 { + public open val publicProperty = 1 + public open val publicOrInternalProperty = 1 + internal open val internalProperty = 1 + internal open val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + public open fun publicFunction() = 1 + public open fun publicOrInternalFunction() = 1 + internal open fun internalFunction() = 1 + internal open fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + } +} diff --git a/konan/commonizer/testData/callableMemberCommonization/visibility/original/jvm/package_root.kt b/konan/commonizer/testData/callableMemberCommonization/visibility/original/jvm/package_root.kt index 4f5b02569c9..5f89e830447 100644 --- a/konan/commonizer/testData/callableMemberCommonization/visibility/original/jvm/package_root.kt +++ b/konan/commonizer/testData/callableMemberCommonization/visibility/original/jvm/package_root.kt @@ -6,6 +6,62 @@ private val privateProperty = 1 public fun publicFunction() = 1 internal fun publicOrInternalFunction() = 1 -internal val internalFunction() = 1 -private val internalOrPrivateFunction() = 1 -private val privateFunction() = 1 +internal fun internalFunction() = 1 +private fun internalOrPrivateFunction() = 1 +private fun privateFunction() = 1 + +open class Outer1 { + public val publicProperty = 1 + internal val publicOrInternalProperty = 1 + internal val internalProperty = 1 + private val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + public fun publicFunction() = 1 + internal fun publicOrInternalFunction() = 1 + internal fun internalFunction() = 1 + private fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + + open class Inner1 { + public val publicProperty = 1 + internal val publicOrInternalProperty = 1 + internal val internalProperty = 1 + private val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + public fun publicFunction() = 1 + internal fun publicOrInternalFunction() = 1 + internal fun internalFunction() = 1 + private fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + } +} + +open class Outer2 { + public open val publicProperty = 1 + internal open val publicOrInternalProperty = 1 + internal open val internalProperty = 1 + private val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + public open fun publicFunction() = 1 + internal open fun publicOrInternalFunction() = 1 + internal open fun internalFunction() = 1 + private fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + + open class Inner2 { + public open val publicProperty = 1 + internal open val publicOrInternalProperty = 1 + internal open val internalProperty = 1 + private val internalOrPrivateProperty = 1 + private val privateProperty = 1 + + public open fun publicFunction() = 1 + internal open fun publicOrInternalFunction() = 1 + internal open fun internalFunction() = 1 + private fun internalOrPrivateFunction() = 1 + private fun privateFunction() = 1 + } +} diff --git a/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/commonized/common/package_root.kt b/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/commonized/common/package_root.kt new file mode 100644 index 00000000000..0a4355a9c9e --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/commonized/common/package_root.kt @@ -0,0 +1,84 @@ +expect class A1() +expect interface B1 +expect annotation class C1() +expect object D1 +expect enum class E1 { FOO, BAR, BAZ } + +expect class F() { + inner class G1() + class H1() + interface I1 + object J1 + enum class K1 { FOO, BAR, BAZ } +} + +expect interface L { + class M1() + interface N1 + object O1 + enum class P1 { FOO, BAR, BAZ } +} + +expect object R { + class S1() + interface T1 + object U1 + enum class V1 { FOO, BAR, BAZ } +} + +expect class W() { + object X { + interface Y { + class Z() { + enum class AA { FOO, BAR, BAZ } + } + } + } +} + +expect class BB1() { companion object } +expect class BB2() + +expect class CC1() { companion object DD1 } +expect class CC2() +expect class CC3() + +expect inline class EE1(val value: String) + +expect class FF1(property1: String) { + val property1: String + val property2: String + val property3: String + val property4: String + + fun function1(): String + fun function2(): String +} +expect class FF2() + +expect sealed class GG1 +expect sealed class GG2 { + class HH1(): GG2 + object HH2 : GG2 +} + +expect class HH5(): GG2 +expect object HH6 : GG2 + +expect enum class II1 +expect enum class II2 { FOO } + +expect interface JJ { + val property: String + fun function(): String +} + +expect class KK1(property: String) : JJ { + override val property: String + override fun function(): String +} + +expect class KK2(wrapped: JJ) : JJ + +expect class LL1(value: String) { val value: String } +expect class LL2(value: String) { val value: String } diff --git a/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/commonized/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/commonized/js/package_root.kt new file mode 100644 index 00000000000..74ca2b02048 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/commonized/js/package_root.kt @@ -0,0 +1,133 @@ +actual class A1 actual constructor() +class A2 +class A3 +class A4 +class A5 + +actual interface B1 +interface B2 +interface B3 +interface B4 + +actual annotation class C1 actual constructor() +annotation class C2 +annotation class C3 + +actual object D1 +object D2 + +actual enum class E1 { FOO, BAR, BAZ } + +actual class F actual constructor() { + actual inner class G1 actual constructor() + inner class G2 + inner class G3 + inner class G4 + inner class G5 + inner class G6 + + actual class H1 actual constructor() + class H2 + class H3 + class H4 + + actual interface I1 + interface I2 + interface I3 + + actual object J1 + object J2 + + actual enum class K1 { FOO, BAR, BAZ } +} + +actual interface L { + actual class M1 actual constructor() + class M2 + class M3 + class M4 + class M5 + + actual interface N1 + interface N2 + interface N3 + + actual object O1 + object O2 + + actual enum class P1 { FOO, BAR, BAZ } +} + +actual object R { + actual class S1 actual constructor() + class S2 + class S3 + class S4 + + actual interface T1 + interface T2 + interface T3 + + actual object U1 + object U2 + + actual enum class V1 { FOO, BAR, BAZ } +} + +actual class W actual constructor() { + actual object X { + actual interface Y { + actual class Z actual constructor() { + actual enum class AA { FOO, BAR, BAZ } + } + } + } +} + +actual class BB1 actual constructor() { actual companion object } +actual class BB2 actual constructor() { companion object } + +actual class CC1 actual constructor() { actual companion object DD1 } +actual class CC2 actual constructor() { companion object DD2 } +actual class CC3 actual constructor() { companion object DD3 } + +actual inline class EE1 actual constructor(actual val value: String) +inline class EE2(val value: String) + +actual external class FF1 actual constructor(actual val property1: String) { + actual val property2 = property1 + actual val property3 get() = property1 + actual val property4: String + + actual fun function1() = property1 + actual fun function2(): String +} +actual external class FF2 actual constructor() + +actual sealed class GG1 +actual sealed class GG2 { + actual class HH1 actual constructor(): GG2() + actual object HH2 : GG2() + class HH3 : GG2() +} + +actual class HH5 actual constructor(): GG2() +actual object HH6 : GG2() +class HH7 : GG2() + +actual enum class II1 +actual enum class II2 { FOO, BAR } + +actual interface JJ { + actual val property: String + actual fun function(): String +} + +actual class KK1 actual constructor(actual override val property: String) : JJ { + actual override fun function() = property +} + +actual class KK2 actual constructor(private val wrapped: JJ) : JJ by wrapped + +actual data class LL1 actual constructor(actual val value: String) +actual data class LL2 actual constructor(actual val value: String) diff --git a/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/commonized/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/commonized/jvm/package_root.kt new file mode 100644 index 00000000000..422f4b8a13c --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/commonized/jvm/package_root.kt @@ -0,0 +1,135 @@ +actual class A1 actual constructor() +interface A2 +annotation class A3 +object A4 +enum class A5 { FOO, BAR, BAZ } + +actual interface B1 +annotation class B2 +object B3 +enum class B4 { FOO, BAR, BAZ } + +actual annotation class C1 actual constructor() +object C2 +enum class C3 { FOO, BAR, BAZ } + +actual object D1 +enum class D2 { FOO, BAR, BAZ } + +actual enum class E1 { FOO, BAR, BAZ } + +actual class F actual constructor() { + actual inner class G1 actual constructor() + class G2 + interface G3 + object G4 + enum class G5 { FOO, BAR, BAZ } + companion object G6 + + actual class H1 actual constructor() + interface H2 + object H3 + enum class H4 { FOO, BAR, BAZ } + + actual interface I1 + object I2 + enum class I3 { FOO, BAR, BAZ } + + actual object J1 + enum class J2 { FOO, BAR, BAZ } + + actual enum class K1 { FOO, BAR, BAZ } +} + +actual interface L { + actual class M1 actual constructor() + interface M2 + object M3 + enum class M4 { FOO, BAR, BAZ } + companion object M5 + + actual interface N1 + object N2 + enum class N3 { FOO, BAR, BAZ } + + actual object O1 + enum class O2 { FOO, BAR, BAZ } + + actual enum class P1 { FOO, BAR, BAZ } +} + +actual object R { + actual class S1 actual constructor() + interface S2 + object S3 + enum class S4 { FOO, BAR, BAZ } + + actual interface T1 + object T2 + enum class T3 { FOO, BAR, BAZ } + + actual object U1 + enum class U2 { FOO, BAR, BAZ } + + actual enum class V1 { FOO, BAR, BAZ } +} + +actual class W actual constructor() { + actual object X { + actual interface Y { + actual class Z actual constructor() { + actual enum class AA { FOO, BAR, BAZ } + } + } + } +} + +actual class BB1 actual constructor() { actual companion object } +actual class BB2 actual constructor() + +actual class CC1 actual constructor() { actual companion object DD1 } +actual class CC2 actual constructor() { companion object CompanionWithAnotherName } +actual class CC3 actual constructor() { companion object } + +actual inline class EE1 actual constructor(actual val value: String) +class EE2(val value: String) + +actual class FF1 actual constructor(actual val property1: String) { + actual val property2 = property1 + actual val property3 get() = property1 + actual val property4 = property1 + + actual fun function1() = property1 + actual fun function2() = function1() +} +actual external class FF2 actual constructor() + +actual sealed class GG1 +actual sealed class GG2 { + actual class HH1 actual constructor(): GG2() + actual object HH2 : GG2() + class HH4 : GG2() +} + +actual class HH5 actual constructor(): GG2() +actual object HH6 : GG2() +class HH8 : GG2() + +actual enum class II1 +actual enum class II2 { FOO, BAZ } + +actual interface JJ { + actual val property: String + val property2: String + actual fun function(): String +} + +actual class KK1 actual constructor(actual override val property: String) : JJ { + val property2 = property + actual override fun function() = property +} + +actual class KK2 actual constructor(wrapped: JJ) : JJ by wrapped + +actual data class LL1 actual constructor(actual val value: String) +actual class LL2 actual constructor(actual val value: String) diff --git a/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/original/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/original/js/package_root.kt new file mode 100644 index 00000000000..4a385b10ac6 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/original/js/package_root.kt @@ -0,0 +1,133 @@ +class A1 +class A2 +class A3 +class A4 +class A5 + +interface B1 +interface B2 +interface B3 +interface B4 + +annotation class C1 +annotation class C2 +annotation class C3 + +object D1 +object D2 + +enum class E1 { FOO, BAR, BAZ } + +class F { + inner class G1 + inner class G2 + inner class G3 + inner class G4 + inner class G5 + inner class G6 + + class H1 + class H2 + class H3 + class H4 + + interface I1 + interface I2 + interface I3 + + object J1 + object J2 + + enum class K1 { FOO, BAR, BAZ } +} + +interface L { + class M1 + class M2 + class M3 + class M4 + class M5 + + interface N1 + interface N2 + interface N3 + + object O1 + object O2 + + enum class P1 { FOO, BAR, BAZ } +} + +object R { + class S1 + class S2 + class S3 + class S4 + + interface T1 + interface T2 + interface T3 + + object U1 + object U2 + + enum class V1 { FOO, BAR, BAZ } +} + +class W { + object X { + interface Y { + class Z { + enum class AA { FOO, BAR, BAZ } + } + } + } +} + +class BB1 { companion object } +class BB2 { companion object } + +class CC1 { companion object DD1 } +class CC2 { companion object DD2 } +class CC3 { companion object DD3 } + +inline class EE1(val value: String) +inline class EE2(val value: String) + +external class FF1(val property1: String) { + val property2 = property1 + val property3 get() = property1 + val property4: String + + fun function1() = property1 + fun function2(): String +} +external class FF2() + +sealed class GG1 +sealed class GG2 { + class HH1 : GG2() + object HH2 : GG2() + class HH3 : GG2() +} + +class HH5 : GG2() +object HH6 : GG2() +class HH7 : GG2() + +enum class II1 +enum class II2 { FOO, BAR } + +interface JJ { + val property: String + fun function(): String +} + +class KK1(override val property: String) : JJ { + override fun function() = property +} + +class KK2(private val wrapped: JJ) : JJ by wrapped + +data class LL1(val value: String) +data class LL2(val value: String) diff --git a/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/original/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/original/jvm/package_root.kt new file mode 100644 index 00000000000..84c7956ab30 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/classKindAndModifiers/original/jvm/package_root.kt @@ -0,0 +1,135 @@ +class A1 +interface A2 +annotation class A3 +object A4 +enum class A5 { FOO, BAR, BAZ } + +interface B1 +annotation class B2 +object B3 +enum class B4 { FOO, BAR, BAZ } + +annotation class C1 +object C2 +enum class C3 { FOO, BAR, BAZ } + +object D1 +enum class D2 { FOO, BAR, BAZ } + +enum class E1 { FOO, BAR, BAZ } + +class F { + inner class G1 + class G2 + interface G3 + object G4 + enum class G5 { FOO, BAR, BAZ } + companion object G6 + + class H1 + interface H2 + object H3 + enum class H4 { FOO, BAR, BAZ } + + interface I1 + object I2 + enum class I3 { FOO, BAR, BAZ } + + object J1 + enum class J2 { FOO, BAR, BAZ } + + enum class K1 { FOO, BAR, BAZ } +} + +interface L { + class M1 + interface M2 + object M3 + enum class M4 { FOO, BAR, BAZ } + companion object M5 + + interface N1 + object N2 + enum class N3 { FOO, BAR, BAZ } + + object O1 + enum class O2 { FOO, BAR, BAZ } + + enum class P1 { FOO, BAR, BAZ } +} + +object R { + class S1 + interface S2 + object S3 + enum class S4 { FOO, BAR, BAZ } + + interface T1 + object T2 + enum class T3 { FOO, BAR, BAZ } + + object U1 + enum class U2 { FOO, BAR, BAZ } + + enum class V1 { FOO, BAR, BAZ } +} + +class W { + object X { + interface Y { + class Z { + enum class AA { FOO, BAR, BAZ } + } + } + } +} + +class BB1 { companion object } +class BB2 + +class CC1 { companion object DD1 } +class CC2 { companion object CompanionWithAnotherName } +class CC3 { companion object } + +inline class EE1(val value: String) +class EE2(val value: String) + +class FF1(val property1: String) { + val property2 = property1 + val property3 get() = property1 + val property4 = property1 + + fun function1() = property1 + fun function2() = function1() +} +external class FF2() + +sealed class GG1 +sealed class GG2 { + class HH1 : GG2() + object HH2 : GG2() + class HH4 : GG2() +} + +class HH5 : GG2() +object HH6 : GG2() +class HH8 : GG2() + +enum class II1 +enum class II2 { FOO, BAZ } + +interface JJ { + val property: String + val property2: String + fun function(): String +} + +class KK1(override val property: String) : JJ { + val property2 = property + override fun function() = property +} + +class KK2(wrapped: JJ) : JJ by wrapped + +data class LL1(val value: String) +class LL2(val value: String) diff --git a/konan/commonizer/testData/classifierCommonization/constructors/commonized/common/package_root.kt b/konan/commonizer/testData/classifierCommonization/constructors/commonized/common/package_root.kt new file mode 100644 index 00000000000..53f2a59500f --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/constructors/commonized/common/package_root.kt @@ -0,0 +1,30 @@ +expect class A1(text: String) { constructor(number: Int) } +expect class A2(text: String) { constructor(number: Int) } +expect class A3 +expect class A4 +expect class A5 + +expect class B1 protected constructor(text: String) { protected constructor(number: Int) } +expect class B2 +expect class B3 + +expect class C1 internal constructor(text: String) { internal constructor(number: Int) } +expect class C2 + +expect class D1 + +expect class E { + constructor(a: Any) + + constructor(a: Any, b: String) + constructor(a: Any, b: Int) +} + +expect enum class F { + FOO, + BAR, + BAZ; + + // no constructor allowed for enum class + val alias: String +} diff --git a/konan/commonizer/testData/classifierCommonization/constructors/commonized/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/constructors/commonized/js/package_root.kt new file mode 100644 index 00000000000..83acfee6d51 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/constructors/commonized/js/package_root.kt @@ -0,0 +1,30 @@ +actual class A1 actual constructor(text: String) { actual constructor(number: Int) : this(number.toString()) } +actual class A2 actual constructor(text: String) { actual constructor(number: Int) : this(number.toString()) } +actual class A3(text: String) { constructor(number: Int) : this(number.toString()) } +actual class A4(text: String) { constructor(number: Int) : this(number.toString()) } +actual class A5(text: String) { constructor(number: Int) : this(number.toString()) } + +actual class B1 protected actual constructor(text: String) { protected actual constructor(number: Int) : this(number.toString()) } +actual class B2 protected constructor(text: String) { protected constructor(number: Int) : this(number.toString()) } +actual class B3 protected constructor(text: String) { protected constructor(number: Int) : this(number.toString()) } + +actual class C1 internal actual constructor(text: String) { internal actual constructor(number: Int) : this(number.toString()) } +actual class C2 internal constructor(text: String) { internal constructor(number: Int) : this(number.toString()) } + +actual class D1 private constructor(text: String) { private constructor(number: Int) : this(number.toString()) } + +actual class E { + constructor(a: Int) + actual constructor(a: Any) + + constructor(a: Int, b: String) + constructor(a: Int, b: Any) + actual constructor(a: Any, b: String) + actual constructor(a: Any, b: Int) +} + +actual enum class F(actual val alias: String) { + FOO("foo"), + BAR("bar"), + BAZ("baz") +} diff --git a/konan/commonizer/testData/classifierCommonization/constructors/commonized/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/constructors/commonized/jvm/package_root.kt new file mode 100644 index 00000000000..04d817a47da --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/constructors/commonized/jvm/package_root.kt @@ -0,0 +1,30 @@ +actual class A1 actual constructor(text: String) { actual constructor(number: Int) : this(number.toString()) } +actual class A2 actual constructor(text: String) { actual constructor(number: Int) : this(number.toString()) } +actual class A3 protected constructor(text: String) { protected constructor(number: Int) : this(number.toString()) } +actual class A4 internal constructor(text: String) { internal constructor(number: Int) : this(number.toString()) } +actual class A5 private constructor(text: String) { private constructor(number: Int) : this(number.toString()) } + +actual class B1 protected actual constructor(text: String) { protected actual constructor(number: Int) : this(number.toString()) } +actual class B2 internal constructor(text: String) { internal constructor(number: Int) : this(number.toString()) } +actual class B3 private constructor(text: String) { private constructor(number: Int) : this(number.toString()) } + +actual class C1 internal actual constructor(text: String) { internal actual constructor(number: Int) : this(number.toString()) } +actual class C2 private constructor(text: String) { private constructor(number: Int) : this(number.toString()) } + +actual class D1 private constructor(text: String) { private constructor(number: Int) : this(number.toString()) } + +actual class E { + constructor(a: String) + actual constructor(a: Any) + + constructor(a: String, b: Int) + constructor(a: String, b: Any) + actual constructor(a: Any, b: String) + actual constructor(a: Any, b: Int) +} + +actual enum class F(actual val alias: String) { + FOO("foo"), + BAR("bar"), + BAZ("baz") +} diff --git a/konan/commonizer/testData/classifierCommonization/constructors/original/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/constructors/original/js/package_root.kt new file mode 100644 index 00000000000..f94a51858fc --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/constructors/original/js/package_root.kt @@ -0,0 +1,30 @@ +class A1(text: String) { constructor(number: Int) : this(number.toString()) } +class A2(text: String) { constructor(number: Int) : this(number.toString()) } +class A3(text: String) { constructor(number: Int) : this(number.toString()) } +class A4(text: String) { constructor(number: Int) : this(number.toString()) } +class A5(text: String) { constructor(number: Int) : this(number.toString()) } + +class B1 protected constructor(text: String) { protected constructor(number: Int) : this(number.toString()) } +class B2 protected constructor(text: String) { protected constructor(number: Int) : this(number.toString()) } +class B3 protected constructor(text: String) { protected constructor(number: Int) : this(number.toString()) } + +class C1 internal constructor(text: String) { internal constructor(number: Int) : this(number.toString()) } +class C2 internal constructor(text: String) { internal constructor(number: Int) : this(number.toString()) } + +class D1 private constructor(text: String) { private constructor(number: Int) : this(number.toString()) } + +class E { + constructor(a: Int) + constructor(a: Any) + + constructor(a: Int, b: String) + constructor(a: Int, b: Any) + constructor(a: Any, b: String) + constructor(a: Any, b: Int) +} + +enum class F(val alias: String) { + FOO("foo"), + BAR("bar"), + BAZ("baz") +} diff --git a/konan/commonizer/testData/classifierCommonization/constructors/original/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/constructors/original/jvm/package_root.kt new file mode 100644 index 00000000000..9c01f7e57e7 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/constructors/original/jvm/package_root.kt @@ -0,0 +1,30 @@ +class A1(text: String) { constructor(number: Int) : this(number.toString()) } +class A2 constructor(text: String) { constructor(number: Int) : this(number.toString()) } +class A3 protected constructor(text: String) { protected constructor(number: Int) : this(number.toString()) } +class A4 internal constructor(text: String) { internal constructor(number: Int) : this(number.toString()) } +class A5 private constructor(text: String) { private constructor(number: Int) : this(number.toString()) } + +class B1 protected constructor(text: String) { protected constructor(number: Int) : this(number.toString()) } +class B2 internal constructor(text: String) { internal constructor(number: Int) : this(number.toString()) } +class B3 private constructor(text: String) { private constructor(number: Int) : this(number.toString()) } + +class C1 internal constructor(text: String) { internal constructor(number: Int) : this(number.toString()) } +class C2 private constructor(text: String) { private constructor(number: Int) : this(number.toString()) } + +class D1 private constructor(text: String) { private constructor(number: Int) : this(number.toString()) } + +class E { + constructor(a: String) + constructor(a: Any) + + constructor(a: String, b: Int) + constructor(a: String, b: Any) + constructor(a: Any, b: String) + constructor(a: Any, b: Int) +} + +enum class F(val alias: String) { + FOO("foo"), + BAR("bar"), + BAZ("baz") +} diff --git a/konan/commonizer/testData/classifierCommonization/modality/commonized/common/package_root.kt b/konan/commonizer/testData/classifierCommonization/modality/commonized/common/package_root.kt new file mode 100644 index 00000000000..9f921d3554d --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/modality/commonized/common/package_root.kt @@ -0,0 +1,17 @@ +expect final class A1() +expect final class A2() +expect open class B1() +expect abstract class C1() +expect sealed class D1 + +expect abstract class E() { + final val p1: Int + final val p2: Int + open val p4: Int + abstract val p6: Int + + final fun f1(): Int + final fun f2(): Int + open fun f4(): Int + abstract fun f6(): Int +} diff --git a/konan/commonizer/testData/classifierCommonization/modality/commonized/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/modality/commonized/js/package_root.kt new file mode 100644 index 00000000000..5558ca63109 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/modality/commonized/js/package_root.kt @@ -0,0 +1,33 @@ +actual final class A1 actual constructor() +actual final class A2 actual constructor() +final class A3 +final class A4 + +actual open class B1 actual constructor() +open class B2 +open class B3 + +actual abstract class C1 actual constructor() +abstract class C2 + +actual sealed class D1 + +actual abstract class E actual constructor() { + actual final val p1: Int = 1 + actual final val p2: Int = 1 + final val p3: Int = 1 + + actual open val p4: Int = 1 + open val p5: Int = 1 + + actual abstract val p6: Int + + actual final fun f1(): Int = 1 + actual final fun f2(): Int = 1 + final fun f3(): Int = 1 + + actual open fun f4(): Int = 1 + open fun f5(): Int = 1 + + actual abstract fun f6(): Int +} diff --git a/konan/commonizer/testData/classifierCommonization/modality/commonized/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/modality/commonized/jvm/package_root.kt new file mode 100644 index 00000000000..9a36d067fcf --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/modality/commonized/jvm/package_root.kt @@ -0,0 +1,33 @@ +actual final class A1 actual constructor() +actual open class A2 actual constructor() +abstract class A3 +sealed class A4 + +actual open class B1 actual constructor() +abstract class B2 +sealed class B3 + +actual abstract class C1 actual constructor() +sealed class C2 + +actual sealed class D1 + +actual abstract class E actual constructor() { + actual final val p1: Int = 1 + actual open val p2: Int = 1 + abstract val p3: Int + + actual open val p4: Int = 1 + abstract val p5: Int + + actual abstract val p6: Int + + actual final fun f1(): Int = 1 + actual open fun f2(): Int = 1 + abstract fun f3(): Int + + actual open fun f4(): Int = 1 + abstract fun f5(): Int + + actual abstract fun f6(): Int +} diff --git a/konan/commonizer/testData/classifierCommonization/modality/original/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/modality/original/js/package_root.kt new file mode 100644 index 00000000000..0b702e676fd --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/modality/original/js/package_root.kt @@ -0,0 +1,33 @@ +final class A1 +final class A2 +final class A3 +final class A4 + +open class B1 +open class B2 +open class B3 + +abstract class C1 +abstract class C2 + +sealed class D1 + +abstract class E { + final val p1: Int = 1 + final val p2: Int = 1 + final val p3: Int = 1 + + open val p4: Int = 1 + open val p5: Int = 1 + + abstract val p6: Int + + final fun f1(): Int = 1 + final fun f2(): Int = 1 + final fun f3(): Int = 1 + + open fun f4(): Int = 1 + open fun f5(): Int = 1 + + abstract fun f6(): Int +} diff --git a/konan/commonizer/testData/classifierCommonization/modality/original/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/modality/original/jvm/package_root.kt new file mode 100644 index 00000000000..74f0b051e28 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/modality/original/jvm/package_root.kt @@ -0,0 +1,33 @@ +final class A1 +open class A2 +abstract class A3 +sealed class A4 + +open class B1 +abstract class B2 +sealed class B3 + +abstract class C1 +sealed class C2 + +sealed class D1 + +abstract class E { + final val p1: Int = 1 + open val p2: Int = 1 + abstract val p3: Int + + open val p4: Int = 1 + abstract val p5: Int + + abstract val p6: Int + + final fun f1(): Int = 1 + open fun f2(): Int = 1 + abstract fun f3(): Int + + open fun f4(): Int = 1 + abstract fun f5(): Int + + abstract fun f6(): Int +} diff --git a/konan/commonizer/testData/classifierCommonization/supertypes/commonized/common/package_root.kt b/konan/commonizer/testData/classifierCommonization/supertypes/commonized/common/package_root.kt new file mode 100644 index 00000000000..6a51bed6e21 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/supertypes/commonized/common/package_root.kt @@ -0,0 +1,64 @@ +expect interface A1 { + val property1: Int + fun function1(): Int +} + +expect abstract class A2(): A1 { + abstract val property2: Int + abstract fun function2(): Int +} + +expect class A3 (): A2 { + override val property1: Int + override val property2: Int + val property3: Int + + override fun function1(): Int + override fun function2(): Int + fun function3(): Int +} + +expect interface B1 { + val property1: Int + fun function1(): Int +} + +expect class B3(): B1 { + override val property1: Int + open val property2: Int + val property3: Int + + override fun function1(): Int + open fun function2(): Int + fun function3(): Int +} + +expect interface C1 { + val property1: Int + fun function1(): Int +} + +expect class C3 (): C1 { + override val property1: Int + val property2: Int + val property3: Int + + override fun function1(): Int + fun function2(): Int + fun function3(): Int +} + +expect interface D2 { + val property2: Int + fun function2(): Int +} + +expect class D3(): D2 { + open val property1: Int + override val property2: Int + val property3: Int + + open fun function1(): Int + override fun function2(): Int + fun function3(): Int +} diff --git a/konan/commonizer/testData/classifierCommonization/supertypes/commonized/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/supertypes/commonized/js/package_root.kt new file mode 100644 index 00000000000..8506b925c57 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/supertypes/commonized/js/package_root.kt @@ -0,0 +1,79 @@ +actual interface A1 { + actual val property1: Int + actual fun function1(): Int +} + +actual abstract class A2 actual constructor(): A1 { + actual abstract val property2: Int + actual abstract fun function2(): Int +} + +actual class A3 actual constructor(): A2() { + actual override val property1 = 1 + actual override val property2 = 1 + actual val property3 = 1 + + actual override fun function1() = 1 + actual override fun function2() = 1 + actual fun function3() = 1 +} + +actual interface B1 { + actual val property1: Int + actual fun function1(): Int +} + +interface B2 { + val property2: Int + fun function2(): Int +} + +actual class B3 actual constructor(): B1, B2 { + actual override val property1 = 1 + actual override val property2 = 1 + actual val property3 = 1 + + actual override fun function1() = 1 + actual override fun function2() = 1 + actual fun function3() = 1 +} + +actual interface C1 { + actual val property1: Int + actual fun function1(): Int +} + +interface C2 { + val property2: Int + fun function2(): Int +} + +actual class C3 actual constructor(): C1, C2 { + actual override val property1 = 1 + actual override val property2 = 1 + actual val property3 = 1 + + actual override fun function1() = 1 + actual override fun function2() = 1 + actual fun function3() = 1 +} + +interface D1 { + val property1: Int + fun function1(): Int +} + +actual interface D2 { + actual val property2: Int + actual fun function2(): Int +} + +actual class D3 actual constructor(): D1, D2 { + actual override val property1 = 1 + actual override val property2 = 1 + actual val property3 = 1 + + actual override fun function1() = 1 + actual override fun function2() = 1 + actual fun function3() = 1 +} diff --git a/konan/commonizer/testData/classifierCommonization/supertypes/commonized/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/supertypes/commonized/jvm/package_root.kt new file mode 100644 index 00000000000..a2a3e17d64c --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/supertypes/commonized/jvm/package_root.kt @@ -0,0 +1,72 @@ +actual interface A1 { + actual val property1: Int + actual fun function1(): Int +} + +actual abstract class A2 actual constructor(): A1 { + actual abstract val property2: Int + actual abstract fun function2(): Int +} + +actual class A3 actual constructor(): A2(), A1 { + actual override val property1 = 1 + actual override val property2 = 1 + actual val property3 = 1 + + actual override fun function1() = 1 + actual override fun function2() = 1 + actual fun function3() = 1 +} + +actual interface B1 { + actual val property1: Int + val property2: Int + + actual fun function1(): Int + fun function2(): Int +} + +actual class B3 actual constructor(): B1 { + actual override val property1 = 1 + actual override val property2 = 1 + actual val property3 = 1 + + actual override fun function1() = 1 + actual override fun function2() = 1 + actual fun function3() = 1 +} + +actual interface C1 { + actual val property1: Int + actual fun function1(): Int +} + +actual class C3 actual constructor(): C1 { + actual override val property1 = 1 + actual val property2 = 1 + actual val property3 = 1 + + actual override fun function1() = 1 + actual fun function2() = 1 + actual fun function3() = 1 +} + +abstract class D1 { + abstract val property1: Int + abstract fun function1(): Int +} + +actual interface D2 { + actual val property2: Int + actual fun function2(): Int +} + +actual class D3 actual constructor(): D1(), D2 { + actual override val property1 = 1 + actual override val property2 = 1 + actual val property3 = 1 + + actual override fun function1() = 1 + actual override fun function2() = 1 + actual fun function3() = 1 +} diff --git a/konan/commonizer/testData/classifierCommonization/supertypes/original/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/supertypes/original/js/package_root.kt new file mode 100644 index 00000000000..87d71a582a9 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/supertypes/original/js/package_root.kt @@ -0,0 +1,79 @@ +interface A1 { + val property1: Int + fun function1(): Int +} + +abstract class A2 : A1 { + abstract val property2: Int + abstract fun function2(): Int +} + +class A3 : A2() { + override val property1 = 1 + override val property2 = 1 + val property3 = 1 + + override fun function1() = 1 + override fun function2() = 1 + fun function3() = 1 +} + +interface B1 { + val property1: Int + fun function1(): Int +} + +interface B2 { + val property2: Int + fun function2(): Int +} + +class B3 : B1, B2 { + override val property1 = 1 + override val property2 = 1 + val property3 = 1 + + override fun function1() = 1 + override fun function2() = 1 + fun function3() = 1 +} + +interface C1 { + val property1: Int + fun function1(): Int +} + +interface C2 { + val property2: Int + fun function2(): Int +} + +class C3 : C1, C2 { + override val property1 = 1 + override val property2 = 1 + val property3 = 1 + + override fun function1() = 1 + override fun function2() = 1 + fun function3() = 1 +} + +interface D1 { + val property1: Int + fun function1(): Int +} + +interface D2 { + val property2: Int + fun function2(): Int +} + +class D3 : D1, D2 { + override val property1 = 1 + override val property2 = 1 + val property3 = 1 + + override fun function1() = 1 + override fun function2() = 1 + fun function3() = 1 +} diff --git a/konan/commonizer/testData/classifierCommonization/supertypes/original/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/supertypes/original/jvm/package_root.kt new file mode 100644 index 00000000000..768ba7f68b5 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/supertypes/original/jvm/package_root.kt @@ -0,0 +1,72 @@ +interface A1 { + val property1: Int + fun function1(): Int +} + +abstract class A2 : A1 { + abstract val property2: Int + abstract fun function2(): Int +} + +class A3 : A2(), A1 { + override val property1 = 1 + override val property2 = 1 + val property3 = 1 + + override fun function1() = 1 + override fun function2() = 1 + fun function3() = 1 +} + +interface B1 { + val property1: Int + val property2: Int + + fun function1(): Int + fun function2(): Int +} + +class B3 : B1 { + override val property1 = 1 + override val property2 = 1 + val property3 = 1 + + override fun function1() = 1 + override fun function2() = 1 + fun function3() = 1 +} + +interface C1 { + val property1: Int + fun function1(): Int +} + +class C3 : C1 { + override val property1 = 1 + val property2 = 1 + val property3 = 1 + + override fun function1() = 1 + fun function2() = 1 + fun function3() = 1 +} + +abstract class D1 { + abstract val property1: Int + abstract fun function1(): Int +} + +interface D2 { + val property2: Int + fun function2(): Int +} + +class D3 : D1(), D2 { + override val property1 = 1 + override val property2 = 1 + val property3 = 1 + + override fun function1() = 1 + override fun function2() = 1 + fun function3() = 1 +} diff --git a/konan/commonizer/testData/classifierCommonization/typeAliases/commonized/common/package_root.kt b/konan/commonizer/testData/classifierCommonization/typeAliases/commonized/common/package_root.kt new file mode 100644 index 00000000000..1f8dadcb2b7 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/typeAliases/commonized/common/package_root.kt @@ -0,0 +1,2 @@ +expect class A () +expect class B diff --git a/konan/commonizer/testData/classifierCommonization/typeAliases/commonized/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/typeAliases/commonized/js/package_root.kt new file mode 100644 index 00000000000..5f7570031fe --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/typeAliases/commonized/js/package_root.kt @@ -0,0 +1,8 @@ +actual class A actual constructor() +actual typealias B = A +typealias C = B +typealias D = List +typealias E = List +typealias F = Function +typealias G = () -> Unit +typealias H = (String) -> Int diff --git a/konan/commonizer/testData/classifierCommonization/typeAliases/commonized/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/typeAliases/commonized/jvm/package_root.kt new file mode 100644 index 00000000000..5f7570031fe --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/typeAliases/commonized/jvm/package_root.kt @@ -0,0 +1,8 @@ +actual class A actual constructor() +actual typealias B = A +typealias C = B +typealias D = List +typealias E = List +typealias F = Function +typealias G = () -> Unit +typealias H = (String) -> Int diff --git a/konan/commonizer/testData/classifierCommonization/typeAliases/original/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/typeAliases/original/js/package_root.kt new file mode 100644 index 00000000000..41f1dd6ac67 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/typeAliases/original/js/package_root.kt @@ -0,0 +1,8 @@ +class A +typealias B = A +typealias C = B +typealias D = List +typealias E = List +typealias F = Function +typealias G = () -> Unit +typealias H = (String) -> Int diff --git a/konan/commonizer/testData/classifierCommonization/typeAliases/original/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/typeAliases/original/jvm/package_root.kt new file mode 100644 index 00000000000..41f1dd6ac67 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/typeAliases/original/jvm/package_root.kt @@ -0,0 +1,8 @@ +class A +typealias B = A +typealias C = B +typealias D = List +typealias E = List +typealias F = Function +typealias G = () -> Unit +typealias H = (String) -> Int diff --git a/konan/commonizer/testData/classifierCommonization/typeParameters/commonized/common/package_root.kt b/konan/commonizer/testData/classifierCommonization/typeParameters/commonized/common/package_root.kt new file mode 100644 index 00000000000..076ed8f8af8 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/typeParameters/commonized/common/package_root.kt @@ -0,0 +1,126 @@ +expect class A2() { + val property: T + fun function(value: T): T + + expect class Nested() { + val property: T + fun function(value: T): T + } + + expect inner class Inner() { + val property: T + fun function(value: T): T + } +} +expect class B4() { + val property: T + fun function(value: T): T + + expect class Nested() { + val property: T + fun function(value: T): T + } + + expect inner class Inner() { + val property: T + fun function(value: T): T + } +} +expect class C5() { + val property: T + fun function(value: T): T + + expect class Nested() { + val property: T + fun function(value: T): T + } + + expect inner class Inner() { + val property: T + fun function(value: T): T + } +} +expect class D6() { + val property: T + fun function(value: T): T + + expect class Nested() { + val property: T + fun function(value: T): T + } + + expect inner class Inner() { + val property: T + fun function(value: T): T + } +} +expect class E7() { + val property: String + fun function(value: String): String + + expect class Nested() { + val property: String + fun function(value: String): String + } + + expect inner class Inner() { + val property: String + fun function(value: String): String + } +} +expect class F1() { + val property: T + fun function(value: T): T + + expect class Nested() { + val property: T + fun function(value: T): T + } + + expect inner class Inner() { + val property: T + fun function(value: T): T + } +} +expect class G1() { + val property1: T + val property2: R + fun function(value: T): R + + expect class Nested() { + val property1: T + val property2: R + fun function(value: T): R + } + + expect inner class Inner() { + val property1: T + val property2: R + fun function(value: T): R + } +} + +expect class H1() { + val dependentProperty: T + fun dependentFunction(value: T): T + + val T.dependentExtensionProperty: T + fun T.dependentExtensionFunction(): T + + fun independentFunction(): T + + val T.independentExtensionProperty: T + fun T.independentExtensionFunction(): T +} +expect class H2() { + val dependentProperty: T + fun dependentFunction(value: T): T + + val T.dependentExtensionProperty: T + fun T.dependentExtensionFunction(): T +} + +expect class I>() { + val property: T + fun function(value: T): T +} diff --git a/konan/commonizer/testData/classifierCommonization/typeParameters/commonized/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/typeParameters/commonized/js/package_root.kt new file mode 100644 index 00000000000..df8fb256039 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/typeParameters/commonized/js/package_root.kt @@ -0,0 +1,636 @@ +class A1 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +actual class A2 actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + + actual class Nested actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } + + actual inner class Inner actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } +} +class A3 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A7 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} + +class B1 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B3 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +actual class B4 actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + + actual class Nested actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } + + actual inner class Inner actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } +} +class B5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B7 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} + +class C1 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C3 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +actual class C5 actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + + actual class Nested actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } + + actual inner class Inner actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } +} +class C6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C7 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} + +class D1 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D3 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +actual class D6 actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + + actual class Nested actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } + + actual inner class Inner actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } +} +class D7 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} + +class E1 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E2 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E3 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E4 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E5 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E6 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +actual class E7 actual constructor() { + actual val property: String get() = TODO() + actual fun function(value: String): String = value + + actual class Nested actual constructor() { + actual val property: String get() = TODO() + actual fun function(value: String): String = value + } + + actual inner class Inner actual constructor() { + actual val property: String get() = TODO() + actual fun function(value: String): String = value + } +} + +actual class F1 actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + + actual class Nested actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } + + actual inner class Inner actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } +} +class F2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class F3 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} + +actual class G1 actual constructor() { + actual val property1: T get() = TODO() + actual val property2: R get() = TODO() + actual fun function(value: T): R = TODO() + + actual class Nested actual constructor() { + actual val property1: T get() = TODO() + actual val property2: R get() = TODO() + actual fun function(value: T): R = TODO() + } + + actual inner class Inner actual constructor() { + actual val property1: T get() = TODO() + actual val property2: R get() = TODO() + actual fun function(value: T): R = TODO() + } +} +class G2 { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + + class Nested { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } + + inner class Inner { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } +} +class G3 { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + + class Nested { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } + + inner class Inner { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } +} +class G4 { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + + class Nested { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } + + inner class Inner { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } +} + +actual class H1 actual constructor() { + actual val dependentProperty: T get() = TODO() + actual fun dependentFunction(value: T): T = value + + actual val T.dependentExtensionProperty: T get() = this + actual fun T.dependentExtensionFunction(): T = this + + actual fun independentFunction(): T = TODO() + + actual val T.independentExtensionProperty: T get() = this + actual fun T.independentExtensionFunction(): T = this +} +actual class H2 actual constructor() { + actual val dependentProperty: T get() = TODO() + actual fun dependentFunction(value: T): T = value + + actual val T.dependentExtensionProperty: T get() = this + actual fun T.dependentExtensionFunction(): T = this + + fun independentFunction(): T = TODO() + + val T.independentExtensionProperty: T get() = this + fun T.independentExtensionFunction(): T = this +} + +actual class I> actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value +} diff --git a/konan/commonizer/testData/classifierCommonization/typeParameters/commonized/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/typeParameters/commonized/jvm/package_root.kt new file mode 100644 index 00000000000..e1f2cd081fe --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/typeParameters/commonized/jvm/package_root.kt @@ -0,0 +1,636 @@ +class A1 { + val property: Any get() = TODO() + fun function(value: Any): Any = value + + class Nested { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } + + inner class Inner { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } +} +actual class A2 actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + + actual class Nested actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } + + actual inner class Inner actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } +} +class A3 { + val property: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property: R get() = TODO() + fun function(value: R): R = value + } +} +class A4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A7 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} + +class B1 { + val property: Any get() = TODO() + fun function(value: Any): Any = value + + class Nested { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } + + inner class Inner { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } +} +class B2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B3 { + val property: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property: R get() = TODO() + fun function(value: R): R = value + } +} +actual class B4 actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + + actual class Nested actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } + + actual inner class Inner actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } +} +class B5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B7 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} + +class C1 { + val property: Any get() = TODO() + fun function(value: Any): Any = value + + class Nested { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } + + inner class Inner { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } +} +class C2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested{ + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C3 { + val property: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property: R get() = TODO() + fun function(value: R): R = value + } +} +class C4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +actual class C5 actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + + actual class Nested actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } + + actual inner class Inner actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } +} +class C6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C7 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} + +class D1 { + val property: Any get() = TODO() + fun function(value: Any): Any = value + + class Nested { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } + + inner class Inner { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } +} +class D2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D3 { + val property: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property: R get() = TODO() + fun function(value: R): R = value + } +} +class D4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +actual class D6 actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + + actual class Nested actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } + + actual inner class Inner actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } +} +class D7 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} + +class E1 { + val property: Any get() = TODO() + fun function(value: Any): Any = value + + class Nested { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } + + inner class Inner { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } +} +class E2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class E3 { + val property: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property: R get() = TODO() + fun function(value: R): R = value + } +} +class E4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class E5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class E6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +actual class E7 actual constructor() { + actual val property: String get() = TODO() + actual fun function(value: String): String = value + + actual class Nested actual constructor() { + actual val property: String get() = TODO() + actual fun function(value: String): String = value + } + + actual inner class Inner actual constructor() { + actual val property: String get() = TODO() + actual fun function(value: String): String = value + } +} + +actual class F1 actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + + actual class Nested actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } + + actual inner class Inner actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value + } +} +class F2 { + val property: String get() = TODO() + fun function(value: T): Any = TODO() + + class Nested { + val property: String get() = TODO() + fun function(value: T): Any = TODO() + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: T): Any = TODO() + } +} +class F3 { + val property: T get() = TODO() + fun function(value: Any): T = TODO() + + class Nested { + val property: T get() = TODO() + fun function(value: Any): T = TODO() + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: Any): T = TODO() + } +} + +actual class G1 actual constructor() { + actual val property1: T get() = TODO() + actual val property2: R get() = TODO() + actual fun function(value: T): R = TODO() + + actual class Nested actual constructor() { + actual val property1: T get() = TODO() + actual val property2: R get() = TODO() + actual fun function(value: T): R = TODO() + } + + actual inner class Inner actual constructor() { + actual val property1: T get() = TODO() + actual val property2: R get() = TODO() + actual fun function(value: T): R = TODO() + } +} +class G2 { + val property1: T get() = TODO() + val property2: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property1: T get() = TODO() + val property2: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property1: T get() = TODO() + val property2: T get() = TODO() + fun function(value: T): T = value + } +} +class G3 { + val property1: R get() = TODO() + val property2: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property1: R get() = TODO() + val property2: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property1: R get() = TODO() + val property2: R get() = TODO() + fun function(value: R): R = value + } +} +class G4 { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + + class Nested { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } + + inner class Inner { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } +} + +actual class H1 actual constructor() { + actual val dependentProperty: T get() = TODO() + actual fun dependentFunction(value: T): T = value + + actual val T.dependentExtensionProperty: T get() = this + actual fun T.dependentExtensionFunction(): T = this + + actual fun independentFunction(): T = TODO() + + actual val T.independentExtensionProperty: T get() = this + actual fun T.independentExtensionFunction(): T = this +} +actual class H2 actual constructor() { + actual val dependentProperty: T get() = TODO() + actual fun dependentFunction(value: T): T = value + + actual val T.dependentExtensionProperty: T get() = this + actual fun T.dependentExtensionFunction(): T = this + + fun independentFunction(): T = TODO() + + val T.independentExtensionProperty: T get() = this + fun T.independentExtensionFunction(): T = this +} + +actual class I> actual constructor() { + actual val property: T get() = TODO() + actual fun function(value: T): T = value +} diff --git a/konan/commonizer/testData/classifierCommonization/typeParameters/original/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/typeParameters/original/js/package_root.kt new file mode 100644 index 00000000000..219f02e46c8 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/typeParameters/original/js/package_root.kt @@ -0,0 +1,636 @@ +class A1 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A3 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A7 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} + +class B1 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B3 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B7 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} + +class C1 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C3 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C7 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} + +class D1 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D3 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D7 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} + +class E1 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E2 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E3 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E4 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E5 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E6 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} +class E7 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} + +class F1 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class F2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class F3 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} + +class G1 { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + + class Nested { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } + + inner class Inner { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } +} +class G2 { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + + class Nested { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } + + inner class Inner { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } +} +class G3 { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + + class Nested { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } + + inner class Inner { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } +} +class G4 { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + + class Nested { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } + + inner class Inner { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } +} + +class H1 { + val dependentProperty: T get() = TODO() + fun dependentFunction(value: T): T = value + + val T.dependentExtensionProperty: T get() = this + fun T.dependentExtensionFunction(): T = this + + fun independentFunction(): T = TODO() + + val T.independentExtensionProperty: T get() = this + fun T.independentExtensionFunction(): T = this +} +class H2 { + val dependentProperty: T get() = TODO() + fun dependentFunction(value: T): T = value + + val T.dependentExtensionProperty: T get() = this + fun T.dependentExtensionFunction(): T = this + + fun independentFunction(): T = TODO() + + val T.independentExtensionProperty: T get() = this + fun T.independentExtensionFunction(): T = this +} + +class I> { + val property: T get() = TODO() + fun function(value: T): T = value +} diff --git a/konan/commonizer/testData/classifierCommonization/typeParameters/original/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/typeParameters/original/jvm/package_root.kt new file mode 100644 index 00000000000..798e03d3c89 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/typeParameters/original/jvm/package_root.kt @@ -0,0 +1,636 @@ +class A1 { + val property: Any get() = TODO() + fun function(value: Any): Any = value + + class Nested { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } + + inner class Inner { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } +} +class A2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A3 { + val property: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property: R get() = TODO() + fun function(value: R): R = value + } +} +class A4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class A7 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} + +class B1 { + val property: Any get() = TODO() + fun function(value: Any): Any = value + + class Nested { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } + + inner class Inner { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } +} +class B2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B3 { + val property: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property: R get() = TODO() + fun function(value: R): R = value + } +} +class B4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class B7 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} + +class C1 { + val property: Any get() = TODO() + fun function(value: Any): Any = value + + class Nested { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } + + inner class Inner { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } +} +class C2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested{ + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C3 { + val property: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property: R get() = TODO() + fun function(value: R): R = value + } +} +class C4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class C7 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} + +class D1 { + val property: Any get() = TODO() + fun function(value: Any): Any = value + + class Nested { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } + + inner class Inner { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } +} +class D2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D3 { + val property: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property: R get() = TODO() + fun function(value: R): R = value + } +} +class D4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class D7 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} + +class E1 { + val property: Any get() = TODO() + fun function(value: Any): Any = value + + class Nested { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } + + inner class Inner { + val property: Any get() = TODO() + fun function(value: Any): Any = value + } +} +class E2 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class E3 { + val property: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property: R get() = TODO() + fun function(value: R): R = value + } +} +class E4 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class E5 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class E6 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class E7 { + val property: String get() = TODO() + fun function(value: String): String = value + + class Nested { + val property: String get() = TODO() + fun function(value: String): String = value + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: String): String = value + } +} + +class F1 { + val property: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: T): T = value + } +} +class F2 { + val property: String get() = TODO() + fun function(value: T): Any = TODO() + + class Nested { + val property: String get() = TODO() + fun function(value: T): Any = TODO() + } + + inner class Inner { + val property: String get() = TODO() + fun function(value: T): Any = TODO() + } +} +class F3 { + val property: T get() = TODO() + fun function(value: Any): T = TODO() + + class Nested { + val property: T get() = TODO() + fun function(value: Any): T = TODO() + } + + inner class Inner { + val property: T get() = TODO() + fun function(value: Any): T = TODO() + } +} + +class G1 { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + + class Nested { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } + + inner class Inner { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } +} +class G2 { + val property1: T get() = TODO() + val property2: T get() = TODO() + fun function(value: T): T = value + + class Nested { + val property1: T get() = TODO() + val property2: T get() = TODO() + fun function(value: T): T = value + } + + inner class Inner { + val property1: T get() = TODO() + val property2: T get() = TODO() + fun function(value: T): T = value + } +} +class G3 { + val property1: R get() = TODO() + val property2: R get() = TODO() + fun function(value: R): R = value + + class Nested { + val property1: R get() = TODO() + val property2: R get() = TODO() + fun function(value: R): R = value + } + + inner class Inner { + val property1: R get() = TODO() + val property2: R get() = TODO() + fun function(value: R): R = value + } +} +class G4 { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + + class Nested { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } + + inner class Inner { + val property1: T get() = TODO() + val property2: R get() = TODO() + fun function(value: T): R = TODO() + } +} + +class H1 { + val dependentProperty: T get() = TODO() + fun dependentFunction(value: T): T = value + + val T.dependentExtensionProperty: T get() = this + fun T.dependentExtensionFunction(): T = this + + fun independentFunction(): T = TODO() + + val T.independentExtensionProperty: T get() = this + fun T.independentExtensionFunction(): T = this +} +class H2 { + val dependentProperty: T get() = TODO() + fun dependentFunction(value: T): T = value + + val T.dependentExtensionProperty: T get() = this + fun T.dependentExtensionFunction(): T = this + + fun independentFunction(): T = TODO() + + val T.independentExtensionProperty: T get() = this + fun T.independentExtensionFunction(): T = this +} + +class I> { + val property: T get() = TODO() + fun function(value: T): T = value +} diff --git a/konan/commonizer/testData/classifierCommonization/visibility/commonized/common/package_root.kt b/konan/commonizer/testData/classifierCommonization/visibility/commonized/common/package_root.kt new file mode 100644 index 00000000000..18e9f8d9244 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/visibility/commonized/common/package_root.kt @@ -0,0 +1,20 @@ +expect public class A1() +expect protected class B1() +expect internal class C1() + +expect public class E1 +expect protected class E2 +expect internal class E3 +expect private class E4 + +expect protected class F1 +expect private class F3 + +expect internal class G1 +expect private class G2 + +expect private class H1 + +expect public class I1 +expect public class I2 +expect public class I3 diff --git a/konan/commonizer/testData/classifierCommonization/visibility/commonized/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/visibility/commonized/js/package_root.kt new file mode 100644 index 00000000000..9f54b9ec8c9 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/visibility/commonized/js/package_root.kt @@ -0,0 +1,32 @@ +actual public class A1 actual constructor() +public class A2 +public class A3 +public class A4 + +actual protected class B1 actual constructor() +protected class B2 +protected class B3 + +actual internal class C1 actual constructor() +internal class C2 + +private class D1 + +actual public typealias E1 = A1 +actual public typealias E2 = A1 +actual public typealias E3 = A1 +actual public typealias E4 = A1 + +actual protected typealias F1 = A1 +protected typealias F2 = A1 +actual protected typealias F3 = A1 + +actual internal typealias G1 = A1 +actual internal typealias G2 = A1 + +actual private typealias H1 = A1 + +actual public typealias I1 = A1 // points to public +actual public typealias I2 = B1 // points to protected +actual public typealias I3 = C1 // points to internal +public typealias I4 = D1 // points to private diff --git a/konan/commonizer/testData/classifierCommonization/visibility/commonized/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/visibility/commonized/jvm/package_root.kt new file mode 100644 index 00000000000..07094cafb36 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/visibility/commonized/jvm/package_root.kt @@ -0,0 +1,32 @@ +actual public class A1 actual constructor() +protected class A2 +internal class A3 +private class A4 + +actual protected class B1 actual constructor() +internal class B2 +private class B3 + +actual internal class C1 actual constructor() +private class C2 + +private class D1 + +actual public typealias E1 = A1 +actual protected typealias E2 = A1 +actual internal typealias E3 = A1 +actual private typealias E4 = A1 + +actual protected typealias F1 = A1 +internal typealias F2 = A1 +actual private typealias F3 = A1 + +actual internal typealias G1 = A1 +actual private typealias G2 = A1 + +actual private typealias H1 = A1 + +actual public typealias I1 = A1 // points to public +actual public typealias I2 = B1 // points to protected +actual public typealias I3 = C1 // points to internal +public typealias I4 = D1 // points to private diff --git a/konan/commonizer/testData/classifierCommonization/visibility/original/js/package_root.kt b/konan/commonizer/testData/classifierCommonization/visibility/original/js/package_root.kt new file mode 100644 index 00000000000..8861023dcb5 --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/visibility/original/js/package_root.kt @@ -0,0 +1,32 @@ +public class A1 +public class A2 +public class A3 +public class A4 + +protected class B1 +protected class B2 +protected class B3 + +internal class C1 +internal class C2 + +private class D1 + +public typealias E1 = A1 +public typealias E2 = A1 +public typealias E3 = A1 +public typealias E4 = A1 + +protected typealias F1 = A1 +protected typealias F2 = A1 +protected typealias F3 = A1 + +internal typealias G1 = A1 +internal typealias G2 = A1 + +private typealias H1 = A1 + +public typealias I1 = A1 // points to public +public typealias I2 = B1 // points to protected +public typealias I3 = C1 // points to internal +public typealias I4 = D1 // points to private diff --git a/konan/commonizer/testData/classifierCommonization/visibility/original/jvm/package_root.kt b/konan/commonizer/testData/classifierCommonization/visibility/original/jvm/package_root.kt new file mode 100644 index 00000000000..1cbdec29f7c --- /dev/null +++ b/konan/commonizer/testData/classifierCommonization/visibility/original/jvm/package_root.kt @@ -0,0 +1,32 @@ +public class A1 +protected class A2 +internal class A3 +private class A4 + +protected class B1 +internal class B2 +private class B3 + +internal class C1 +private class C2 + +private class D1 + +public typealias E1 = A1 +protected typealias E2 = A1 +internal typealias E3 = A1 +private typealias E4 = A1 + +protected typealias F1 = A1 +internal typealias F2 = A1 +private typealias F3 = A1 + +internal typealias G1 = A1 +private typealias G2 = A1 + +private typealias H1 = A1 + +public typealias I1 = A1 // points to public +public typealias I2 = B1 // points to protected +public typealias I3 = C1 // points to internal +public typealias I4 = D1 // points to private diff --git a/konan/commonizer/testData/generalCommonization/annotations/commonized/common/package_root.kt b/konan/commonizer/testData/generalCommonization/annotations/commonized/common/package_root.kt index 9a686afc15a..d0832528670 100644 --- a/konan/commonizer/testData/generalCommonization/annotations/commonized/common/package_root.kt +++ b/konan/commonizer/testData/generalCommonization/annotations/commonized/common/package_root.kt @@ -1,3 +1,6 @@ +expect annotation class CommonAnnotationForAnnotationClassesOnly(text: String) { val text: String } +expect annotation class CommonAnnotation(text: String) { val text: String } + expect var propertyWithoutBackingField: Double expect val propertyWithBackingField: Double expect val propertyWithDelegateField: Int @@ -5,3 +8,6 @@ expect val T.propertyWithExtensionReceiver: Int expect fun function1(text: String): String expect fun Q.function2(): Q + +expect class AnnotatedClass(value: String) { val value: String } +expect class AnnotatedTypeAlias diff --git a/konan/commonizer/testData/generalCommonization/annotations/commonized/js/package_root.kt b/konan/commonizer/testData/generalCommonization/annotations/commonized/js/package_root.kt index d35a86d583d..a235cc5aea5 100644 --- a/konan/commonizer/testData/generalCommonization/annotations/commonized/js/package_root.kt +++ b/konan/commonizer/testData/generalCommonization/annotations/commonized/js/package_root.kt @@ -1,27 +1,50 @@ import kotlin.annotation.AnnotationTarget.* -@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER) -annotation class Foo(val text: String) +@Target(ANNOTATION_CLASS) +actual annotation class CommonAnnotationForAnnotationClassesOnly actual constructor(actual val text: String) -@property:Foo("property") -@get:Foo("getter") -@set:Foo("setter") -@setparam:Foo("parameter") +@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, TYPE_PARAMETER, FUNCTION, CLASS, CONSTRUCTOR, TYPEALIAS, TYPE) +@JsAnnotationForAnnotationClassesOnly("annotation-class") +@CommonAnnotationForAnnotationClassesOnly("annotation-class") +actual annotation class CommonAnnotation actual constructor(actual val text: String) + +@Target(ANNOTATION_CLASS) +annotation class JsAnnotationForAnnotationClassesOnly(val text: String) + +@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, TYPE_PARAMETER, FUNCTION, CLASS, CONSTRUCTOR, TYPEALIAS, TYPE) +@JsAnnotationForAnnotationClassesOnly("annotation-class") +@CommonAnnotationForAnnotationClassesOnly("annotation-class") +annotation class JsAnnotation(val text: String) + +@JsAnnotation("property") +@CommonAnnotation("property") actual var propertyWithoutBackingField - get() = 3.14 - set(value) = Unit + @JsAnnotation("getter") @CommonAnnotation("getter") get() = 3.14 + @JsAnnotation("setter") @CommonAnnotation("setter") set(@JsAnnotation("parameter") @CommonAnnotation("parameter") value) = Unit -@field:Foo("field") +@field:JsAnnotation("field") +@field:CommonAnnotation("field") actual val propertyWithBackingField = 3.14 -@delegate:Foo("field") +@delegate:JsAnnotation("field") +@delegate:CommonAnnotation("field") actual val propertyWithDelegateField: Int by lazy { 42 } -actual val <@Foo("type-parameter") T : CharSequence> @receiver:Foo("receiver") T.propertyWithExtensionReceiver: Int +actual val <@JsAnnotation("type-parameter") @CommonAnnotation("type-parameter") T : CharSequence> @receiver:JsAnnotation("receiver") @receiver:CommonAnnotation("receiver") T.propertyWithExtensionReceiver: Int get() = length -@Foo("function") -actual fun function1(@Foo("parameter") text: String) = text +@JsAnnotation("function") +@CommonAnnotation("function") +actual fun function1(@JsAnnotation("parameter") @CommonAnnotation("parameter") text: String) = text -@Foo("function") -actual fun <@Foo("type-parameter") Q : Number> @receiver:Foo("receiver") Q.function2() = this +@JsAnnotation("function") +@CommonAnnotation("function") +actual fun <@JsAnnotation("type-parameter") @CommonAnnotation("type-parameter") Q : @JsAnnotation("type1") @CommonAnnotation("type1") Number> @receiver:JsAnnotation("receiver") @receiver:CommonAnnotation("receiver") Q.function2(): @JsAnnotation("type2") @CommonAnnotation("type2") Q = this + +@JsAnnotation("class") +@CommonAnnotation("class") +actual class AnnotatedClass @JsAnnotation("constructor") @CommonAnnotation("constructor") actual constructor(actual val value: String) + +@JsAnnotation("type-alias") +@CommonAnnotation("type-alias") +actual typealias AnnotatedTypeAlias = AnnotatedClass diff --git a/konan/commonizer/testData/generalCommonization/annotations/commonized/jvm/package_root.kt b/konan/commonizer/testData/generalCommonization/annotations/commonized/jvm/package_root.kt index ddd2d2717a9..2178c626759 100644 --- a/konan/commonizer/testData/generalCommonization/annotations/commonized/jvm/package_root.kt +++ b/konan/commonizer/testData/generalCommonization/annotations/commonized/jvm/package_root.kt @@ -1,24 +1,50 @@ import kotlin.annotation.AnnotationTarget.* -@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER) -annotation class Bar(val text: String) +@Target(ANNOTATION_CLASS) +actual annotation class CommonAnnotationForAnnotationClassesOnly actual constructor(actual val text: String) -@Bar("property") +@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, TYPE_PARAMETER, FUNCTION, CLASS, CONSTRUCTOR, TYPEALIAS, TYPE) +@JvmAnnotationForAnnotationClassesOnly("annotation-class") +@CommonAnnotationForAnnotationClassesOnly("annotation-class") +actual annotation class CommonAnnotation actual constructor(actual val text: String) + +@Target(ANNOTATION_CLASS) +annotation class JvmAnnotationForAnnotationClassesOnly(val text: String) + +@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, TYPE_PARAMETER, FUNCTION, CLASS, CONSTRUCTOR, TYPEALIAS, TYPE) +@JvmAnnotationForAnnotationClassesOnly("annotation-class") +@CommonAnnotationForAnnotationClassesOnly("annotation-class") +annotation class JvmAnnotation(val text: String) + +@JvmAnnotation("property") +@CommonAnnotation("property") actual var propertyWithoutBackingField - @Bar("getter") get() = 3.14 - @Bar("setter") set(@Bar("parameter") value) = Unit + @JvmAnnotation("getter") @CommonAnnotation("getter") get() = 3.14 + @JvmAnnotation("setter") @CommonAnnotation("setter") set(@JvmAnnotation("parameter") @CommonAnnotation("parameter") value) = Unit -@field:Bar("field") +@field:JvmAnnotation("field") +@field:CommonAnnotation("field") actual val propertyWithBackingField = 3.14 -@delegate:Bar("field") +@delegate:JvmAnnotation("field") +@delegate:CommonAnnotation("field") actual val propertyWithDelegateField: Int by lazy { 42 } -actual val <@Bar("type-parameter") T : CharSequence> @receiver:Bar("receiver") T.propertyWithExtensionReceiver: Int +actual val <@JvmAnnotation("type-parameter") @CommonAnnotation("type-parameter") T : CharSequence> @receiver:JvmAnnotation("receiver") @receiver:CommonAnnotation("receiver") T.propertyWithExtensionReceiver: Int get() = length -@Bar("function") -actual fun function1(@Bar("parameter") text: String) = text +@JvmAnnotation("function") +@CommonAnnotation("function") +actual fun function1(@JvmAnnotation("parameter") @CommonAnnotation("parameter") text: String) = text -@Bar("function") -actual fun <@Bar("type-parameter") Q : Number> @receiver:Bar("receiver") Q.function2() = this +@JvmAnnotation("function") +@CommonAnnotation("function") +actual fun <@JvmAnnotation("type-parameter") @CommonAnnotation("type-parameter") Q : @JvmAnnotation("type1") @CommonAnnotation("type1") Number> @receiver:JvmAnnotation("receiver") @receiver:CommonAnnotation("receiver") Q.function2(): @JvmAnnotation("type2") @CommonAnnotation("type2") Q = this + +@JvmAnnotation("class") +@CommonAnnotation("class") +actual class AnnotatedClass @JvmAnnotation("constructor") @CommonAnnotation("constructor") actual constructor(actual val value: String) + +@JvmAnnotation("type-alias") +@CommonAnnotation("type-alias") +actual typealias AnnotatedTypeAlias = AnnotatedClass diff --git a/konan/commonizer/testData/generalCommonization/annotations/original/js/package_root.kt b/konan/commonizer/testData/generalCommonization/annotations/original/js/package_root.kt index fedae0e5d6e..c4424dc7394 100644 --- a/konan/commonizer/testData/generalCommonization/annotations/original/js/package_root.kt +++ b/konan/commonizer/testData/generalCommonization/annotations/original/js/package_root.kt @@ -1,24 +1,50 @@ import kotlin.annotation.AnnotationTarget.* -@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, TYPE_PARAMETER, FUNCTION) -annotation class Foo(val text: String) +@Target(ANNOTATION_CLASS) +annotation class CommonAnnotationForAnnotationClassesOnly(val text: String) -@Foo("property") +@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, TYPE_PARAMETER, FUNCTION, CLASS, CONSTRUCTOR, TYPEALIAS, TYPE) +@JsAnnotationForAnnotationClassesOnly("annotation-class") +@CommonAnnotationForAnnotationClassesOnly("annotation-class") +annotation class CommonAnnotation(val text: String) + +@Target(ANNOTATION_CLASS) +annotation class JsAnnotationForAnnotationClassesOnly(val text: String) + +@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, TYPE_PARAMETER, FUNCTION, CLASS, CONSTRUCTOR, TYPEALIAS, TYPE) +@JsAnnotationForAnnotationClassesOnly("annotation-class") +@CommonAnnotationForAnnotationClassesOnly("annotation-class") +annotation class JsAnnotation(val text: String) + +@JsAnnotation("property") +@CommonAnnotation("property") var propertyWithoutBackingField - @Foo("getter") get() = 3.14 - @Foo("setter") set(@Foo("parameter") value) = Unit + @JsAnnotation("getter") @CommonAnnotation("getter") get() = 3.14 + @JsAnnotation("setter") @CommonAnnotation("setter") set(@JsAnnotation("parameter") @CommonAnnotation("parameter") value) = Unit -@field:Foo("field") +@field:JsAnnotation("field") +@field:CommonAnnotation("field") val propertyWithBackingField = 3.14 -@delegate:Foo("field") +@delegate:JsAnnotation("field") +@delegate:CommonAnnotation("field") val propertyWithDelegateField: Int by lazy { 42 } -val <@Foo("type-parameter") T : CharSequence> @receiver:Foo("receiver") T.propertyWithExtensionReceiver: Int +val <@JsAnnotation("type-parameter") @CommonAnnotation("type-parameter") T : CharSequence> @receiver:JsAnnotation("receiver") @receiver:CommonAnnotation("receiver") T.propertyWithExtensionReceiver: Int get() = length -@Foo("function") -fun function1(@Foo("parameter") text: String) = text +@JsAnnotation("function") +@CommonAnnotation("function") +fun function1(@JsAnnotation("parameter") @CommonAnnotation("parameter") text: String) = text -@Foo("function") -fun <@Foo("type-parameter") Q : Number> @receiver:Foo("receiver") Q.function2() = this +@JsAnnotation("function") +@CommonAnnotation("function") +fun <@JsAnnotation("type-parameter") @CommonAnnotation("type-parameter") Q : @JsAnnotation("type1") @CommonAnnotation("type1") Number> @receiver:JsAnnotation("receiver") @receiver:CommonAnnotation("receiver") Q.function2(): @JsAnnotation("type2") @CommonAnnotation("type2") Q = this + +@JsAnnotation("class") +@CommonAnnotation("class") +class AnnotatedClass @JsAnnotation("constructor") @CommonAnnotation("constructor") constructor(val value: String) + +@JsAnnotation("type-alias") +@CommonAnnotation("type-alias") +typealias AnnotatedTypeAlias = AnnotatedClass diff --git a/konan/commonizer/testData/generalCommonization/annotations/original/jvm/package_root.kt b/konan/commonizer/testData/generalCommonization/annotations/original/jvm/package_root.kt index 12f9416217d..c04f8f2f246 100644 --- a/konan/commonizer/testData/generalCommonization/annotations/original/jvm/package_root.kt +++ b/konan/commonizer/testData/generalCommonization/annotations/original/jvm/package_root.kt @@ -1,24 +1,50 @@ import kotlin.annotation.AnnotationTarget.* -@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER) -annotation class Bar(val text: String) +@Target(ANNOTATION_CLASS) +annotation class CommonAnnotationForAnnotationClassesOnly(val text: String) -@Bar("property") +@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, TYPE_PARAMETER, FUNCTION, CLASS, CONSTRUCTOR, TYPEALIAS, TYPE) +@JvmAnnotationForAnnotationClassesOnly("annotation-class") +@CommonAnnotationForAnnotationClassesOnly("annotation-class") +annotation class CommonAnnotation(val text: String) + +@Target(ANNOTATION_CLASS) +annotation class JvmAnnotationForAnnotationClassesOnly(val text: String) + +@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, TYPE_PARAMETER, FUNCTION, CLASS, CONSTRUCTOR, TYPEALIAS, TYPE) +@JvmAnnotationForAnnotationClassesOnly("annotation-class") +@CommonAnnotationForAnnotationClassesOnly("annotation-class") +annotation class JvmAnnotation(val text: String) + +@JvmAnnotation("property") +@CommonAnnotation("property") var propertyWithoutBackingField - @Bar("getter") get() = 3.14 - @Bar("setter") set(@Bar("parameter") value) = Unit + @JvmAnnotation("getter") @CommonAnnotation("getter") get() = 3.14 + @JvmAnnotation("setter") @CommonAnnotation("setter") set(@JvmAnnotation("parameter") @CommonAnnotation("parameter") value) = Unit -@field:Bar("field") +@field:JvmAnnotation("field") +@field:CommonAnnotation("field") val propertyWithBackingField = 3.14 -@delegate:Bar("field") +@delegate:JvmAnnotation("field") +@delegate:CommonAnnotation("field") val propertyWithDelegateField: Int by lazy { 42 } -val <@Bar("type-parameter") T : CharSequence> @receiver:Bar("receiver") T.propertyWithExtensionReceiver: Int +val <@JvmAnnotation("type-parameter") @CommonAnnotation("type-parameter") T : CharSequence> @receiver:JvmAnnotation("receiver") @receiver:CommonAnnotation("receiver") T.propertyWithExtensionReceiver: Int get() = length -@Bar("function") -fun function1(@Bar("parameter") text: String) = text +@JvmAnnotation("function") +@CommonAnnotation("function") +fun function1(@JvmAnnotation("parameter") @CommonAnnotation("parameter") text: String) = text -@Bar("function") -fun <@Bar("type-parameter") Q : Number> @receiver:Bar("receiver") Q.function2() = this +@JvmAnnotation("function") +@CommonAnnotation("function") +fun <@JvmAnnotation("type-parameter") @CommonAnnotation("type-parameter") Q : @JvmAnnotation("type1") @CommonAnnotation("type1") Number> @receiver:JvmAnnotation("receiver") @receiver:CommonAnnotation("receiver") Q.function2(): @JvmAnnotation("type2") @CommonAnnotation("type2") Q = this + +@JvmAnnotation("class") +@CommonAnnotation("class") +class AnnotatedClass @JvmAnnotation("constructor") @CommonAnnotation("constructor") constructor(val value: String) + +@JvmAnnotation("type-alias") +@CommonAnnotation("type-alias") +typealias AnnotatedTypeAlias = AnnotatedClass diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/AbstractCommonizationFromSourcesTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/AbstractCommonizationFromSourcesTest.kt index fcaf46cae0a..db3df7ecbc7 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/AbstractCommonizationFromSourcesTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/AbstractCommonizationFromSourcesTest.kt @@ -12,6 +12,10 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.languageVersionSettings import org.jetbrains.kotlin.descriptors.ModuleDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.utils.assertCommonizationPerformed +import org.jetbrains.kotlin.descriptors.commonizer.utils.assertIsDirectory +import org.jetbrains.kotlin.descriptors.commonizer.utils.assertModulesAreEqual +import org.jetbrains.kotlin.descriptors.commonizer.utils.assertValidModule import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.test.KotlinTestUtils.* @@ -130,6 +134,8 @@ abstract class AbstractCommonizationFromSourcesTest : KtUsefulTestCase() { val commonModuleAsExpected = commonizedModules.getValue("common") val commonModuleByCommonizer = result.commonModules.single() + assertValidModule(commonModuleAsExpected) + assertValidModule(commonModuleByCommonizer) assertModulesAreEqual(commonModuleAsExpected, commonModuleByCommonizer, "\"common\" target") val concreteTargetNames = commonizedModules.keys - "common" @@ -139,6 +145,8 @@ abstract class AbstractCommonizationFromSourcesTest : KtUsefulTestCase() { val targetModuleAsExpected = commonizedModules.getValue(targetName) val targetModuleByCommonizer = result.modulesByTargets.getValue(targetName).single() + assertValidModule(targetModuleAsExpected) + assertValidModule(targetModuleByCommonizer) assertModulesAreEqual(targetModuleAsExpected, targetModuleByCommonizer, "\"$targetName\" target") } } diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CallableMemberCommonizationFromSourcesTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CallableMemberCommonizationFromSourcesTest.kt index 975393eb4d4..e99cc407631 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CallableMemberCommonizationFromSourcesTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CallableMemberCommonizationFromSourcesTest.kt @@ -15,7 +15,4 @@ class CallableMemberCommonizationFromSourcesTest : AbstractCommonizationFromSour fun testReturnTypes() = doTestSuccessfulCommonization() fun testExtensionReceivers() = doTestSuccessfulCommonization() - - // TODO: test modality (possible only inside classes) - // TODO: test virtual val/fun visibility commonization (possible only inside classes) } diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/ClassifierCommonizationFromSourcesTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/ClassifierCommonizationFromSourcesTest.kt new file mode 100644 index 00000000000..eaf9745d2b7 --- /dev/null +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/ClassifierCommonizationFromSourcesTest.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer + +import kotlin.contracts.ExperimentalContracts + +@ExperimentalContracts +class ClassifierCommonizationFromSourcesTest : AbstractCommonizationFromSourcesTest() { + + fun testClassKindAndModifiers() = doTestSuccessfulCommonization() + + fun testModality() = doTestSuccessfulCommonization() + + fun testVisibility() = doTestSuccessfulCommonization() + + fun testConstructors() = doTestSuccessfulCommonization() + + fun testTypeParameters() = doTestSuccessfulCommonization() + + fun testSupertypes() = doTestSuccessfulCommonization() + + fun testTypeAliases() = doTestSuccessfulCommonization() +} diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CommonizerFacadeTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CommonizerFacadeTest.kt index 811fa8740da..94fe562c190 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CommonizerFacadeTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CommonizerFacadeTest.kt @@ -6,9 +6,11 @@ package org.jetbrains.kotlin.descriptors.commonizer import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.junit.Assert.* +import kotlin.test.* import org.junit.Test import org.jetbrains.kotlin.descriptors.commonizer.AbstractCommonizationFromSourcesTest.Companion.eachModuleAsTarget +import org.jetbrains.kotlin.descriptors.commonizer.utils.assertCommonizationPerformed +import org.jetbrains.kotlin.descriptors.commonizer.utils.mockEmptyModule import kotlin.contracts.ExperimentalContracts @ExperimentalContracts diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractCommonizerTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractCommonizerTest.kt index 21549f2b61f..54ef580d834 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractCommonizerTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractCommonizerTest.kt @@ -5,8 +5,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.junit.Assert.* import org.junit.Test +import kotlin.test.* abstract class AbstractCommonizerTest { diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultExtensionReceiverCommonizerTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultExtensionReceiverCommonizerTest.kt index 919ea145e59..a23ab4d2e0c 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultExtensionReceiverCommonizerTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultExtensionReceiverCommonizerTest.kt @@ -6,9 +6,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.commonizer.EMPTY_CLASSIFIERS_CACHE +import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiver -import org.jetbrains.kotlin.descriptors.commonizer.mockClassType +import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.refinement.TypeRefinement import org.junit.Test diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeCommonizerTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeCommonizerTest.kt index a76cbaf1cda..5e9d9e0baee 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeCommonizerTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeCommonizerTest.kt @@ -11,8 +11,8 @@ import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroupMap import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.RootNode.ClassifiersCacheImpl import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildClassNode import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildTypeAliasNode -import org.jetbrains.kotlin.descriptors.commonizer.mockClassType -import org.jetbrains.kotlin.descriptors.commonizer.mockTAType +import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType +import org.jetbrains.kotlin.descriptors.commonizer.utils.mockTAType import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.storage.LockBasedStorageManager diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeParameterCommonizerTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeParameterCommonizerTest.kt index 5a8161fdf0c..e1cda38f030 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeParameterCommonizerTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeParameterCommonizerTest.kt @@ -5,10 +5,10 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.EMPTY_CLASSIFIERS_CACHE +import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonTypeParameter import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeParameter -import org.jetbrains.kotlin.descriptors.commonizer.mockClassType +import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.refinement.TypeRefinement diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeParameterListCommonizerTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeParameterListCommonizerTest.kt index 93a88b18890..a54313c3464 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeParameterListCommonizerTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultTypeParameterListCommonizerTest.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.EMPTY_CLASSIFIERS_CACHE +import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeParameter import org.jetbrains.kotlin.types.refinement.TypeRefinement import org.junit.Test diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultValueParameterCommonizerTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultValueParameterCommonizerTest.kt index 123ba791781..2d11a529618 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultValueParameterCommonizerTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultValueParameterCommonizerTest.kt @@ -6,11 +6,11 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.commonizer.EMPTY_CLASSIFIERS_CACHE +import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE import org.jetbrains.kotlin.descriptors.commonizer.core.TestValueParameter.Companion.areEqual import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ValueParameter -import org.jetbrains.kotlin.descriptors.commonizer.mockClassType +import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.refinement.TypeRefinement diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultValueParameterListCommonizerTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultValueParameterListCommonizerTest.kt index e4d04627602..ff580d57d56 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultValueParameterListCommonizerTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultValueParameterListCommonizerTest.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.EMPTY_CLASSIFIERS_CACHE +import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE import org.jetbrains.kotlin.descriptors.commonizer.core.TestValueParameter.Companion.areEqual import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ValueParameter import org.jetbrains.kotlin.types.refinement.TypeRefinement diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/LoweringVisibilityCommonizerTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/LoweringVisibilityCommonizerTest.kt index 1353a390e41..809d0bf8a04 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/LoweringVisibilityCommonizerTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/LoweringVisibilityCommonizerTest.kt @@ -7,8 +7,10 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.Visibilities.* -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.DeclarationWithVisibility -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.MaybeVirtualCallableMember +import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.UnwrappedType import org.junit.Test abstract class LoweringVisibilityCommonizerTest( @@ -30,9 +32,19 @@ abstract class LoweringVisibilityCommonizerTest( final override fun createCommonizer() = VisibilityCommonizer.lowering(allowPrivate = allowPrivate) - protected fun Visibility.toMock() = object : MaybeVirtualCallableMember { + protected fun Visibility.toMock() = object : FunctionOrProperty { override val visibility: Visibility = this@toMock - override val isVirtual: Boolean = !isPrivate(visibility) && areMembersVirtual + override val modality: Modality get() = if (areMembersVirtual) Modality.OPEN else Modality.FINAL + override val containingClassModality: Modality? get() = if (areMembersVirtual) Modality.OPEN else null + override val containingClassKind: ClassKind? get() = if (areMembersVirtual) ClassKind.CLASS else null + override val isExternal: Boolean get() = unsupported() + override val extensionReceiver: ExtensionReceiver? get() = unsupported() + override val returnType: UnwrappedType get() = unsupported() + override val kind: CallableMemberDescriptor.Kind get() = unsupported() + override val annotations: Annotations get() = unsupported() + override val name: Name get() = unsupported() + override val containingClassIsData: Boolean? get() = unsupported() + override val typeParameters: List get() = unsupported() } class PrivateMembers : LoweringVisibilityCommonizerTest(true, false) { diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/assertions.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/ComparingDeclarationsVisitor.kt similarity index 95% rename from konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/assertions.kt rename to konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/ComparingDeclarationsVisitor.kt index 2e91596c66f..36da5f610a1 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/assertions.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/ComparingDeclarationsVisitor.kt @@ -3,47 +3,25 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.descriptors.commonizer +package org.jetbrains.kotlin.descriptors.commonizer.utils -import junit.framework.TestCase.fail import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.descriptors.commonizer.fqName +import org.jetbrains.kotlin.descriptors.commonizer.fqNameWithTypeParameters +import org.jetbrains.kotlin.descriptors.commonizer.isNull import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.* import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.getAbbreviation -import java.io.File import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract import kotlin.reflect.KCallable - -fun assertIsDirectory(file: File) { - if (!file.isDirectory) - fail("Not a directory: $file") -} +import kotlin.test.fail @ExperimentalContracts -fun assertCommonizationPerformed(result: CommonizationResult) { - contract { - returns() implies (result is CommonizationPerformed) - } - - if (result !is CommonizationPerformed) - fail("$result is not instance of ${CommonizationPerformed::class}") -} - -@ExperimentalContracts -fun assertModulesAreEqual(expected: ModuleDescriptor, actual: ModuleDescriptor, designatorMessage: String) { - val visitor = ComparingDeclarationsVisitor(designatorMessage) - val context = visitor.Context(actual) - - expected.accept(visitor, context) -} - -@ExperimentalContracts -private class ComparingDeclarationsVisitor( +internal class ComparingDeclarationsVisitor( val designatorMessage: String ) : DeclarationDescriptorVisitor { @@ -91,7 +69,7 @@ private class ComparingDeclarationsVisitor( } } - fun visitMemberScopes(expected: MemberScope, actual: MemberScope, context: Context) { + private fun visitMemberScopes(expected: MemberScope, actual: MemberScope, context: Context) { val expectedProperties = mutableMapOf() val expectedFunctions = mutableMapOf() val expectedClasses = mutableMapOf() @@ -162,10 +140,16 @@ private class ComparingDeclarationsVisitor( context.assertFieldsEqual(expected::isSuspend, actual::isSuspend) context.assertFieldsEqual(expected::isExternal, actual::isExternal) context.assertFieldsEqual(expected::isExpect, actual::isExpect) - context.assertFieldsEqual(expected::isActual, actual::isActual) context.assertFieldsEqual(expected::hasStableParameterNames, actual::hasStableParameterNames) context.assertFieldsEqual(expected::hasSynthesizedParameterNames, actual::hasSynthesizedParameterNames) + if (!expected.isActual || actual.kind != CallableMemberDescriptor.Kind.DELEGATION) { + context.assertFieldsEqual(expected::isActual, actual::isActual) + } /* else { + // don't check, because there can be any value in expect.isActual + // see org.jetbrains.kotlin.resolve.DelegationResolver + } */ + visitType(expected.returnType, actual.returnType, context.nextLevel("Function type")) visitValueParameterDescriptorList(expected.valueParameters, actual.valueParameters, context.nextLevel("Function value parameters")) @@ -176,7 +160,7 @@ private class ComparingDeclarationsVisitor( visitTypeParameters(expected.typeParameters, actual.typeParameters, context.nextLevel("Function type parameters")) } - fun visitValueParameterDescriptorList( + private fun visitValueParameterDescriptorList( expected: List, actual: List, context: Context @@ -339,9 +323,17 @@ private class ComparingDeclarationsVisitor( context.assertFieldsEqual(expected::isConst, actual::isConst) context.assertFieldsEqual(expected::isExternal, actual::isExternal) context.assertFieldsEqual(expected::isExpect, actual::isExpect) - context.assertFieldsEqual(expected::isActual, actual::isActual) + + if (!expected.isActual || actual.kind != CallableMemberDescriptor.Kind.DELEGATION) { + context.assertFieldsEqual(expected::isActual, actual::isActual) + } /* else { + // don't check, because there can be any value in expect.isActual + // see org.jetbrains.kotlin.resolve.DelegationResolver + } */ + @Suppress("DEPRECATION") context.assertFieldsEqual(expected::isDelegated, actual::isDelegated) + visitAnnotations( expected.delegateField?.annotations, actual.delegateField?.annotations, @@ -352,6 +344,7 @@ private class ComparingDeclarationsVisitor( actual.backingField?.annotations, context.nextLevel("Property backing field annotations") ) + context.assertEquals(expected.compileTimeInitializer.isNull(), actual.compileTimeInitializer.isNull(), "compile-time initializers") visitType(expected.type, actual.type, context.nextLevel("Property type")) diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/assertions.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/assertions.kt new file mode 100644 index 00000000000..3000c301460 --- /dev/null +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/assertions.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.utils + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.commonizer.CommonizationPerformed +import org.jetbrains.kotlin.descriptors.commonizer.CommonizationResult +import org.jetbrains.kotlin.test.util.DescriptorValidator.* +import org.jetbrains.kotlin.types.ErrorUtils +import java.io.File +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract +import kotlin.test.assertFalse +import kotlin.test.fail + +fun assertIsDirectory(file: File) { + if (!file.isDirectory) + fail("Not a directory: $file") +} + +@ExperimentalContracts +fun assertCommonizationPerformed(result: CommonizationResult) { + contract { + returns() implies (result is CommonizationPerformed) + } + + if (result !is CommonizationPerformed) + fail("$result is not instance of ${CommonizationPerformed::class}") +} + +@ExperimentalContracts +fun assertModulesAreEqual(expected: ModuleDescriptor, actual: ModuleDescriptor, designatorMessage: String) { + val visitor = ComparingDeclarationsVisitor(designatorMessage) + val context = visitor.Context(actual) + + expected.accept(visitor, context) +} + +fun assertValidModule(module: ModuleDescriptor) = validate( + object : ValidationVisitor() { + override fun visitModuleDeclaration(descriptor: ModuleDescriptor, collector: DiagnosticCollector): Boolean { + assertValid(descriptor) + return super.visitModuleDeclaration(descriptor, collector) + } + + override fun visitClassDescriptor(descriptor: ClassDescriptor, collector: DiagnosticCollector): Boolean { + assertValid(descriptor) + return super.visitClassDescriptor(descriptor, collector) + } + + override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, collector: DiagnosticCollector): Boolean { + assertValid(descriptor) + return super.visitFunctionDescriptor(descriptor, collector) + } + + override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, collector: DiagnosticCollector): Boolean { + assertValid(descriptor) + return super.visitPropertyDescriptor(descriptor, collector) + } + + override fun visitConstructorDescriptor(constructorDescriptor: ConstructorDescriptor, collector: DiagnosticCollector): Boolean { + assertValid(constructorDescriptor) + return super.visitConstructorDescriptor(constructorDescriptor, collector) + } + }, + module +) + +@Suppress("NOTHING_TO_INLINE") +private inline fun assertValid(descriptor: DeclarationDescriptor) = when (descriptor) { + is ModuleDescriptor -> descriptor.assertValid() + else -> assertFalse(ErrorUtils.isError(descriptor), "$descriptor is error") +} diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/mocks.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt similarity index 99% rename from konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/mocks.kt rename to konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt index 127325316fe..ccef2b7dab1 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/mocks.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt @@ -3,7 +3,7 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.descriptors.commonizer +package org.jetbrains.kotlin.descriptors.commonizer.utils import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations