KAPT+IR: support IR error types
#KT-49682
This commit is contained in:
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.types
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.signature.AsmTypeFactory
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmDescriptorTypeWriter
|
||||
import org.jetbrains.kotlin.load.kotlin.NON_EXISTENT_CLASS_NAME
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.load.kotlin.mapBuiltInType
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
@@ -56,6 +57,12 @@ object AbstractTypeMapper {
|
||||
mode: TypeMappingMode = TypeMappingMode.DEFAULT,
|
||||
sw: Writer? = null
|
||||
): Type {
|
||||
if (type.isError()) {
|
||||
val jvmType = Type.getObjectType(NON_EXISTENT_CLASS_NAME)
|
||||
with(context) { sw?.writeGenericType(type, jvmType, mode) }
|
||||
return jvmType
|
||||
}
|
||||
|
||||
val typeConstructor = type.typeConstructor()
|
||||
|
||||
if (type is SimpleTypeMarker) {
|
||||
|
||||
+1
-1
@@ -216,7 +216,7 @@ abstract class AnnotationCodegen(
|
||||
genCompileTimeValue(getAnnotationArgumentJvmName(annotationClass, param.name), value, annotationVisitor)
|
||||
else if (param.defaultValue != null)
|
||||
continue // Default value will be supplied by JVM at runtime.
|
||||
else
|
||||
else if (context.state.classBuilderMode.generateBodies) //skip error for KAPT
|
||||
error("No value for annotation parameter $param")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ val IrType.erasedUpperBound: IrClass
|
||||
is IrClassSymbol -> classifier.owner
|
||||
is IrTypeParameterSymbol -> classifier.owner.erasedUpperBound
|
||||
is IrScriptSymbol -> classifier.owner.targetClass!!.owner
|
||||
else -> error(render())
|
||||
else -> if (this is IrErrorType) symbol.owner else error(render())
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -132,6 +132,11 @@ class IrTypeMapper(private val context: JvmBackendContext) : KotlinTypeMapperBas
|
||||
): Type = AbstractTypeMapper.mapType(this, type, mode, sw)
|
||||
|
||||
override fun JvmSignatureWriter.writeGenericType(type: KotlinTypeMarker, asmType: Type, mode: TypeMappingMode) {
|
||||
if (type is IrErrorType) {
|
||||
writeAsmType(asmType)
|
||||
return
|
||||
}
|
||||
|
||||
if (type !is IrSimpleType) return
|
||||
if (skipGenericSignature() || hasNothingInNonContravariantPosition(type) || type.arguments.isEmpty() || type.isRawTypeImpl()) {
|
||||
writeAsmType(asmType)
|
||||
|
||||
@@ -31,6 +31,7 @@ interface IrDeclarationOrigin {
|
||||
object FILE_CLASS : IrDeclarationOriginImpl("FILE_CLASS")
|
||||
object SYNTHETIC_FILE_CLASS : IrDeclarationOriginImpl("SYNTHETIC_FILE_CLASS", isSynthetic = true)
|
||||
object JVM_MULTIFILE_CLASS : IrDeclarationOriginImpl("JVM_MULTIFILE_CLASS")
|
||||
object ERROR_CLASS : IrDeclarationOriginImpl("ERROR_CLASS")
|
||||
|
||||
object SCRIPT_CLASS : IrDeclarationOriginImpl("SCRIPT_CLASS")
|
||||
object SCRIPT_STATEMENT : IrDeclarationOriginImpl("SCRIPT_STATEMENT")
|
||||
|
||||
@@ -1138,6 +1138,7 @@ fun IrType.toIrBasedKotlinType(): KotlinType = when (this) {
|
||||
it
|
||||
}
|
||||
}
|
||||
is IrErrorType -> kotlinType ?: error("Can't find KotlinType in IrErrorType: " + (this as IrType).render())
|
||||
else ->
|
||||
throw AssertionError("Unexpected type: $this = ${this.render()}")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.ir.types
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrTypeBase
|
||||
@@ -28,7 +29,10 @@ abstract class IrType : KotlinTypeMarker, IrAnnotationContainer {
|
||||
abstract override fun hashCode(): Int
|
||||
}
|
||||
|
||||
abstract class IrErrorType(kotlinType: KotlinType?) : IrTypeBase(kotlinType)
|
||||
abstract class IrErrorType(kotlinType: KotlinType?, private val errorClassStubSymbol: IrClassSymbol) : IrTypeBase(kotlinType), SimpleTypeMarker {
|
||||
val symbol: IrClassSymbol
|
||||
get() = errorClassStubSymbol
|
||||
}
|
||||
|
||||
abstract class IrDynamicType(kotlinType: KotlinType?) : IrTypeBase(kotlinType), DynamicTypeMarker
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
override fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker = when (this) {
|
||||
is IrCapturedType -> constructor
|
||||
is IrSimpleType -> classifier
|
||||
is IrErrorType -> symbol
|
||||
else -> error("Unknown type constructor")
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,26 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.types.impl
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.model.CaptureStatus
|
||||
@@ -25,12 +40,46 @@ class IrErrorTypeImpl(
|
||||
kotlinType: KotlinType?,
|
||||
override val annotations: List<IrConstructorCall>,
|
||||
override val variance: Variance,
|
||||
) : IrErrorType(kotlinType) {
|
||||
) : IrErrorType(kotlinType, IrErrorClassImpl.symbol) {
|
||||
override fun equals(other: Any?): Boolean = other is IrErrorTypeImpl
|
||||
|
||||
override fun hashCode(): Int = IrErrorTypeImpl::class.java.hashCode()
|
||||
}
|
||||
|
||||
object IrErrorClassImpl : IrClassImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.ERROR_CLASS, IrClassSymbolImpl(),
|
||||
Name.special("<error>"), ClassKind.CLASS, DescriptorVisibilities.DEFAULT_VISIBILITY, Modality.FINAL
|
||||
) {
|
||||
override var parent: IrDeclarationParent
|
||||
get() = object: IrFile() {
|
||||
override val startOffset: Int
|
||||
get() = TODO("Not yet implemented")
|
||||
override val endOffset: Int
|
||||
get() = TODO("Not yet implemented")
|
||||
override var annotations: List<IrConstructorCall>
|
||||
get() = TODO("Not yet implemented")
|
||||
set(_) {}
|
||||
override val declarations: MutableList<IrDeclaration>
|
||||
get() = TODO("Not yet implemented")
|
||||
override val symbol: IrFileSymbol
|
||||
get() = TODO("Not yet implemented")
|
||||
override val module: IrModuleFragment
|
||||
get() = TODO("Not yet implemented")
|
||||
override val fileEntry: IrFileEntry
|
||||
get() = TODO("Not yet implemented")
|
||||
override var metadata: MetadataSource?
|
||||
get() = TODO("Not yet implemented")
|
||||
set(_) {}
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
override val packageFragmentDescriptor: PackageFragmentDescriptor
|
||||
get() = TODO("Not yet implemented")
|
||||
override val fqName: FqName
|
||||
get() = FqName.ROOT
|
||||
}
|
||||
set(_) = TODO()
|
||||
}
|
||||
|
||||
class IrDynamicTypeImpl(
|
||||
kotlinType: KotlinType?,
|
||||
override val annotations: List<IrConstructorCall>,
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrErrorClassImpl
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
|
||||
@@ -95,7 +95,11 @@ abstract class TypeTranslator(
|
||||
|
||||
when {
|
||||
approximatedType.isError ->
|
||||
return IrErrorTypeImpl(approximatedType, translateTypeAnnotations(approximatedType), variance)
|
||||
return IrErrorTypeImpl(
|
||||
approximatedType,
|
||||
translateTypeAnnotations(approximatedType),
|
||||
variance,
|
||||
)
|
||||
approximatedType.isDynamic() ->
|
||||
return IrDynamicTypeImpl(approximatedType, translateTypeAnnotations(approximatedType), variance)
|
||||
supportDefinitelyNotNullTypes && approximatedType is DefinitelyNotNullType ->
|
||||
|
||||
Reference in New Issue
Block a user