Add diagnostic info to assertion on type argument consistency

This commit is contained in:
Denis Zharkov
2017-03-10 14:56:03 +03:00
parent 830bf62d94
commit 39055229a1
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.types.typesApproximation
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructor
import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
@@ -41,7 +43,14 @@ private class TypeArgument(
}
private fun TypeArgument.toTypeProjection(): TypeProjection {
assert(isConsistent) { "Only consistent enhanced type propection can be converted to type projection" }
assert(isConsistent) {
val descriptorRenderer = DescriptorRenderer.withOptions {
classifierNamePolicy = ClassifierNamePolicy.FULLY_QUALIFIED
}
"Only consistent enhanced type projection can be converted to type projection, but " +
"[${descriptorRenderer.render(typeParameter)}: <${descriptorRenderer.renderType(inProjection)}, ${descriptorRenderer.renderType(outProjection)}>]" +
" was found"
}
fun removeProjectionIfRedundant(variance: Variance) = if (variance == typeParameter.variance) Variance.INVARIANT else variance
return when {
inProjection == outProjection -> TypeProjectionImpl(inProjection)