KAPT+IR: support IR error types
diff --git a/compiler/backend.common.jvm/src/org/jetbrains/kotlin/types/AbstractTypeMapper.kt b/compiler/backend.common.jvm/src/org/jetbrains/kotlin/types/AbstractTypeMapper.kt
index ac621bd..9707fda 100644
--- a/compiler/backend.common.jvm/src/org/jetbrains/kotlin/types/AbstractTypeMapper.kt
+++ b/compiler/backend.common.jvm/src/org/jetbrains/kotlin/types/AbstractTypeMapper.kt
@@ -8,6 +8,7 @@
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
@@ -57,6 +58,11 @@
sw: Writer? = null
): Type {
val typeConstructor = type.typeConstructor()
+ if (type.isError()) {
+ val jvmType = Type.getObjectType(NON_EXISTENT_CLASS_NAME)
+ with(context) { sw?.writeGenericType(type, jvmType, mode) }
+ return jvmType
+ }
if (type is SimpleTypeMarker) {
val builtInType = mapBuiltInType(type, AsmTypeFactory, mode)
diff --git a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/AnnotationCodegen.kt b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/AnnotationCodegen.kt
index f54ee5f..9b5bf3c 100644
--- a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/AnnotationCodegen.kt
+++ b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/AnnotationCodegen.kt
@@ -217,7 +217,7 @@
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")
}
}
diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt
index e57fcca..17490f4 100644
--- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt
+++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt
@@ -89,6 +89,7 @@
is IrClassSymbol -> classifier.owner
is IrTypeParameterSymbol -> classifier.owner.erasedUpperBound
is IrScriptSymbol -> classifier.owner.targetClass!!.owner
+ is IrErrorType -> classifier.symbol.owner
else -> error(render())
}
diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/mapping/IrTypeMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/mapping/IrTypeMapper.kt
index 3eed8c5..3a51b87 100644
--- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/mapping/IrTypeMapper.kt
+++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/mapping/IrTypeMapper.kt
@@ -132,6 +132,11 @@
): 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)
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt
index a599701..ed8d036 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt
@@ -1138,6 +1138,7 @@
it
}
}
+ is IrErrorType -> kotlinType!!
else ->
throw AssertionError("Unexpected type: $this = ${this.render()}")
}
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt
index 2930e0a..b5cf250 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt
@@ -6,8 +6,10 @@
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.IrErrorClassImpl
import org.jetbrains.kotlin.ir.types.impl.IrTypeBase
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.Variance
@@ -28,7 +30,10 @@
abstract override fun hashCode(): Int
}
-abstract class IrErrorType(kotlinType: KotlinType?) : IrTypeBase(kotlinType)
+abstract class IrErrorType(kotlinType: KotlinType?, private val errorClassStubSymbol: IrClassSymbol? = null) : IrTypeBase(kotlinType), SimpleTypeMarker {
+ val symbol: IrClassSymbol
+ get() = IrErrorClassImpl.symbol//errorClassStubSymbol ?: error("123")
+}
abstract class IrDynamicType(kotlinType: KotlinType?) : IrTypeBase(kotlinType), DynamicTypeMarker
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt
index cf28656..e69884d 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt
@@ -86,6 +86,7 @@
override fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker = when (this) {
is IrCapturedType -> constructor
is IrSimpleType -> classifier
+ is IrErrorType -> symbol
else -> error("Unknown type constructor")
}
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt
index 83476db..fa9f2a2 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt
@@ -5,11 +5,25 @@
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.IrFileImpl
+import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyClass
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
+import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
+import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
+import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
import org.jetbrains.kotlin.ir.types.*
+import org.jetbrains.kotlin.name.FqName
+import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.model.CaptureStatus
@@ -25,12 +39,47 @@
kotlinType: KotlinType?,
override val annotations: List<IrConstructorCall>,
override val variance: Variance,
-) : IrErrorType(kotlinType) {
+ private val errorClassStubSymbol: IrClassSymbol? = null
+) : IrErrorType(kotlinType, errorClassStubSymbol) {
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.DEFAULT_PROPERTY_ACCESSOR, 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>,
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt
index 815726c..44b750a 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt
@@ -88,6 +88,7 @@
val IrType.classifierOrNull: IrClassifierSymbol?
get() = when (this) {
is IrSimpleType -> classifier
+ is IrErrorType -> symbol
else -> null
}
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt
index 15581b9..52c22da 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt
@@ -12,6 +12,7 @@
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.types.*
+import org.jetbrains.kotlin.ir.types.impl.IrErrorClassImpl
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.utils.DFS
@@ -263,10 +264,14 @@
val IrClass.isAnonymousObject get() = isClass && name == SpecialNames.NO_NAME_PROVIDED
val IrClass.isNonCompanionObject: Boolean get() = isObject && !isCompanion
val IrDeclarationWithName.fqNameWhenAvailable: FqName?
- get() = when (val parent = parent) {
- is IrDeclarationWithName -> parent.fqNameWhenAvailable?.child(name)
- is IrPackageFragment -> parent.fqName.child(name)
- else -> null
+ get() {
+ if (this is IrErrorClassImpl) return FqName.ROOT.child(this.name)
+ return when (val parent = parent) {
+ is IrErrorClassImpl -> null
+ is IrDeclarationWithName -> parent.fqNameWhenAvailable?.child(name)
+ is IrPackageFragment -> parent.fqName.child(name)
+ else -> null
+ }
}
val IrDeclaration.parentAsClass: IrClass
diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt b/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt
index 1b989ed..dd0188d 100644
--- a/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt
+++ b/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt
@@ -1,4 +1,3 @@
-// IGNORE_BACKEND: JVM_IR
// CORRECT_ERROR_TYPES
@file:Suppress("UNRESOLVED_REFERENCE", "ANNOTATION_ARGUMENT_MUST_BE_CONST", "NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION")