[FIR] Disallow bare types for nested type arguments

Detect missing WRONG_NUMBER_OF_TYPE_ARGUMENTS
This commit is contained in:
Ivan Kochurkin
2021-08-16 20:06:47 +03:00
committed by TeamCityServer
parent 21026cc704
commit d4a11fc295
6 changed files with 10 additions and 17 deletions
@@ -29,9 +29,9 @@ class FirSpecificTypeResolverTransformer(
var areBareTypesAllowed: Boolean = false
@OptIn(PrivateForInline::class)
inline fun <R> withAllowedBareTypes(block: () -> R): R {
inline fun <R> withBareTypes(allowed: Boolean = true, block: () -> R): R {
val oldValue = areBareTypesAllowed
areBareTypesAllowed = true
areBareTypesAllowed = allowed
return try {
block()
} finally {
@@ -72,7 +72,9 @@ class FirSpecificTypeResolverTransformer(
override fun transformTypeRef(typeRef: FirTypeRef, data: ScopeClassDeclaration): FirResolvedTypeRef {
val scopeOwnerLookupNames = data.scopes.flatMap { it.scopeOwnerLookupNames }
session.lookupTracker?.recordTypeLookup(typeRef, scopeOwnerLookupNames, currentFile?.source)
typeRef.transformChildren(this, data)
withBareTypes(allowed = false) {
typeRef.transformChildren(this, data)
}
return transformType(
typeRef,
typeResolver.resolveType(
@@ -219,7 +219,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
superReferenceContainer.resultType = superTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.SuperCallExplicitType)
}
superTypeRef !is FirImplicitTypeRef -> {
components.typeResolverTransformer.withAllowedBareTypes {
components.typeResolverTransformer.withBareTypes {
superReference.transformChildren(transformer, ResolutionMode.ContextIndependent)
}
@@ -621,7 +621,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
typeOperatorCall: FirTypeOperatorCall,
data: ResolutionMode,
): FirStatement {
val resolved = components.typeResolverTransformer.withAllowedBareTypes {
val resolved = components.typeResolverTransformer.withBareTypes {
if (typeOperatorCall.operation == FirOperation.IS || typeOperatorCall.operation == FirOperation.NOT_IS) {
components.typeResolverTransformer.withIsOperandOfIsOperator {
typeOperatorCall.transformConversionTypeRef(transformer, ResolutionMode.ContextIndependent)