KAPT+IR: support nullability for error types

#KT-49682
This commit is contained in:
Mikhael Bogdanov
2022-06-10 10:45:59 +02:00
committed by Space
parent 162ca4ac2b
commit e1d00c3d6e
5 changed files with 66 additions and 54 deletions
@@ -29,7 +29,11 @@ abstract class IrType : KotlinTypeMarker, IrAnnotationContainer {
abstract override fun hashCode(): Int
}
abstract class IrErrorType(kotlinType: KotlinType?, private val errorClassStubSymbol: IrClassSymbol) : IrTypeBase(kotlinType), SimpleTypeMarker {
abstract class IrErrorType(
kotlinType: KotlinType?,
private val errorClassStubSymbol: IrClassSymbol,
val isMarkedNullable: Boolean = false
) : IrTypeBase(kotlinType), SimpleTypeMarker {
val symbol: IrClassSymbol
get() = errorClassStubSymbol
}
@@ -47,6 +47,7 @@ fun IrType.isNullable(): Boolean =
else -> error("Unsupported classifier: $classifier")
}
is IrDynamicType -> true
is IrErrorType -> this.isMarkedNullable
else -> false
}
@@ -0,0 +1,55 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.ir.types.impl
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.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
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()
}
@@ -5,26 +5,11 @@
package org.jetbrains.kotlin.ir.types.impl
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.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
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
@@ -40,46 +25,13 @@ class IrErrorTypeImpl(
kotlinType: KotlinType?,
override val annotations: List<IrConstructorCall>,
override val variance: Variance,
) : IrErrorType(kotlinType, IrErrorClassImpl.symbol) {
isMarkedNullable: Boolean = false
) : IrErrorType(kotlinType, IrErrorClassImpl.symbol, isMarkedNullable) {
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>,
@@ -90,7 +42,6 @@ class IrDynamicTypeImpl(
override fun hashCode(): Int = IrDynamicTypeImpl::class.java.hashCode()
}
val IrType.originalKotlinType: KotlinType?
get() = safeAs<IrTypeBase>()?.kotlinType
@@ -99,6 +99,7 @@ abstract class TypeTranslator(
approximatedType,
translateTypeAnnotations(approximatedType),
variance,
isMarkedNullable = approximatedType.isMarkedNullable,
)
approximatedType.isDynamic() ->
return IrDynamicTypeImpl(approximatedType, translateTypeAnnotations(approximatedType), variance)