KAPT: Fix an ISE when processing unresolved generic types

Error types that are generic could sometimes throw an ISE when
generating the stub.

This fixes KT-43786
This commit is contained in:
Nicklas Ansman Giertz
2022-09-16 11:54:52 -04:00
committed by Alexander Udalov
parent 21fe0e80ff
commit 115bc6ac89
6 changed files with 90 additions and 1 deletions
@@ -19,6 +19,10 @@ package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext.replaceArguments
import org.jetbrains.kotlin.types.error.ErrorType
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.model.typeConstructor
abstract class TypeSubstitution {
companion object {
@@ -171,6 +175,10 @@ fun SimpleType.replace(
return replaceAttributes(newAttributes)
}
if (this is ErrorType) {
return replaceArguments(newArguments)
}
return KotlinTypeFactory.simpleType(
newAttributes,
constructor,
@@ -24,8 +24,11 @@ class ErrorType @JvmOverloads internal constructor(
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType = this
fun replaceArguments(newArguments: List<TypeProjection>): ErrorType =
ErrorType(constructor, memberScope, kind, newArguments, isMarkedNullable, *formatParams)
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType =
ErrorType(constructor, memberScope, kind, arguments, newNullability, *formatParams)
ErrorType(constructor, memberScope, kind, arguments, newNullability, *formatParams)
@TypeRefinement
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) = this