[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)
@@ -1,10 +0,0 @@
interface Tr
interface G<T>
fun test(tr: Tr): Any {
return tr as G<G>
}
fun test1(tr: Tr): Any {
return tr as G.(G) -> G
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface Tr
interface G<T>
@@ -6,7 +6,7 @@ public fun foo(a: Any) {
a is Map<out Any?, Any?>
a is Map<*, *>
a is Map<<!SYNTAX!><!>>
a is List<Map>
a is List<<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Map<!>>
a is <!NO_TYPE_ARGUMENTS_ON_RHS!>List<!>
a is Int
@@ -5,7 +5,7 @@ public fun foo(a: Any, b: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Map<!>) {
is Map<out Any?, Any?> -> {}
is Map<*, *> -> {}
is Map<<!SYNTAX!><!>> -> {}
is List<Map> -> {}
is List<<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Map<!>> -> {}
is <!NO_TYPE_ARGUMENTS_ON_RHS!>List<!> -> {}
is Int -> {}
else -> {}