Introduce TypeSystemCommonBackendContext, use in KotlinTypeMapper.getVarianceForWildcard

This commit is contained in:
Alexander Udalov
2019-06-19 19:30:42 +02:00
parent 0460b2990f
commit 2585ce0aa7
4 changed files with 67 additions and 39 deletions
@@ -0,0 +1,13 @@
/*
* 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.types
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
import org.jetbrains.kotlin.types.model.TypeSystemContext
interface TypeSystemCommonBackendContext : TypeSystemContext {
fun TypeConstructorMarker.isFinalClassOrEnumEntryOrAnnotationClassConstructor(): Boolean
}
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.types.typeUtil.contains
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext {
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSystemCommonBackendContext {
override fun TypeConstructorMarker.isDenotable(): Boolean {
require(this is TypeConstructor, this::errorMessage)
return this.isDenotable
@@ -145,15 +145,6 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext {
return this.projectionKind.convertVariance()
}
private fun TypeVariance.convertVariance(): Variance {
return when (this) {
TypeVariance.INV -> Variance.INVARIANT
TypeVariance.IN -> Variance.IN_VARIANCE
TypeVariance.OUT -> Variance.OUT_VARIANCE
}
}
override fun TypeArgumentMarker.getType(): KotlinTypeMarker {
require(this is TypeProjection, this::errorMessage)
return this.type.unwrap()
@@ -214,6 +205,12 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext {
classDescriptor.kind != ClassKind.ANNOTATION_CLASS
}
override fun TypeConstructorMarker.isFinalClassOrEnumEntryOrAnnotationClassConstructor(): Boolean {
require(this is TypeConstructor, this::errorMessage)
val classDescriptor = declarationDescriptor
return classDescriptor is ClassDescriptor && classDescriptor.isFinalClass
}
override fun SimpleTypeMarker.asArgumentList(): TypeArgumentListMarker {
require(this is SimpleType, this::errorMessage)
return this
@@ -490,6 +487,14 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext {
}
fun TypeVariance.convertVariance(): Variance {
return when (this) {
TypeVariance.INV -> Variance.INVARIANT
TypeVariance.IN -> Variance.IN_VARIANCE
TypeVariance.OUT -> Variance.OUT_VARIANCE
}
}
private fun captureFromExpressionInternal(type: UnwrappedType) = captureFromExpression(type)
private fun hasNoInferInternal(type: UnwrappedType): Boolean {