[Commonizer] Type parameters, type parameter tests
This commit is contained in:
Generated
+1
@@ -5,6 +5,7 @@
|
||||
<w>commonize</w>
|
||||
<w>commonized</w>
|
||||
<w>commonizer</w>
|
||||
<w>commonizers</w>
|
||||
<w>konan</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
|
||||
+3
-11
@@ -59,18 +59,10 @@ private fun Function.buildDescriptor(
|
||||
functionDescriptor.isExpect = isExpect
|
||||
functionDescriptor.isActual = isActual
|
||||
|
||||
val extensionReceiverDescriptor = DescriptorFactory.createExtensionReceiverParameterForCallable(
|
||||
functionDescriptor,
|
||||
extensionReceiver?.type,
|
||||
extensionReceiver?.annotations ?: Annotations.EMPTY
|
||||
)
|
||||
|
||||
val dispatchReceiverDescriptor = DescriptorUtils.getDispatchReceiverParameterIfNeeded(containingDeclaration)
|
||||
|
||||
functionDescriptor.initialize(
|
||||
extensionReceiverDescriptor,
|
||||
dispatchReceiverDescriptor,
|
||||
emptyList(), // TODO: support type parameters
|
||||
extensionReceiver?.buildExtensionReceiver(functionDescriptor),
|
||||
buildDispatchReceiver(functionDescriptor),
|
||||
typeParameters.buildDescriptors(functionDescriptor),
|
||||
valueParameters.buildValueParameters(functionDescriptor),
|
||||
returnType,
|
||||
modality,
|
||||
|
||||
+3
-13
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroup
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Property
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.PropertyNode
|
||||
@@ -16,7 +15,6 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.indexOfCommon
|
||||
import org.jetbrains.kotlin.descriptors.impl.FieldDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
internal fun PropertyNode.buildDescriptors(
|
||||
@@ -60,19 +58,11 @@ private fun Property.buildDescriptor(
|
||||
isDelegate
|
||||
)
|
||||
|
||||
val extensionReceiverDescriptor = DescriptorFactory.createExtensionReceiverParameterForCallable(
|
||||
propertyDescriptor,
|
||||
extensionReceiver?.type,
|
||||
extensionReceiver?.annotations ?: Annotations.EMPTY
|
||||
)
|
||||
|
||||
val dispatchReceiverDescriptor = DescriptorUtils.getDispatchReceiverParameterIfNeeded(containingDeclaration)
|
||||
|
||||
propertyDescriptor.setType(
|
||||
returnType,
|
||||
emptyList(), // TODO: support type parameters
|
||||
dispatchReceiverDescriptor,
|
||||
extensionReceiverDescriptor
|
||||
typeParameters.buildDescriptors(propertyDescriptor),
|
||||
buildDispatchReceiver(propertyDescriptor),
|
||||
extensionReceiver?.buildExtensionReceiver(propertyDescriptor)
|
||||
)
|
||||
|
||||
val getterDescriptor = getter?.let { getter ->
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.builder
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiver
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeParameter
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
internal fun List<TypeParameter>.buildDescriptors(
|
||||
containingDeclaration: DeclarationDescriptor
|
||||
): List<TypeParameterDescriptor> {
|
||||
return mapIndexed { index, param ->
|
||||
val descriptor = TypeParameterDescriptorImpl.createForFurtherModification(
|
||||
containingDeclaration,
|
||||
param.annotations,
|
||||
param.isReified,
|
||||
param.variance,
|
||||
param.name,
|
||||
index,
|
||||
SourceElement.NO_SOURCE
|
||||
)
|
||||
|
||||
param.upperBounds.forEach(descriptor::addUpperBound)
|
||||
descriptor.setInitialized()
|
||||
|
||||
descriptor
|
||||
}
|
||||
}
|
||||
|
||||
internal fun ExtensionReceiver.buildExtensionReceiver(
|
||||
containingDeclaration: CallableDescriptor
|
||||
) = DescriptorFactory.createExtensionReceiverParameterForCallable(
|
||||
containingDeclaration,
|
||||
type,
|
||||
annotations
|
||||
)
|
||||
|
||||
internal fun buildDispatchReceiver(callableDescriptor: CallableDescriptor) =
|
||||
DescriptorUtils.getDispatchReceiverParameterIfNeeded(callableDescriptor.containingDeclaration)
|
||||
+3
-1
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CallableMember
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract class CallableMemberCommonizer<T : CallableMemberDescriptor, R: CallableMember> : Commonizer<T, R> {
|
||||
abstract class AbstractCallableMemberCommonizer<T : CallableMemberDescriptor, R: CallableMember> : Commonizer<T, R> {
|
||||
protected enum class State {
|
||||
EMPTY,
|
||||
ERROR,
|
||||
@@ -22,6 +22,7 @@ abstract class CallableMemberCommonizer<T : CallableMemberDescriptor, R: Callabl
|
||||
protected val visibility = VisibilityCommonizer.lowering()
|
||||
protected val extensionReceiver = ExtensionReceiverCommonizer.default()
|
||||
protected val returnType = TypeCommonizer.default()
|
||||
protected val typeParameters = TypeParameterListCommonizer.default()
|
||||
|
||||
protected var state = State.EMPTY
|
||||
|
||||
@@ -37,6 +38,7 @@ abstract class CallableMemberCommonizer<T : CallableMemberDescriptor, R: Callabl
|
||||
&& visibility.commonizeWith(next.visibility)
|
||||
&& extensionReceiver.commonizeWith(next.extensionReceiverParameter)
|
||||
&& returnType.commonizeWith(next.returnType!!)
|
||||
&& typeParameters.commonizeWith(next.typeParameters)
|
||||
&& commonizeSpecifics(next)
|
||||
|
||||
state = if (!result) State.ERROR else State.IN_PROGRESS
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.core
|
||||
|
||||
abstract class AbstractListCommonizer<T, R>(
|
||||
private val subject: String,
|
||||
private val singleElementCommonizerFactory: () -> Commonizer<T, R>
|
||||
) : Commonizer<List<T>, List<R>> {
|
||||
private var commonizers: List<Commonizer<T, R>>? = null
|
||||
private var error = false
|
||||
|
||||
final override val result: List<R>
|
||||
get() = commonizers?.takeIf { !error }?.map { it.result } ?: error("Can't commonize list of $subject")
|
||||
|
||||
final override fun commonizeWith(next: List<T>): Boolean {
|
||||
if (error)
|
||||
return false
|
||||
|
||||
val commonizers = commonizers
|
||||
?: mutableListOf<Commonizer<T, R>>().apply {
|
||||
repeat(next.size) {
|
||||
this += singleElementCommonizerFactory()
|
||||
}
|
||||
}.also {
|
||||
this.commonizers = it
|
||||
}
|
||||
|
||||
if (commonizers.size != next.size)
|
||||
error = true
|
||||
else
|
||||
for (index in 0 until next.size) {
|
||||
val commonizer = commonizers[index]
|
||||
val nextElement = next[index]
|
||||
|
||||
if (!commonizer.commonizeWith(nextElement)) {
|
||||
error = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return !error
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -8,28 +8,28 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
|
||||
import org.jetbrains.kotlin.descriptors.Named
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract class NamedListWrappedCommonizer<T : Named, R>(
|
||||
abstract class AbstractNamedListCommonizer<T : Named, R>(
|
||||
private val subject: String,
|
||||
private val wrappedCommonizerFactory: () -> Commonizer<T, R>
|
||||
private val singleElementCommonizerFactory: () -> Commonizer<T, R>
|
||||
) : Commonizer<List<T>, List<R>> {
|
||||
private var wrapped: List<Pair<Name, Commonizer<T, R>>>? = null
|
||||
private var commonizers: List<Pair<Name, Commonizer<T, R>>>? = null
|
||||
private var error = false
|
||||
|
||||
final override val result: List<R>
|
||||
get() = wrapped?.takeIf { !error }?.map { it.second.result } ?: error("Can't commonize list of $subject")
|
||||
get() = commonizers?.takeIf { !error }?.map { it.second.result } ?: error("Can't commonize list of $subject")
|
||||
|
||||
final override fun commonizeWith(next: List<T>): Boolean {
|
||||
if (error)
|
||||
return false
|
||||
|
||||
val wrapped = wrapped
|
||||
?: next.map { it.name to wrappedCommonizerFactory() }.also { this.wrapped = it }
|
||||
val commonizers = commonizers
|
||||
?: next.map { it.name to singleElementCommonizerFactory() }.also { this.commonizers = it }
|
||||
|
||||
if (wrapped.size != next.size)
|
||||
if (commonizers.size != next.size)
|
||||
error = true
|
||||
else
|
||||
for (index in 0 until next.size) {
|
||||
val (name, commonizer) = wrapped[index]
|
||||
val (name, commonizer) = commonizers[index]
|
||||
val nextElement = next[index]
|
||||
|
||||
if (name != nextElement.name || !commonizer.commonizeWith(nextElement)) {
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.core
|
||||
|
||||
abstract class NullableWrappedCommonizer<T : Any, R : Any, WT, WR>(
|
||||
abstract class AbstractNullableCommonizer<T : Any, R : Any, WT, WR>(
|
||||
private val subject: String,
|
||||
private val wrappedCommonizerFactory: () -> Commonizer<WT, WR>,
|
||||
private val extractor: (T) -> WT,
|
||||
+5
-8
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonFunction
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiver.Companion.toReceiverNoAnnotations
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Function
|
||||
|
||||
class FunctionCommonizer : CallableMemberCommonizer<SimpleFunctionDescriptor, Function>() {
|
||||
class FunctionCommonizer : AbstractCallableMemberCommonizer<SimpleFunctionDescriptor, Function>() {
|
||||
private val modifiers = FunctionModifiersCommonizer.default()
|
||||
private val valueParameters = ValueParameterListCommonizer.default()
|
||||
|
||||
@@ -24,16 +24,13 @@ class FunctionCommonizer : CallableMemberCommonizer<SimpleFunctionDescriptor, Fu
|
||||
extensionReceiver = extensionReceiver.result?.toReceiverNoAnnotations(),
|
||||
returnType = returnType.result,
|
||||
modifiers = modifiers.result,
|
||||
valueParameters = valueParameters.result
|
||||
valueParameters = valueParameters.result,
|
||||
typeParameters = typeParameters.result
|
||||
)
|
||||
}
|
||||
|
||||
override fun canBeCommonized(next: SimpleFunctionDescriptor) = true
|
||||
|
||||
override fun commonizeSpecifics(next: SimpleFunctionDescriptor): Boolean {
|
||||
|
||||
// TODO: type parameters (for functions???)
|
||||
|
||||
return modifiers.commonizeWith(next) && valueParameters.commonizeWith(next.valueParameters)
|
||||
}
|
||||
override fun commonizeSpecifics(next: SimpleFunctionDescriptor) =
|
||||
modifiers.commonizeWith(next) && valueParameters.commonizeWith(next.valueParameters)
|
||||
}
|
||||
|
||||
+3
-5
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonProperty
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiver.Companion.toReceiverNoAnnotations
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Property
|
||||
|
||||
class PropertyCommonizer : CallableMemberCommonizer<PropertyDescriptor, Property>() {
|
||||
class PropertyCommonizer : AbstractCallableMemberCommonizer<PropertyDescriptor, Property>() {
|
||||
private val setter = PropertySetterCommonizer.default()
|
||||
private var isExternal = true
|
||||
|
||||
@@ -24,7 +24,8 @@ class PropertyCommonizer : CallableMemberCommonizer<PropertyDescriptor, Property
|
||||
isExternal = isExternal,
|
||||
extensionReceiver = extensionReceiver.result?.toReceiverNoAnnotations(),
|
||||
returnType = returnType.result,
|
||||
setter = setter.result
|
||||
setter = setter.result,
|
||||
typeParameters = typeParameters.result
|
||||
)
|
||||
}
|
||||
|
||||
@@ -35,9 +36,6 @@ class PropertyCommonizer : CallableMemberCommonizer<PropertyDescriptor, Property
|
||||
}
|
||||
|
||||
override fun commonizeSpecifics(next: PropertyDescriptor): Boolean {
|
||||
|
||||
// TODO: type parameters (for properties???)
|
||||
|
||||
isExternal = isExternal && next.isExternal
|
||||
|
||||
return setter.commonizeWith(next.setter)
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ interface PropertySetterCommonizer : Commonizer<PropertySetterDescriptor?, Sette
|
||||
|
||||
private class DefaultPropertySetterCommonizer :
|
||||
PropertySetterCommonizer,
|
||||
NullableWrappedCommonizer<PropertySetterDescriptor, Setter, Visibility, Visibility>(
|
||||
AbstractNullableCommonizer<PropertySetterDescriptor, Setter, Visibility, Visibility>(
|
||||
subject = "Property",
|
||||
wrappedCommonizerFactory = { VisibilityCommonizer.equalizing() },
|
||||
extractor = { it.visibility },
|
||||
|
||||
+22
-9
@@ -82,19 +82,26 @@ private fun areAbbreviatedTypesEqual(a: SimpleType, aExpanded: SimpleType, b: Si
|
||||
val aDescriptor = requireNotNull(a.constructor.declarationDescriptor, a::nonNullDescriptorExpectedErrorMessage)
|
||||
val bDescriptor = requireNotNull(b.constructor.declarationDescriptor, b::nonNullDescriptorExpectedErrorMessage)
|
||||
|
||||
val aFqName = aDescriptor.fqNameSafe
|
||||
val bFqName = bDescriptor.fqNameSafe
|
||||
val isUnderStandardKotlinPackages = if (
|
||||
aDescriptor is ClassifierDescriptorWithTypeParameters
|
||||
&& bDescriptor is ClassifierDescriptorWithTypeParameters
|
||||
) {
|
||||
// N.B. only for descriptors that represent classes or type aliases, but not type parameters:
|
||||
|
||||
if (aFqName.isUnderStandardKotlinPackages || bFqName.isUnderStandardKotlinPackages) {
|
||||
// make sure that FQ names of abbreviated types (e.g. representing type aliases) are equal
|
||||
return aFqName == bFqName
|
||||
val aFqName = aDescriptor.fqNameSafe
|
||||
val bFqName = bDescriptor.fqNameSafe
|
||||
|
||||
aFqName.isUnderStandardKotlinPackages
|
||||
// make sure that FQ names of abbreviated types (e.g. representing type aliases) are equal
|
||||
&& aFqName == bFqName
|
||||
// if classes are from the standard Kotlin packages, compare them only by type constructors
|
||||
// effectively, this includes 1) comparison of FQ names and 2) number of type constructor parameters
|
||||
// see org.jetbrains.kotlin.types.AbstractClassTypeConstructor.equals() for details
|
||||
&& aExpanded.constructor == bExpandedType.constructor
|
||||
}
|
||||
} else false
|
||||
|
||||
val descriptorsCanBeCommonized = when (aDescriptor) {
|
||||
val descriptorsCanBeCommonized = isUnderStandardKotlinPackages || when (aDescriptor) {
|
||||
is TypeParameterDescriptor -> (bDescriptor is TypeParameterDescriptor) && canBeCommonized(aDescriptor, bDescriptor)
|
||||
is TypeAliasDescriptor -> (bDescriptor is TypeAliasDescriptor) && canBeCommonized(aDescriptor, bDescriptor)
|
||||
is ClassDescriptor -> (bDescriptor is ClassDescriptor) && canBeCommonized(aDescriptor, bDescriptor)
|
||||
else -> false
|
||||
@@ -103,8 +110,8 @@ private fun areAbbreviatedTypesEqual(a: SimpleType, aExpanded: SimpleType, b: Si
|
||||
if (!descriptorsCanBeCommonized)
|
||||
return false
|
||||
|
||||
if (a.arguments === b.arguments)
|
||||
return true
|
||||
if (a.arguments.size != b.arguments.size)
|
||||
return false
|
||||
|
||||
for (i in 0 until a.arguments.size) {
|
||||
val aArg = a.arguments[i]
|
||||
@@ -162,6 +169,12 @@ private fun canBeCommonized(a: TypeAliasDescriptor, b: TypeAliasDescriptor): Boo
|
||||
return areTypesEqual(aUnderlyingType, bUnderlyingType)
|
||||
}
|
||||
|
||||
private fun canBeCommonized(a: TypeParameterDescriptor, b: TypeParameterDescriptor): Boolean {
|
||||
// N.B. real type parameter commonization is performed in TypeParameterCommonizer,
|
||||
// here it is enough to check FQ names
|
||||
return areFqNamesEqual(a, b)
|
||||
}
|
||||
|
||||
private fun <T : ClassifierDescriptor> areFqNamesEqual(d1: T, d2: T): Boolean {
|
||||
val p1 = d1.parentsWithSelf.iterator()
|
||||
val p2 = d2.parentsWithSelf.iterator()
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.core
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonTypeParameter
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeParameter
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
interface TypeParameterCommonizer : Commonizer<TypeParameterDescriptor, TypeParameter> {
|
||||
companion object {
|
||||
fun default(): TypeParameterCommonizer = DefaultTypeParameterCommonizer()
|
||||
}
|
||||
}
|
||||
|
||||
private class DefaultTypeParameterCommonizer : TypeParameterCommonizer {
|
||||
private enum class State {
|
||||
EMPTY,
|
||||
ERROR,
|
||||
IN_PROGRESS
|
||||
}
|
||||
|
||||
private var state = State.EMPTY
|
||||
private lateinit var name: Name
|
||||
private var isReified = false
|
||||
private lateinit var variance: Variance
|
||||
private val upperBounds = TypeParameterUpperBoundsCommonizer()
|
||||
|
||||
override val result: TypeParameter
|
||||
get() = when (state) {
|
||||
State.EMPTY, State.ERROR -> error("Can't commonize type parameter")
|
||||
State.IN_PROGRESS -> CommonTypeParameter(
|
||||
name = name,
|
||||
isReified = isReified,
|
||||
variance = variance,
|
||||
upperBounds = upperBounds.result
|
||||
)
|
||||
}
|
||||
|
||||
override fun commonizeWith(next: TypeParameterDescriptor): Boolean {
|
||||
state = when (state) {
|
||||
State.ERROR -> State.ERROR
|
||||
State.EMPTY -> {
|
||||
name = next.name
|
||||
isReified = next.isReified
|
||||
variance = next.variance
|
||||
|
||||
if (!upperBounds.commonizeWith(next.upperBounds)) State.ERROR else State.IN_PROGRESS
|
||||
}
|
||||
State.IN_PROGRESS -> {
|
||||
if (isReified != next.isReified
|
||||
|| variance != next.variance
|
||||
|| !upperBounds.commonizeWith(next.upperBounds)
|
||||
) State.ERROR else State.IN_PROGRESS
|
||||
}
|
||||
}
|
||||
|
||||
return state != State.ERROR
|
||||
}
|
||||
}
|
||||
|
||||
private class TypeParameterUpperBoundsCommonizer : AbstractListCommonizer<KotlinType, UnwrappedType>(
|
||||
subject = "type parameter upper bounds",
|
||||
singleElementCommonizerFactory = { TypeCommonizer.default() }
|
||||
)
|
||||
|
||||
interface TypeParameterListCommonizer : Commonizer<List<TypeParameterDescriptor>, List<TypeParameter>> {
|
||||
companion object {
|
||||
fun default(): TypeParameterListCommonizer = DefaultTypeParameterListCommonizer()
|
||||
}
|
||||
}
|
||||
|
||||
private class DefaultTypeParameterListCommonizer :
|
||||
TypeParameterListCommonizer,
|
||||
AbstractNamedListCommonizer<TypeParameterDescriptor, TypeParameter>(
|
||||
subject = "type parameters",
|
||||
singleElementCommonizerFactory = { TypeParameterCommonizer.default() }
|
||||
)
|
||||
+2
-2
@@ -82,7 +82,7 @@ interface ValueParameterListCommonizer : Commonizer<List<ValueParameterDescripto
|
||||
|
||||
private class DefaultValueParameterListCommonizer :
|
||||
ValueParameterListCommonizer,
|
||||
NamedListWrappedCommonizer<ValueParameterDescriptor, ValueParameter>(
|
||||
AbstractNamedListCommonizer<ValueParameterDescriptor, ValueParameter>(
|
||||
subject = "value parameters",
|
||||
wrappedCommonizerFactory = { ValueParameterCommonizer.default() }
|
||||
singleElementCommonizerFactory = { ValueParameterCommonizer.default() }
|
||||
)
|
||||
|
||||
+2
-1
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiv
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
|
||||
interface CallableMember {
|
||||
interface CallableMember : DeclarationWithTypeParameters {
|
||||
val annotations: Annotations
|
||||
val name: Name
|
||||
val modality: Modality
|
||||
@@ -39,6 +39,7 @@ abstract class TargetCallableMember<T : CallableMemberDescriptor>(protected val
|
||||
final override val extensionReceiver: ExtensionReceiver? get() = descriptor.extensionReceiverParameter?.toReceiver()
|
||||
final override val returnType: UnwrappedType get() = descriptor.returnType!!.unwrap()
|
||||
final override val kind: CallableMemberDescriptor.Kind get() = descriptor.kind
|
||||
final override val typeParameters: List<TypeParameter> get() = descriptor.typeParameters.map(::TargetTypeParameter)
|
||||
}
|
||||
|
||||
data class ExtensionReceiver(
|
||||
|
||||
+2
-1
@@ -33,7 +33,8 @@ data class CommonFunction(
|
||||
override val extensionReceiver: ExtensionReceiver?,
|
||||
override val returnType: UnwrappedType,
|
||||
private val modifiers: FunctionModifiers,
|
||||
override val valueParameters: List<ValueParameter>
|
||||
override val valueParameters: List<ValueParameter>,
|
||||
override val typeParameters: List<TypeParameter>
|
||||
) : CommonCallableMember(), Function, FunctionModifiers by modifiers
|
||||
|
||||
class TargetFunction(descriptor: SimpleFunctionDescriptor) : TargetCallableMember<SimpleFunctionDescriptor>(descriptor), Function {
|
||||
|
||||
+2
-1
@@ -32,7 +32,8 @@ data class CommonProperty(
|
||||
override val isExternal: Boolean,
|
||||
override val extensionReceiver: ExtensionReceiver?,
|
||||
override val returnType: UnwrappedType,
|
||||
override val setter: Setter?
|
||||
override val setter: Setter?,
|
||||
override val typeParameters: List<TypeParameter>
|
||||
) : CommonCallableMember(), Property {
|
||||
override val isVar: Boolean get() = setter != null
|
||||
override val lateInit: Boolean get() = false
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.mergedtree.ir
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
interface TypeParameter {
|
||||
val annotations: Annotations
|
||||
val name: Name
|
||||
val isReified: Boolean
|
||||
val variance: Variance
|
||||
val upperBounds: List<UnwrappedType>
|
||||
}
|
||||
|
||||
interface DeclarationWithTypeParameters : Declaration {
|
||||
val typeParameters: List<TypeParameter>
|
||||
}
|
||||
|
||||
data class CommonTypeParameter(
|
||||
override val name: Name,
|
||||
override val isReified: Boolean,
|
||||
override val variance: Variance,
|
||||
override val upperBounds: List<UnwrappedType>
|
||||
) : TypeParameter {
|
||||
override val annotations: Annotations get() = Annotations.EMPTY
|
||||
}
|
||||
|
||||
data class TargetTypeParameter(private val descriptor: TypeParameterDescriptor) : TypeParameter {
|
||||
override val annotations: Annotations get() = descriptor.annotations
|
||||
override val name: Name get() = descriptor.name
|
||||
override val isReified: Boolean get() = descriptor.isReified
|
||||
override val variance: Variance get() = descriptor.variance
|
||||
override val upperBounds: List<UnwrappedType> get() = descriptor.upperBounds.map { it.unwrap() }
|
||||
}
|
||||
+7
-7
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroupMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.fqName
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.fqNameWithTypeParameters
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
@@ -49,11 +49,11 @@ internal fun mergePackages(
|
||||
|
||||
internal data class PropertyKey(
|
||||
val name: Name,
|
||||
val extensionReceiverParameterFqName: FqName?
|
||||
val extensionReceiverParameter: String?
|
||||
) {
|
||||
constructor(property: PropertyDescriptor) : this(
|
||||
property.name,
|
||||
property.extensionReceiverParameter?.type?.fqName
|
||||
property.extensionReceiverParameter?.type?.fqNameWithTypeParameters
|
||||
)
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ internal fun MemberScope.collectProperties(collector: (PropertyKey, PropertyDesc
|
||||
|
||||
internal data class FunctionKey(
|
||||
val name: Name,
|
||||
val valueParameters: List<Pair<Name, FqName>>,
|
||||
val extensionReceiverParameterFqName: FqName?
|
||||
val valueParameters: List<Pair<Name, String>>,
|
||||
val extensionReceiverParameter: String?
|
||||
) {
|
||||
constructor(function: SimpleFunctionDescriptor) : this(
|
||||
function.name,
|
||||
function.valueParameters.map { it.name to it.type.fqName },
|
||||
function.extensionReceiverParameter?.type?.fqName
|
||||
function.valueParameters.map { it.name to it.type.fqNameWithTypeParameters },
|
||||
function.extensionReceiverParameter?.type?.fqNameWithTypeParameters
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.descriptors.commonizer
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||
|
||||
internal fun <T> Sequence<T>.toList(expectedCapacity: Int): List<T> {
|
||||
@@ -21,4 +22,30 @@ internal inline fun <reified T> Iterable<T?>.firstNonNull() = firstIsInstance<T>
|
||||
internal val KotlinType.fqName: FqName
|
||||
get() = constructor.declarationDescriptor!!.fqNameSafe
|
||||
|
||||
internal val KotlinType.fqNameWithTypeParameters: String
|
||||
get() = buildString { buildFqNameWithTypeParameters(this@fqNameWithTypeParameters) }
|
||||
|
||||
private fun StringBuilder.buildFqNameWithTypeParameters(type: KotlinType) {
|
||||
append(type.fqName)
|
||||
|
||||
val arguments = type.arguments
|
||||
if (arguments.isNotEmpty()) {
|
||||
append("<")
|
||||
arguments.forEachIndexed { index, argument ->
|
||||
if (index > 0)
|
||||
append(",")
|
||||
|
||||
if (argument.isStarProjection)
|
||||
append("*")
|
||||
else {
|
||||
val variance = argument.projectionKind
|
||||
if (variance != Variance.INVARIANT)
|
||||
append(variance).append(" ")
|
||||
buildFqNameWithTypeParameters(argument.type)
|
||||
}
|
||||
}
|
||||
append(">")
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Any?.isNull() = this == null
|
||||
|
||||
+6
@@ -13,3 +13,9 @@ expect fun Short.intFunction(): Int
|
||||
expect fun Long.intFunction(): Int
|
||||
expect fun String.intFunction(): Int
|
||||
expect fun Planet.intFunction(): Int
|
||||
|
||||
expect val <T> T.propertyWithTypeParameter1: Int
|
||||
expect val <T : Any?> T.propertyWithTypeParameter2: Int
|
||||
expect val <T : CharSequence> T.propertyWithTypeParameter4: Int
|
||||
|
||||
expect fun <T> T.functionWithTypeParameter1()
|
||||
|
||||
+15
@@ -19,3 +19,18 @@ val mismatchedProperty2 get() = 42
|
||||
|
||||
fun String.mismatchedFunction1() = 42
|
||||
fun mismatchedFunction2() = 42
|
||||
|
||||
actual val <T> T.propertyWithTypeParameter1 get() = 42
|
||||
actual val <T> T.propertyWithTypeParameter2 get() = 42
|
||||
val <T> T.propertyWithTypeParameter3 get() = 42
|
||||
actual val <T : CharSequence> T.propertyWithTypeParameter4 get() = length
|
||||
val <T : CharSequence> T.propertyWithTypeParameter5 get() = length
|
||||
val <T : CharSequence> T.propertyWithTypeParameter6 get() = length
|
||||
val <T : CharSequence> T.propertyWithTypeParameter7 get() = length
|
||||
val <T> T.propertyWithTypeParameter8 get() = 42
|
||||
val <T> T.propertyWithTypeParameter9 get() = 42
|
||||
|
||||
actual fun <T> T.functionWithTypeParameter1() {}
|
||||
fun <T> T.functionWithTypeParameter2() {}
|
||||
fun <T> T.functionWithTypeParameter3() {}
|
||||
fun <T> T.functionWithTypeParameter4() {}
|
||||
|
||||
+15
@@ -19,3 +19,18 @@ val Double.mismatchedProperty2 get() = 42
|
||||
|
||||
fun mismatchedFunction1() = 42
|
||||
fun Double.mismatchedFunction2() = 42
|
||||
|
||||
actual val <T> T.propertyWithTypeParameter1 get() = 42
|
||||
actual val <T : Any?> T.propertyWithTypeParameter2 get() = 42
|
||||
val <T : Any> T.propertyWithTypeParameter3 get() = 42
|
||||
actual val <T : CharSequence> T.propertyWithTypeParameter4 get() = length
|
||||
val <T : Appendable> T.propertyWithTypeParameter5 get() = length
|
||||
val <T : String> T.propertyWithTypeParameter6 get() = length
|
||||
val String.propertyWithTypeParameter7 get() = length
|
||||
val <Q> Q.propertyWithTypeParameter8 get() = 42
|
||||
val <T, Q> T.propertyWithTypeParameter9 get() = 42
|
||||
|
||||
actual fun <T> T.functionWithTypeParameter1() {}
|
||||
fun <Q> Q.functionWithTypeParameter2() {}
|
||||
fun <T, Q> T.functionWithTypeParameter3() {}
|
||||
fun <T, Q> Q.functionWithTypeParameter4() {}
|
||||
|
||||
konan/commonizer/testData/callableMemberCommonization/extensionReceivers/original/js/package_root.kt
Vendored
+15
@@ -19,3 +19,18 @@ val mismatchedProperty2 get() = 42
|
||||
|
||||
fun String.mismatchedFunction1() = 42
|
||||
fun mismatchedFunction2() = 42
|
||||
|
||||
val <T> T.propertyWithTypeParameter1 get() = 42
|
||||
val <T> T.propertyWithTypeParameter2 get() = 42
|
||||
val <T> T.propertyWithTypeParameter3 get() = 42
|
||||
val <T : CharSequence> T.propertyWithTypeParameter4 get() = length
|
||||
val <T : CharSequence> T.propertyWithTypeParameter5 get() = length
|
||||
val <T : CharSequence> T.propertyWithTypeParameter6 get() = length
|
||||
val <T : CharSequence> T.propertyWithTypeParameter7 get() = length
|
||||
val <T> T.propertyWithTypeParameter8 get() = 42
|
||||
val <T> T.propertyWithTypeParameter9 get() = 42
|
||||
|
||||
fun <T> T.functionWithTypeParameter1() {}
|
||||
fun <T> T.functionWithTypeParameter2() {}
|
||||
fun <T> T.functionWithTypeParameter3() {}
|
||||
fun <T> T.functionWithTypeParameter4() {}
|
||||
|
||||
+15
@@ -19,3 +19,18 @@ val Double.mismatchedProperty2 get() = 42
|
||||
|
||||
fun mismatchedFunction1() = 42
|
||||
fun Double.mismatchedFunction2() = 42
|
||||
|
||||
val <T> T.propertyWithTypeParameter1 get() = 42
|
||||
val <T : Any?> T.propertyWithTypeParameter2 get() = 42
|
||||
val <T : Any> T.propertyWithTypeParameter3 get() = 42
|
||||
val <T : CharSequence> T.propertyWithTypeParameter4 get() = length
|
||||
val <T : Appendable> T.propertyWithTypeParameter5 get() = length
|
||||
val <T : String> T.propertyWithTypeParameter6 get() = length
|
||||
val String.propertyWithTypeParameter7 get() = length
|
||||
val <Q> Q.propertyWithTypeParameter8 get() = 42
|
||||
val <T, Q> T.propertyWithTypeParameter9 get() = 42
|
||||
|
||||
fun <T> T.functionWithTypeParameter1() {}
|
||||
fun <Q> Q.functionWithTypeParameter2() {}
|
||||
fun <T, Q> T.functionWithTypeParameter3() {}
|
||||
fun <T, Q> Q.functionWithTypeParameter4() {}
|
||||
|
||||
Vendored
+16
@@ -19,3 +19,19 @@ expect fun function2(): String
|
||||
expect fun function3(): Planet
|
||||
expect fun function6(): Planet
|
||||
expect fun function7(): C
|
||||
|
||||
class Box<T>(val value: T)
|
||||
class Fox
|
||||
|
||||
expect fun functionWithTypeParametersInReturnType1(): Array<Int>
|
||||
expect fun functionWithTypeParametersInReturnType3(): Array<String>
|
||||
expect fun functionWithTypeParametersInReturnType4(): List<Int>
|
||||
expect fun functionWithTypeParametersInReturnType6(): List<String>
|
||||
expect fun functionWithTypeParametersInReturnType7(): Box<Int>
|
||||
expect fun functionWithTypeParametersInReturnType9(): Box<String>
|
||||
expect fun functionWithTypeParametersInReturnType10(): Box<Planet>
|
||||
expect fun functionWithTypeParametersInReturnType12(): Box<Fox>
|
||||
|
||||
expect fun <T> functionWithUnsubstitutedTypeParametersInReturnType1(): T
|
||||
expect fun <T> functionWithUnsubstitutedTypeParametersInReturnType2(): T
|
||||
expect fun <T> functionWithUnsubstitutedTypeParametersInReturnType8(): Box<T>
|
||||
|
||||
Vendored
+26
@@ -36,3 +36,29 @@ fun functionWithMismatchedType2(): Int = 1
|
||||
fun functionWithMismatchedType3(): Int = 1
|
||||
fun functionWithMismatchedType4(): Int = 1
|
||||
fun functionWithMismatchedType5(): Int = 1
|
||||
|
||||
class Box<T>(val value: T)
|
||||
class Fox
|
||||
|
||||
actual fun functionWithTypeParametersInReturnType1() = arrayOf(1)
|
||||
fun functionWithTypeParametersInReturnType2() = arrayOf(1)
|
||||
actual fun functionWithTypeParametersInReturnType3() = arrayOf("hello")
|
||||
actual fun functionWithTypeParametersInReturnType4(): List<Int> = listOf(1)
|
||||
fun functionWithTypeParametersInReturnType5(): List<Int> = listOf(1)
|
||||
actual fun functionWithTypeParametersInReturnType6(): List<String> = listOf("hello")
|
||||
actual fun functionWithTypeParametersInReturnType7() = Box(1)
|
||||
fun functionWithTypeParametersInReturnType8() = Box(1)
|
||||
actual fun functionWithTypeParametersInReturnType9() = Box("hello")
|
||||
actual fun functionWithTypeParametersInReturnType10() = Box(Planet("Earth", 12742))
|
||||
fun functionWithTypeParametersInReturnType11() = Box(Planet("Earth", 12742))
|
||||
actual fun functionWithTypeParametersInReturnType12() = Box(Fox())
|
||||
|
||||
actual fun <T> functionWithUnsubstitutedTypeParametersInReturnType1(): T = TODO()
|
||||
actual fun <T> functionWithUnsubstitutedTypeParametersInReturnType2(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType3(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType4(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType5(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType6(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType7(): T = TODO()
|
||||
actual fun <T> functionWithUnsubstitutedTypeParametersInReturnType8(): Box<T> = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType9(): Box<T> = TODO()
|
||||
|
||||
Vendored
+26
@@ -36,3 +36,29 @@ fun functionWithMismatchedType2(): Short = 1
|
||||
fun functionWithMismatchedType3(): Number = 1
|
||||
fun functionWithMismatchedType4(): Comparable<Int> = 1
|
||||
fun functionWithMismatchedType5(): String = 1.toString()
|
||||
|
||||
class Box<T>(val value: T)
|
||||
class Fox
|
||||
|
||||
actual fun functionWithTypeParametersInReturnType1() = arrayOf(1)
|
||||
fun functionWithTypeParametersInReturnType2() = arrayOf("hello")
|
||||
actual fun functionWithTypeParametersInReturnType3() = arrayOf("hello")
|
||||
actual fun functionWithTypeParametersInReturnType4(): List<Int> = listOf(1)
|
||||
fun functionWithTypeParametersInReturnType5(): List<String> = listOf("hello")
|
||||
actual fun functionWithTypeParametersInReturnType6(): List<String> = listOf("hello")
|
||||
actual fun functionWithTypeParametersInReturnType7() = Box(1)
|
||||
fun functionWithTypeParametersInReturnType8() = Box("hello")
|
||||
actual fun functionWithTypeParametersInReturnType9() = Box("hello")
|
||||
actual fun functionWithTypeParametersInReturnType10() = Box(Planet("Earth", 12742))
|
||||
fun functionWithTypeParametersInReturnType11() = Box(Fox())
|
||||
actual fun functionWithTypeParametersInReturnType12() = Box(Fox())
|
||||
|
||||
actual fun <T> functionWithUnsubstitutedTypeParametersInReturnType1(): T = TODO()
|
||||
actual fun <T : Any?> functionWithUnsubstitutedTypeParametersInReturnType2(): T = TODO()
|
||||
fun <T : Any> functionWithUnsubstitutedTypeParametersInReturnType3(): T = TODO()
|
||||
fun <Q> functionWithUnsubstitutedTypeParametersInReturnType4(): Q = TODO()
|
||||
fun <T, Q> functionWithUnsubstitutedTypeParametersInReturnType5(): T = TODO()
|
||||
fun <T, Q> functionWithUnsubstitutedTypeParametersInReturnType6(): Q = TODO()
|
||||
fun functionWithUnsubstitutedTypeParametersInReturnType7(): String = TODO()
|
||||
actual fun <T> functionWithUnsubstitutedTypeParametersInReturnType8(): Box<T> = TODO()
|
||||
fun functionWithUnsubstitutedTypeParametersInReturnType9(): Box<String> = TODO()
|
||||
|
||||
Vendored
+26
@@ -38,3 +38,29 @@ fun functionWithMismatchedType2(): Int = 1
|
||||
fun functionWithMismatchedType3(): Int = 1
|
||||
fun functionWithMismatchedType4(): Int = 1
|
||||
fun functionWithMismatchedType5(): Int = 1
|
||||
|
||||
class Box<T>(val value: T)
|
||||
class Fox
|
||||
|
||||
fun functionWithTypeParametersInReturnType1() = arrayOf(1)
|
||||
fun functionWithTypeParametersInReturnType2() = arrayOf(1)
|
||||
fun functionWithTypeParametersInReturnType3() = arrayOf("hello")
|
||||
fun functionWithTypeParametersInReturnType4(): List<Int> = listOf(1)
|
||||
fun functionWithTypeParametersInReturnType5(): List<Int> = listOf(1)
|
||||
fun functionWithTypeParametersInReturnType6(): List<String> = listOf("hello")
|
||||
fun functionWithTypeParametersInReturnType7() = Box(1)
|
||||
fun functionWithTypeParametersInReturnType8() = Box(1)
|
||||
fun functionWithTypeParametersInReturnType9() = Box("hello")
|
||||
fun functionWithTypeParametersInReturnType10() = Box(Planet("Earth", 12742))
|
||||
fun functionWithTypeParametersInReturnType11() = Box(Planet("Earth", 12742))
|
||||
fun functionWithTypeParametersInReturnType12() = Box(Fox())
|
||||
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType1(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType2(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType3(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType4(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType5(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType6(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType7(): T = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType8(): Box<T> = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType9(): Box<T> = TODO()
|
||||
|
||||
Vendored
+26
@@ -38,3 +38,29 @@ fun functionWithMismatchedType2(): Short = 1
|
||||
fun functionWithMismatchedType3(): Number = 1
|
||||
fun functionWithMismatchedType4(): Comparable<Int> = 1
|
||||
fun functionWithMismatchedType5(): String = 1.toString()
|
||||
|
||||
class Box<T>(val value: T)
|
||||
class Fox
|
||||
|
||||
fun functionWithTypeParametersInReturnType1() = arrayOf(1)
|
||||
fun functionWithTypeParametersInReturnType2() = arrayOf("hello")
|
||||
fun functionWithTypeParametersInReturnType3() = arrayOf("hello")
|
||||
fun functionWithTypeParametersInReturnType4(): List<Int> = listOf(1)
|
||||
fun functionWithTypeParametersInReturnType5(): List<String> = listOf("hello")
|
||||
fun functionWithTypeParametersInReturnType6(): List<String> = listOf("hello")
|
||||
fun functionWithTypeParametersInReturnType7() = Box(1)
|
||||
fun functionWithTypeParametersInReturnType8() = Box("hello")
|
||||
fun functionWithTypeParametersInReturnType9() = Box("hello")
|
||||
fun functionWithTypeParametersInReturnType10() = Box(Planet("Earth", 12742))
|
||||
fun functionWithTypeParametersInReturnType11() = Box(Fox())
|
||||
fun functionWithTypeParametersInReturnType12() = Box(Fox())
|
||||
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType1(): T = TODO()
|
||||
fun <T : Any?> functionWithUnsubstitutedTypeParametersInReturnType2(): T = TODO()
|
||||
fun <T : Any> functionWithUnsubstitutedTypeParametersInReturnType3(): T = TODO()
|
||||
fun <Q> functionWithUnsubstitutedTypeParametersInReturnType4(): Q = TODO()
|
||||
fun <T, Q> functionWithUnsubstitutedTypeParametersInReturnType5(): T = TODO()
|
||||
fun <T, Q> functionWithUnsubstitutedTypeParametersInReturnType6(): Q = TODO()
|
||||
fun functionWithUnsubstitutedTypeParametersInReturnType7(): String = TODO()
|
||||
fun <T> functionWithUnsubstitutedTypeParametersInReturnType8(): Box<T> = TODO()
|
||||
fun functionWithUnsubstitutedTypeParametersInReturnType9(): Box<String> = TODO()
|
||||
|
||||
Vendored
+5
@@ -11,3 +11,8 @@ expect inline fun inlineFunction5(noinline lazyMessage: () -> String)
|
||||
|
||||
expect fun functionWithVararg1(vararg numbers: Int)
|
||||
expect fun functionWithVararg5(numbers: Array<out Int>)
|
||||
expect fun functionWithVararg6(vararg names: String)
|
||||
expect fun functionWithVararg10(names: Array<out String>)
|
||||
|
||||
expect fun <T> functionWithTypeParameters1(p1: T, p2: String)
|
||||
expect fun <Q, R> functionWithTypeParameters4(p1: Q, p2: R)
|
||||
|
||||
Vendored
+13
-1
@@ -24,5 +24,17 @@ actual inline fun inlineFunction5(noinline lazyMessage: () -> String) {}
|
||||
actual fun functionWithVararg1(vararg numbers: Int) {}
|
||||
fun functionWithVararg2(vararg numbers: Int) {}
|
||||
fun functionWithVararg3(vararg numbers: Int) {}
|
||||
//fun functionWithVararg4(numbers: Array<Int>) {}
|
||||
fun functionWithVararg4(numbers: Array<Int>) {}
|
||||
actual fun functionWithVararg5(numbers: Array<out Int>) {}
|
||||
actual fun functionWithVararg6(vararg names: String) {}
|
||||
fun functionWithVararg7(vararg names: String) {}
|
||||
fun functionWithVararg8(vararg names: String) {}
|
||||
fun functionWithVararg9(names: Array<String>) {}
|
||||
actual fun functionWithVararg10(names: Array<out String>) {}
|
||||
|
||||
actual fun <T> functionWithTypeParameters1(p1: T, p2: String) {}
|
||||
fun <T> functionWithTypeParameters2(p1: T, p2: String) {}
|
||||
fun <T> functionWithTypeParameters3(p1: T, p2: String) {}
|
||||
actual fun <Q, R> functionWithTypeParameters4(p1: Q, p2: R) {}
|
||||
fun <Q, R> functionWithTypeParameters5(p1: Q, p2: R) {}
|
||||
fun <Q, R> functionWithTypeParameters6(p1: Q, p2: R) {}
|
||||
|
||||
Vendored
+13
-1
@@ -24,5 +24,17 @@ actual inline fun inlineFunction5(noinline lazyMessage: () -> String) {}
|
||||
actual fun functionWithVararg1(vararg numbers: Int) {}
|
||||
fun functionWithVararg2(numbers: Array<Int>) {}
|
||||
fun functionWithVararg3(numbers: Array<out Int>) {}
|
||||
//fun functionWithVararg4(numbers: Array<out Int>) {}
|
||||
fun functionWithVararg4(numbers: Array<out Int>) {}
|
||||
actual fun functionWithVararg5(numbers: Array<out Int>) {}
|
||||
actual fun functionWithVararg6(vararg names: String) {}
|
||||
fun functionWithVararg7(names: Array<String>) {}
|
||||
fun functionWithVararg8(names: Array<out String>) {}
|
||||
fun functionWithVararg9(names: Array<out String>) {}
|
||||
actual fun functionWithVararg10(names: Array<out String>) {}
|
||||
|
||||
actual fun <T> functionWithTypeParameters1(p1: T, p2: String) {}
|
||||
fun <T> functionWithTypeParameters2(p1: String, p2: String) {}
|
||||
fun <T> functionWithTypeParameters2(p1: String, p2: T) {}
|
||||
actual fun <Q, R> functionWithTypeParameters4(p1: Q, p2: R) {}
|
||||
fun <R, Q> functionWithTypeParameters5(p1: Q, p2: R) {}
|
||||
fun <Q, R> functionWithTypeParameters6(p1: R, p2: Q) {}
|
||||
|
||||
Vendored
+13
-1
@@ -24,5 +24,17 @@ inline fun inlineFunction5(noinline lazyMessage: () -> String) {}
|
||||
fun functionWithVararg1(vararg numbers: Int) {}
|
||||
fun functionWithVararg2(vararg numbers: Int) {}
|
||||
fun functionWithVararg3(vararg numbers: Int) {}
|
||||
//fun functionWithVararg4(numbers: Array<Int>) {}
|
||||
fun functionWithVararg4(numbers: Array<Int>) {}
|
||||
fun functionWithVararg5(numbers: Array<out Int>) {}
|
||||
fun functionWithVararg6(vararg names: String) {}
|
||||
fun functionWithVararg7(vararg names: String) {}
|
||||
fun functionWithVararg8(vararg names: String) {}
|
||||
fun functionWithVararg9(names: Array<String>) {}
|
||||
fun functionWithVararg10(names: Array<out String>) {}
|
||||
|
||||
fun <T> functionWithTypeParameters1(p1: T, p2: String) {}
|
||||
fun <T> functionWithTypeParameters2(p1: T, p2: String) {}
|
||||
fun <T> functionWithTypeParameters3(p1: T, p2: String) {}
|
||||
fun <Q, R> functionWithTypeParameters4(p1: Q, p2: R) {}
|
||||
fun <Q, R> functionWithTypeParameters5(p1: Q, p2: R) {}
|
||||
fun <Q, R> functionWithTypeParameters6(p1: Q, p2: R) {}
|
||||
|
||||
Vendored
+13
-1
@@ -24,5 +24,17 @@ inline fun inlineFunction5(noinline lazyMessage: () -> String) {}
|
||||
fun functionWithVararg1(vararg numbers: Int) {}
|
||||
fun functionWithVararg2(numbers: Array<Int>) {}
|
||||
fun functionWithVararg3(numbers: Array<out Int>) {}
|
||||
//fun functionWithVararg4(numbers: Array<out Int>) {}
|
||||
fun functionWithVararg4(numbers: Array<out Int>) {}
|
||||
fun functionWithVararg5(numbers: Array<out Int>) {}
|
||||
fun functionWithVararg6(vararg names: String) {}
|
||||
fun functionWithVararg7(names: Array<String>) {}
|
||||
fun functionWithVararg8(names: Array<out String>) {}
|
||||
fun functionWithVararg9(names: Array<out String>) {}
|
||||
fun functionWithVararg10(names: Array<out String>) {}
|
||||
|
||||
fun <T> functionWithTypeParameters1(p1: T, p2: String) {}
|
||||
fun <T> functionWithTypeParameters2(p1: String, p2: String) {}
|
||||
fun <T> functionWithTypeParameters2(p1: String, p2: T) {}
|
||||
fun <Q, R> functionWithTypeParameters4(p1: Q, p2: R) {}
|
||||
fun <R, Q> functionWithTypeParameters5(p1: Q, p2: R) {}
|
||||
fun <Q, R> functionWithTypeParameters6(p1: R, p2: Q) {}
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
expect var propertyWithoutBackingField: Double
|
||||
expect val propertyWithBackingField: Double
|
||||
expect val propertyWithDelegateField: Int
|
||||
expect val String.propertyWithExtensionReceiver: Int
|
||||
expect val <T : CharSequence> T.propertyWithExtensionReceiver: Int
|
||||
|
||||
expect fun function1(text: String): String
|
||||
expect fun String.function2(): String
|
||||
expect fun <Q : Number> Q.function2(): Q
|
||||
|
||||
+2
-2
@@ -17,11 +17,11 @@ actual val propertyWithBackingField = 3.14
|
||||
@delegate:Foo("field")
|
||||
actual val propertyWithDelegateField: Int by lazy { 42 }
|
||||
|
||||
actual val @receiver:Foo("receiver") String.propertyWithExtensionReceiver: Int
|
||||
actual val <@Foo("type-parameter") T : CharSequence> @receiver:Foo("receiver") T.propertyWithExtensionReceiver: Int
|
||||
get() = length
|
||||
|
||||
@Foo("function")
|
||||
actual fun function1(@Foo("parameter") text: String) = text
|
||||
|
||||
@Foo("function")
|
||||
actual fun @receiver:Foo("receiver") String.function2() = this
|
||||
actual fun <@Foo("type-parameter") Q : Number> @receiver:Foo("receiver") Q.function2() = this
|
||||
|
||||
+2
-2
@@ -14,11 +14,11 @@ actual val propertyWithBackingField = 3.14
|
||||
@delegate:Bar("field")
|
||||
actual val propertyWithDelegateField: Int by lazy { 42 }
|
||||
|
||||
actual val @receiver:Bar("receiver") String.propertyWithExtensionReceiver: Int
|
||||
actual val <@Bar("type-parameter") T : CharSequence> @receiver:Bar("receiver") T.propertyWithExtensionReceiver: Int
|
||||
get() = length
|
||||
|
||||
@Bar("function")
|
||||
actual fun function1(@Bar("parameter") text: String) = text
|
||||
|
||||
@Bar("function")
|
||||
actual fun @receiver:Foo("receiver") String.function2() = this
|
||||
actual fun <@Bar("type-parameter") Q : Number> @receiver:Bar("receiver") Q.function2() = this
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
import kotlin.annotation.AnnotationTarget.*
|
||||
|
||||
@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, FUNCTION)
|
||||
@Target(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, FIELD, VALUE_PARAMETER, TYPE_PARAMETER, FUNCTION)
|
||||
annotation class Foo(val text: String)
|
||||
|
||||
@Foo("property")
|
||||
@@ -14,11 +14,11 @@ val propertyWithBackingField = 3.14
|
||||
@delegate:Foo("field")
|
||||
val propertyWithDelegateField: Int by lazy { 42 }
|
||||
|
||||
val @receiver:Foo("receiver") String.propertyWithExtensionReceiver: Int
|
||||
val <@Foo("type-parameter") T : CharSequence> @receiver:Foo("receiver") T.propertyWithExtensionReceiver: Int
|
||||
get() = length
|
||||
|
||||
@Foo("function")
|
||||
fun function1(@Foo("parameter") text: String) = text
|
||||
|
||||
@Foo("function")
|
||||
fun @receiver:Foo("receiver") String.function2() = this
|
||||
fun <@Foo("type-parameter") Q : Number> @receiver:Foo("receiver") Q.function2() = this
|
||||
|
||||
+2
-2
@@ -14,11 +14,11 @@ val propertyWithBackingField = 3.14
|
||||
@delegate:Bar("field")
|
||||
val propertyWithDelegateField: Int by lazy { 42 }
|
||||
|
||||
val @receiver:Bar("receiver") String.propertyWithExtensionReceiver: Int
|
||||
val <@Bar("type-parameter") T : CharSequence> @receiver:Bar("receiver") T.propertyWithExtensionReceiver: Int
|
||||
get() = length
|
||||
|
||||
@Bar("function")
|
||||
fun function1(@Bar("parameter") text: String) = text
|
||||
|
||||
@Bar("function")
|
||||
fun @receiver:Foo("receiver") String.function2() = this
|
||||
fun <@Bar("type-parameter") Q : Number> @receiver:Bar("receiver") Q.function2() = this
|
||||
|
||||
@@ -67,7 +67,7 @@ private class ComparingDeclarationsVisitor(
|
||||
override fun visitModuleDeclaration(expected: ModuleDescriptor, context: Context) {
|
||||
val actual = context.getActualAs<ModuleDescriptor>()
|
||||
|
||||
context.assertEquals(expected.name, actual.name, "module names")
|
||||
context.assertFieldsEqual(expected::getName, actual::getName)
|
||||
|
||||
fun collectPackageMemberScopes(module: ModuleDescriptor): Map<FqName, MemberScope> = mutableMapOf<FqName, MemberScope>().also {
|
||||
module.collectNonEmptyPackageMemberScopes { packageFqName, memberScope ->
|
||||
@@ -79,7 +79,7 @@ private class ComparingDeclarationsVisitor(
|
||||
val expectedPackageMemberScopes = collectPackageMemberScopes(expected)
|
||||
val actualPackageMemberScopes = collectPackageMemberScopes(actual)
|
||||
|
||||
context.assertEquals(expectedPackageMemberScopes.keys, actualPackageMemberScopes.keys, "sets of packages")
|
||||
context.assertSetsEqual(expectedPackageMemberScopes.keys, actualPackageMemberScopes.keys, "sets of packages")
|
||||
|
||||
for (packageFqName in expectedPackageMemberScopes.keys) {
|
||||
val expectedMemberScope = expectedPackageMemberScopes.getValue(packageFqName)
|
||||
@@ -100,7 +100,7 @@ private class ComparingDeclarationsVisitor(
|
||||
val expectedProperties = collectProperties(expected)
|
||||
val actualProperties = collectProperties(actual)
|
||||
|
||||
context.assertEquals(expectedProperties.keys, actualProperties.keys, "sets of properties")
|
||||
context.assertSetsEqual(expectedProperties.keys, actualProperties.keys, "sets of properties")
|
||||
|
||||
expectedProperties.forEach { (propertyKey, expectedProperty) ->
|
||||
val actualProperty = actualProperties.getValue(propertyKey)
|
||||
@@ -117,7 +117,7 @@ private class ComparingDeclarationsVisitor(
|
||||
val expectedFunctions = collectFunctions(expected)
|
||||
val actualFunctions = collectFunctions(actual)
|
||||
|
||||
context.assertEquals(expectedFunctions.keys, actualFunctions.keys, "sets of functions")
|
||||
context.assertSetsEqual(expectedFunctions.keys, actualFunctions.keys, "sets of functions")
|
||||
|
||||
expectedFunctions.forEach { (functionKey, expectedFunction) ->
|
||||
val actualFunction = actualFunctions.getValue(functionKey)
|
||||
@@ -153,6 +153,8 @@ private class ComparingDeclarationsVisitor(
|
||||
|
||||
visitReceiverParameterDescriptor(expected.extensionReceiverParameter, context.nextLevel(actual.extensionReceiverParameter))
|
||||
visitReceiverParameterDescriptor(expected.dispatchReceiverParameter, context.nextLevel(actual.dispatchReceiverParameter))
|
||||
|
||||
visitTypeParameters(expected.typeParameters, actual.typeParameters, context.nextLevel("Function type parameters"))
|
||||
}
|
||||
|
||||
fun visitValueParameterDescriptorList(
|
||||
@@ -172,17 +174,43 @@ private class ComparingDeclarationsVisitor(
|
||||
val actual = context.getActualAs<ValueParameterDescriptor>()
|
||||
|
||||
visitAnnotations(expected.annotations, actual.annotations, context.nextLevel("Value parameter annotations"))
|
||||
context.assertEquals(expected.name, actual.name, "Name")
|
||||
context.assertEquals(expected.index, actual.index, "Index")
|
||||
context.assertEquals(expected.declaresDefaultValue(), actual.declaresDefaultValue(), "Declares default value")
|
||||
context.assertEquals(expected.isCrossinline, actual.isCrossinline, "Crossinline")
|
||||
context.assertEquals(expected.isNoinline, actual.isNoinline, "Noinline")
|
||||
context.assertFieldsEqual(expected::getName, actual::getName)
|
||||
context.assertFieldsEqual(expected::index, actual::index)
|
||||
context.assertFieldsEqual(expected::declaresDefaultValue, actual::declaresDefaultValue)
|
||||
context.assertFieldsEqual(expected::isCrossinline, actual::isCrossinline)
|
||||
context.assertFieldsEqual(expected::isNoinline, actual::isNoinline)
|
||||
visitType(expected.type, actual.type, context.nextLevel("Value parameter type"))
|
||||
visitType(expected.varargElementType, actual.varargElementType, context.nextLevel("Value parameter vararg element type"))
|
||||
}
|
||||
|
||||
private fun visitTypeParameters(expected: List<TypeParameterDescriptor>, actual: List<TypeParameterDescriptor>, context: Context) {
|
||||
context.assertEquals(expected.size, actual.size, "Type parameters list size")
|
||||
|
||||
expected.forEachIndexed { index, expectedParam ->
|
||||
val actualParam = actual[index]
|
||||
visitTypeParameterDescriptor(expectedParam, context.nextLevel(actualParam))
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTypeParameterDescriptor(expected: TypeParameterDescriptor, context: Context) {
|
||||
TODO("not implemented")
|
||||
val actual = context.getActualAs<TypeParameterDescriptor>()
|
||||
|
||||
visitAnnotations(expected.annotations, actual.annotations, context.nextLevel("Type parameter annotations"))
|
||||
context.assertFieldsEqual(expected::getName, actual::getName)
|
||||
context.assertFieldsEqual(expected::getIndex, actual::getIndex)
|
||||
context.assertFieldsEqual(expected::isCapturedFromOuterDeclaration, actual::isCapturedFromOuterDeclaration)
|
||||
context.assertFieldsEqual(expected::isReified, actual::isReified)
|
||||
context.assertFieldsEqual(expected::getVariance, actual::getVariance)
|
||||
|
||||
val expectedUpperBounds = expected.upperBounds
|
||||
val actualUpperBounds = actual.upperBounds
|
||||
|
||||
context.assertEquals(expectedUpperBounds.size, actualUpperBounds.size, "Size of upper bound types")
|
||||
|
||||
expectedUpperBounds.forEachIndexed { index, expectedType ->
|
||||
val actualType = actualUpperBounds[index]
|
||||
visitType(expectedType, actualType, context.nextLevel("Type parameter type"))
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitClassDescriptor(expected: ClassDescriptor, context: Context) {
|
||||
@@ -231,6 +259,8 @@ private class ComparingDeclarationsVisitor(
|
||||
|
||||
visitReceiverParameterDescriptor(expected.extensionReceiverParameter, context.nextLevel(actual.extensionReceiverParameter))
|
||||
visitReceiverParameterDescriptor(expected.dispatchReceiverParameter, context.nextLevel(actual.dispatchReceiverParameter))
|
||||
|
||||
visitTypeParameters(expected.typeParameters, actual.typeParameters, context.nextLevel("Property type parameters"))
|
||||
}
|
||||
|
||||
override fun visitPropertyGetterDescriptor(expected: PropertyGetterDescriptor?, context: Context) {
|
||||
@@ -280,7 +310,7 @@ private class ComparingDeclarationsVisitor(
|
||||
val expectedAnnotationFqNames = (expected ?: Annotations.EMPTY).map { it.fqName }.toSet()
|
||||
val actualAnnotationFqNames = (actual ?: Annotations.EMPTY).map { it.fqName }.toSet()
|
||||
|
||||
context.assertEquals(expectedAnnotationFqNames, actualAnnotationFqNames, "annotations")
|
||||
context.assertSetsEqual(expectedAnnotationFqNames, actualAnnotationFqNames, "annotations")
|
||||
}
|
||||
|
||||
private fun visitType(expected: KotlinType?, actual: KotlinType?, context: Context) {
|
||||
@@ -297,6 +327,21 @@ private class ComparingDeclarationsVisitor(
|
||||
val actualFqName = actualUnwrapped.fqName
|
||||
|
||||
context.assertEquals(expectedFqName, actualFqName, "type FQN")
|
||||
|
||||
val expectedArguments = expectedUnwrapped.arguments
|
||||
val actualArguments = actualUnwrapped.arguments
|
||||
|
||||
context.assertEquals(expectedArguments.size, actualArguments.size, "size of type arguments list")
|
||||
|
||||
expectedArguments.forEachIndexed { index, expectedArgument ->
|
||||
val actualArgument = actualArguments[index]
|
||||
|
||||
context.assertFieldsEqual(expectedArgument::isStarProjection, actualArgument::isStarProjection)
|
||||
if (!expectedArgument.isStarProjection) {
|
||||
context.assertFieldsEqual(expectedArgument::getProjectionKind, actualArgument::getProjectionKind)
|
||||
visitType(expectedArgument.type, actualArgument.type, context.nextLevel("Type argument type"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> Context.assertEquals(expected: T?, actual: T?, subject: String) {
|
||||
@@ -317,6 +362,24 @@ private class ComparingDeclarationsVisitor(
|
||||
assertEquals(expectedValue, actualValue, "fields \"$expected\"")
|
||||
}
|
||||
|
||||
private fun <T> Context.assertSetsEqual(expected: Set<T>, actual: Set<T>, subject: String) {
|
||||
val expectedMinusActual = expected.subtract(actual)
|
||||
val actualMinusExpected = actual.subtract(expected)
|
||||
|
||||
if (expectedMinusActual.isNotEmpty() || actualMinusExpected.isNotEmpty())
|
||||
fail(
|
||||
buildString {
|
||||
append("Comparing $subject:\n")
|
||||
append("$expected is not equal to $actual\n")
|
||||
append("Expected size: ${expected.size}\n")
|
||||
append("Actual size: ${actual.size}\n")
|
||||
append("Expected minus actual: $expectedMinusActual\n")
|
||||
append("Actual minus expected: $actualMinusExpected\n")
|
||||
append(this@assertSetsEqual.toString())
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitPackageViewDescriptor(expected: PackageViewDescriptor, context: Context) =
|
||||
fail("Comparison of package views not supported")
|
||||
|
||||
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.core
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
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.mockTypeParameter
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
||||
import org.junit.Test
|
||||
|
||||
@TypeRefinement
|
||||
class DefaultTypeParameterCommonizerTest : AbstractCommonizerTest<TypeParameterDescriptor, TypeParameter>() {
|
||||
override fun createCommonizer() = TypeParameterCommonizer.default()
|
||||
|
||||
@Test
|
||||
fun allAreReified() = doTestSuccess(
|
||||
create(isReified = true),
|
||||
create(isReified = true).toMockParam(),
|
||||
create(isReified = true).toMockParam(),
|
||||
create(isReified = true).toMockParam()
|
||||
)
|
||||
|
||||
@Test
|
||||
fun allAreNotReified() = doTestSuccess(
|
||||
create(isReified = false),
|
||||
create(isReified = false).toMockParam(),
|
||||
create(isReified = false).toMockParam(),
|
||||
create(isReified = false).toMockParam()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun someAreReified1() = doTestFailure(
|
||||
create(isReified = true).toMockParam(),
|
||||
create(isReified = true).toMockParam(),
|
||||
create(isReified = false).toMockParam()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun someAreReified2() = doTestFailure(
|
||||
create(isReified = false).toMockParam(),
|
||||
create(isReified = false).toMockParam(),
|
||||
create(isReified = true).toMockParam()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun differentVariance1() = doTestFailure(
|
||||
create(variance = Variance.IN_VARIANCE).toMockParam(),
|
||||
create(variance = Variance.IN_VARIANCE).toMockParam(),
|
||||
create(variance = Variance.OUT_VARIANCE).toMockParam()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun differentVariance2() = doTestFailure(
|
||||
create(variance = Variance.OUT_VARIANCE).toMockParam(),
|
||||
create(variance = Variance.OUT_VARIANCE).toMockParam(),
|
||||
create(variance = Variance.INVARIANT).toMockParam()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun differentUpperBounds1() = doTestFailure(
|
||||
create(upperBounds = listOf("kotlin.String")).toMockParam(),
|
||||
create(upperBounds = listOf("kotlin.String")).toMockParam(),
|
||||
create(upperBounds = listOf("kotlin.Int")).toMockParam()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun differentUpperBounds2() = doTestFailure(
|
||||
create(upperBounds = listOf("kotlin.String", "kotlin.Int")).toMockParam(),
|
||||
create(upperBounds = listOf("kotlin.String", "kotlin.Int")).toMockParam(),
|
||||
create(upperBounds = listOf("kotlin.String")).toMockParam()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun differentUpperBounds3() = doTestFailure(
|
||||
create(upperBounds = listOf("kotlin.String", "kotlin.Int")).toMockParam(),
|
||||
create(upperBounds = listOf("kotlin.String", "kotlin.Int")).toMockParam(),
|
||||
create(upperBounds = listOf("kotlin.Int", "kotlin.String")).toMockParam()
|
||||
)
|
||||
|
||||
internal companion object {
|
||||
fun create(
|
||||
name: String = "T",
|
||||
isReified: Boolean = false,
|
||||
variance: Variance = Variance.INVARIANT,
|
||||
upperBounds: List<String> = listOf("kotlin.Any")
|
||||
) = CommonTypeParameter(
|
||||
name = Name.identifier(name),
|
||||
isReified = isReified,
|
||||
variance = variance,
|
||||
upperBounds = upperBounds.map { mockClassType(it).unwrap() }
|
||||
)
|
||||
|
||||
fun TypeParameter.toMockParam(
|
||||
index: Int = 0
|
||||
): TypeParameterDescriptor = mockTypeParameter(
|
||||
name = name.asString(),
|
||||
index = index,
|
||||
isReified = isReified,
|
||||
variance = variance,
|
||||
upperBounds = upperBounds
|
||||
)
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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.core
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeParameter
|
||||
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
||||
import org.junit.Test
|
||||
|
||||
@TypeRefinement
|
||||
class DefaultTypeParameterListCommonizerTest : AbstractCommonizerTest<List<TypeParameterDescriptor>, List<TypeParameter>>() {
|
||||
|
||||
@Test
|
||||
fun emptyValueParameters() = doTestSuccess(
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
emptyList()
|
||||
)
|
||||
|
||||
@Test
|
||||
fun matchedParameters() = doTestSuccess(
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?"
|
||||
),
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?"
|
||||
).toMockParams(),
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?"
|
||||
).toMockParams(),
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?"
|
||||
).toMockParams()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun mismatchedParameterListSize1() = doTestFailure(
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?"
|
||||
).toMockParams(),
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?"
|
||||
).toMockParams(),
|
||||
emptyList()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun mismatchedParameterListSize2() = doTestFailure(
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?"
|
||||
).toMockParams(),
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?"
|
||||
).toMockParams(),
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence"
|
||||
).toMockParams()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun mismatchedParameterListSize3() = doTestFailure(
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?"
|
||||
).toMockParams(),
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?"
|
||||
).toMockParams(),
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence",
|
||||
"Q" to "org.sample.Foo?",
|
||||
"V" to "org.sample.Bar"
|
||||
).toMockParams()
|
||||
)
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun mismatchedParameterNames() = doTestFailure(
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"R" to "kotlin.CharSequence"
|
||||
).toMockParams(),
|
||||
create(
|
||||
"T" to "kotlin.Any?",
|
||||
"Q" to "kotlin.CharSequence"
|
||||
).toMockParams()
|
||||
)
|
||||
|
||||
override fun createCommonizer() = TypeParameterListCommonizer.default()
|
||||
|
||||
private companion object {
|
||||
fun create(vararg params: Pair<String, String>): List<TypeParameter> {
|
||||
check(params.isNotEmpty())
|
||||
return params.map { (name, returnTypeFqName) ->
|
||||
DefaultTypeParameterCommonizerTest.create(
|
||||
name = name,
|
||||
upperBounds = listOf(returnTypeFqName)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun List<TypeParameter>.toMockParams() = DefaultTypeParameterCommonizerTest.run {
|
||||
mapIndexed { index, param -> param.toMockParam(index) }
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -141,8 +141,8 @@ class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<ValueParamete
|
||||
|
||||
override fun createCommonizer() = ValueParameterCommonizer.default()
|
||||
|
||||
companion object {
|
||||
internal fun create(
|
||||
internal companion object {
|
||||
fun create(
|
||||
returnTypeFqName: String,
|
||||
name: String = "myParameter",
|
||||
hasVarargElementType: Boolean = false,
|
||||
@@ -160,7 +160,7 @@ class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<ValueParamete
|
||||
)
|
||||
}
|
||||
|
||||
internal fun ValueParameter.toMockParam(
|
||||
fun ValueParameter.toMockParam(
|
||||
index: Int = 0,
|
||||
declaresDefaultValue: Boolean = false
|
||||
): ValueParameterDescriptor = mockValueParameter(
|
||||
|
||||
+1
-1
@@ -167,7 +167,7 @@ class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<Valu
|
||||
|
||||
override fun createCommonizer() = ValueParameterListCommonizer.default()
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
fun create(vararg params: Pair<String, String>): List<ValueParameter> {
|
||||
check(params.isNotEmpty())
|
||||
return params.map { (name, returnTypeFqName) ->
|
||||
|
||||
@@ -7,13 +7,13 @@ package org.jetbrains.kotlin.descriptors.commonizer
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.builder.buildDispatchReceiver
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.FunctionModifiers
|
||||
import org.jetbrains.kotlin.descriptors.impl.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.parentOrNull
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
@@ -118,13 +118,8 @@ internal fun mockProperty(
|
||||
): PropertyDescriptor {
|
||||
val propertyName = Name.identifier(name)
|
||||
|
||||
val containingDeclaration = object : DeclarationDescriptorImpl(Annotations.EMPTY, Name.special("<fake containing declaration>")) {
|
||||
override fun getContainingDeclaration() = error("not supported")
|
||||
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D) = error("not supported")
|
||||
}
|
||||
|
||||
val propertyDescriptor = PropertyDescriptorImpl.create(
|
||||
/*containingDeclaration =*/ containingDeclaration,
|
||||
/*containingDeclaration =*/ fakeContainingDeclaration(),
|
||||
/*annotations =*/ Annotations.EMPTY,
|
||||
/*modality =*/ Modality.FINAL,
|
||||
/*visibility =*/ Visibilities.PUBLIC,
|
||||
@@ -146,7 +141,7 @@ internal fun mockProperty(
|
||||
/*annotations =*/ Annotations.EMPTY
|
||||
)
|
||||
|
||||
val dispatchReceiverDescriptor = DescriptorUtils.getDispatchReceiverParameterIfNeeded(containingDeclaration)
|
||||
val dispatchReceiverDescriptor = buildDispatchReceiver(propertyDescriptor)
|
||||
|
||||
propertyDescriptor.setType(
|
||||
/*outType =*/ returnType,
|
||||
@@ -202,13 +197,8 @@ internal fun mockFunction(
|
||||
): SimpleFunctionDescriptor {
|
||||
val functionName = Name.identifier(name)
|
||||
|
||||
val containingDeclaration = object : DeclarationDescriptorImpl(Annotations.EMPTY, Name.special("<fake containing declaration>")) {
|
||||
override fun getContainingDeclaration() = error("not supported")
|
||||
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D) = error("not supported")
|
||||
}
|
||||
|
||||
val functionDescriptor = SimpleFunctionDescriptorImpl.create(
|
||||
/*containingDeclaration =*/ containingDeclaration,
|
||||
/*containingDeclaration =*/ fakeContainingDeclaration(),
|
||||
/*annotations =*/ Annotations.EMPTY,
|
||||
/*name =*/ functionName,
|
||||
/*kind =*/ CallableMemberDescriptor.Kind.DECLARATION,
|
||||
@@ -222,7 +212,7 @@ internal fun mockFunction(
|
||||
functionDescriptor.isSuspend = modifiers.isSuspend
|
||||
functionDescriptor.isExternal = modifiers.isExternal
|
||||
|
||||
val dispatchReceiverDescriptor = DescriptorUtils.getDispatchReceiverParameterIfNeeded(containingDeclaration)
|
||||
val dispatchReceiverDescriptor = buildDispatchReceiver(functionDescriptor)
|
||||
|
||||
functionDescriptor.initialize(
|
||||
/*extensionReceiverParameter =*/ null,
|
||||
@@ -250,7 +240,11 @@ internal fun mockValueParameter(
|
||||
check(index >= 0)
|
||||
|
||||
val effectiveContainingDeclaration = containingDeclaration
|
||||
?: mockFunction("fakeFunction", returnType, TestFunctionModifiers()) // use fake function if no real containing declaration specified
|
||||
?: /* use fake function if no real containing declaration specified */ mockFunction(
|
||||
"fakeFunction",
|
||||
returnType,
|
||||
TestFunctionModifiers()
|
||||
)
|
||||
|
||||
return ValueParameterDescriptorImpl(
|
||||
containingDeclaration = effectiveContainingDeclaration,
|
||||
@@ -267,29 +261,29 @@ internal fun mockValueParameter(
|
||||
)
|
||||
}
|
||||
|
||||
//private fun mockTypeParameterType(
|
||||
// name: String,
|
||||
// containingDeclaration: DeclarationDescriptor,
|
||||
// definitelyNotNull: Boolean = false
|
||||
//): KotlinType {
|
||||
// val typeParameterName = Name.identifier(name)
|
||||
//
|
||||
// val typeParameterDescriptor = TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
// /*containingDeclaration =*/ containingDeclaration,
|
||||
// /*annotations =*/ Annotations.EMPTY,
|
||||
// /*reified =*/ false,
|
||||
// /*variance =*/ Variance.INVARIANT,
|
||||
// /*name =*/ typeParameterName,
|
||||
// /*index =*/ 0
|
||||
// )
|
||||
//
|
||||
// val simpleType = createSimpleType(typeParameterDescriptor.typeConstructor, false)
|
||||
//
|
||||
// return if (definitelyNotNull)
|
||||
// simpleType.makeSimpleTypeDefinitelyNotNullOrNotNull().also { check(it.isDefinitelyNotNullType) }
|
||||
// else
|
||||
// simpleType
|
||||
//}
|
||||
internal fun mockTypeParameter(
|
||||
containingDeclaration: CallableDescriptor? = null,
|
||||
name: String,
|
||||
index: Int,
|
||||
isReified: Boolean,
|
||||
variance: Variance,
|
||||
upperBounds: List<KotlinType>
|
||||
): TypeParameterDescriptor {
|
||||
check(index >= 0)
|
||||
|
||||
return TypeParameterDescriptorImpl.createForFurtherModification(
|
||||
containingDeclaration ?: fakeContainingDeclaration(),
|
||||
Annotations.EMPTY,
|
||||
isReified,
|
||||
variance,
|
||||
Name.identifier(name),
|
||||
index,
|
||||
SourceElement.NO_SOURCE
|
||||
).apply {
|
||||
upperBounds.forEach(this::addUpperBound)
|
||||
setInitialized()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createPackageFragmentForClassifier(classifierFqName: FqName): PackageFragmentDescriptor =
|
||||
object : PackageFragmentDescriptor {
|
||||
@@ -315,3 +309,9 @@ private fun createSimpleType(typeConstructor: TypeConstructor, nullable: Boolean
|
||||
memberScope = MemberScope.Empty,
|
||||
refinedTypeFactory = { null }
|
||||
)
|
||||
|
||||
private fun fakeContainingDeclaration() =
|
||||
object : DeclarationDescriptorImpl(Annotations.EMPTY, Name.special("<fake containing declaration>")) {
|
||||
override fun getContainingDeclaration() = error("not supported")
|
||||
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D) = error("not supported")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user