[Commonizer] Don't preserve annotations on types

This may lead to leakage of specific annotation classes to common module

^KMM-53
This commit is contained in:
Dmitriy Dolovov
2020-05-08 20:11:37 +07:00
parent 5bb5d7f892
commit e92adf3d4e
4 changed files with 6 additions and 8 deletions
@@ -121,7 +121,7 @@ internal fun CirSimpleType.buildType(
}
val simpleType = simpleType(
annotations = annotations.buildDescriptors(targetComponents),
annotations = Annotations.EMPTY,
constructor = classifier.typeConstructor,
arguments = arguments.map { it.buildArgument(targetComponents, typeParameterResolver) },
nullable = isMarkedNullable,
@@ -34,9 +34,10 @@ sealed class CirType {
* expanded type represents right-hand side declaration that should be processed separately.
*
* There is no difference between "abbreviation" and "expanded" for types representing classes and type parameters.
*
* Note: Annotations at simple types are not preserved. After commonization all annotations assigned to types will be lost.
*/
class CirSimpleType private constructor(original: SimpleType) : CirType() {
val annotations: List<CirAnnotation>
val kind: CirSimpleTypeKind
val fqName: FqName
val arguments: List<CirTypeProjection>
@@ -48,7 +49,6 @@ class CirSimpleType private constructor(original: SimpleType) : CirType() {
val abbreviation = (original as? AbbreviatedType)?.abbreviation ?: original
val expanded = (original as? AbbreviatedType)?.expandedType ?: original
annotations = abbreviation.annotations.map(CirAnnotation.Companion::create)
kind = CirSimpleTypeKind.determineKind(abbreviation.declarationDescriptor)
fqName = abbreviation.fqNameInterned
arguments = abbreviation.arguments.map(::CirTypeProjection)
@@ -68,7 +68,6 @@ class CirSimpleType private constructor(original: SimpleType) : CirType() {
&& kind == other.kind
&& arguments == other.arguments
&& fqNameWithTypeParameters == other.fqNameWithTypeParameters
&& annotations == other.annotations
&& isDefinitelyNotNullType == other.isDefinitelyNotNullType
}
else -> false
@@ -77,8 +76,7 @@ class CirSimpleType private constructor(original: SimpleType) : CirType() {
// See also org.jetbrains.kotlin.types.KotlinType.cachedHashCode
private var cachedHashCode = 0
private fun computeHashCode() = hashCode(annotations)
.appendHashCode(kind)
private fun computeHashCode() = hashCode(kind)
.appendHashCode(fqName)
.appendHashCode(arguments)
.appendHashCode(isMarkedNullable)
@@ -47,7 +47,7 @@ actual fun function1(@JsAnnotation("parameter") @CommonAnnotation("parameter") t
@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
actual fun <@JsAnnotation("type-parameter") @CommonAnnotation("type-parameter") Q : Number> @receiver:JsAnnotation("receiver") @receiver:CommonAnnotation("receiver") Q.function2(): Q = this
@JsAnnotation("class")
@CommonAnnotation("class")
@@ -47,7 +47,7 @@ actual fun function1(@JvmAnnotation("parameter") @CommonAnnotation("parameter")
@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
actual fun <@JvmAnnotation("type-parameter") @CommonAnnotation("type-parameter") Q : Number> @receiver:JvmAnnotation("receiver") @receiver:CommonAnnotation("receiver") Q.function2(): Q = this
@JvmAnnotation("class")
@CommonAnnotation("class")