Minor. use when instead of if sequence.

This commit is contained in:
Stanislav Erokhin
2017-02-07 15:30:21 +03:00
parent b616ef0a40
commit 58c2466a52
@@ -102,29 +102,31 @@ object NewKotlinTypeChecker : KotlinTypeChecker {
} }
fun transformToNewType(type: SimpleType): SimpleType { fun transformToNewType(type: SimpleType): SimpleType {
// Type itself can be just SimpleTypeImpl, not CapturedType. see KT-16147 val constructor = type.constructor
if (type.constructor is CapturedTypeConstructor) { when (constructor) {
val constructor = type.constructor as CapturedTypeConstructor // Type itself can be just SimpleTypeImpl, not CapturedType. see KT-16147
val lowerType = constructor.typeProjection.check { it.projectionKind == Variance.IN_VARIANCE }?.type?.unwrap() is CapturedTypeConstructor -> {
val lowerType = constructor.typeProjection.check { it.projectionKind == Variance.IN_VARIANCE }?.type?.unwrap()
// it is incorrect calculate this type directly because of recursive star projections // it is incorrect calculate this type directly because of recursive star projections
if (constructor.newTypeConstructor == null) { if (constructor.newTypeConstructor == null) {
constructor.newTypeConstructor = NewCapturedTypeConstructor(constructor.typeProjection, constructor.supertypes.map { it.unwrap() }) constructor.newTypeConstructor = NewCapturedTypeConstructor(constructor.typeProjection, constructor.supertypes.map { it.unwrap() })
}
val newCapturedType = NewCapturedType(CaptureStatus.FOR_SUBTYPING, constructor.newTypeConstructor!!,
lowerType, type.annotations, type.isMarkedNullable)
return newCapturedType
} }
val newCapturedType = NewCapturedType(CaptureStatus.FOR_SUBTYPING, constructor.newTypeConstructor!!,
lowerType, type.annotations, type.isMarkedNullable)
return newCapturedType
}
if (type.constructor is IntersectionTypeConstructor && type.isMarkedNullable) { is IntegerValueTypeConstructor -> {
val newSuperTypes = type.constructor.supertypes.map { it.makeNullable() } val newConstructor = IntersectionTypeConstructor(constructor.supertypes.map { TypeUtils.makeNullableAsSpecified(it, type.isMarkedNullable) })
val newConstructor = IntersectionTypeConstructor(newSuperTypes) return KotlinTypeFactory.simpleType(type.annotations, newConstructor, listOf(), false, type.memberScope)
return KotlinTypeFactory.simpleType(type.annotations, newConstructor, listOf(), false, newConstructor.createScopeForKotlinType()) }
}
if (type.constructor is IntegerValueTypeConstructor) { is IntersectionTypeConstructor -> if (type.isMarkedNullable) {
val newConstructor = IntersectionTypeConstructor(type.constructor.supertypes.map { TypeUtils.makeNullableAsSpecified(it, type.isMarkedNullable) }) val newSuperTypes = constructor.supertypes.map { it.makeNullable() }
return KotlinTypeFactory.simpleType(type.annotations, newConstructor, listOf(), false, type.memberScope) val newConstructor = IntersectionTypeConstructor(newSuperTypes)
return KotlinTypeFactory.simpleType(type.annotations, newConstructor, listOf(), false, newConstructor.createScopeForKotlinType())
}
} }
return type return type