[FE 1.0] Refactor error utils: split error entities and introduce error type and error scope kinds

This commit is contained in:
Victor Petukhov
2022-03-17 13:32:36 +04:00
committed by teamcity
parent 8c1fcddea3
commit b5933c70e2
139 changed files with 1061 additions and 1204 deletions
@@ -87,7 +87,7 @@ interface TypeSystemTypeFactoryContext: TypeSystemBuiltInsContext {
fun createStarProjection(typeParameter: TypeParameterMarker): TypeArgumentMarker
fun createErrorType(debugName: String): SimpleTypeMarker
fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker
fun createUninferredType(constructor: TypeConstructorMarker): KotlinTypeMarker
}
/**
@@ -34,7 +34,8 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.resolve.constants.StringValue
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.SimpleType
import java.util.*
@@ -159,7 +160,7 @@ object JavaAnnotationTargetMapper {
JavaAnnotationMapper.TARGET_ANNOTATION_ALLOWED_TARGETS,
module.builtIns.getBuiltInClassByFqName(StandardNames.FqNames.target)
)
parameterDescriptor?.type ?: ErrorUtils.createErrorType("Error: AnnotationTarget[]")
parameterDescriptor?.type ?: ErrorUtils.createErrorType(ErrorTypeKind.UNMAPPED_ANNOTATION_TARGET_TYPE)
}
}
@@ -33,7 +33,8 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.resolve.constants.*
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.isError
@@ -47,7 +48,8 @@ class LazyJavaAnnotationDescriptor(
}
override val type by c.storageManager.createLazyValue {
val fqName = fqName ?: return@createLazyValue ErrorUtils.createErrorType("No fqName: $javaAnnotation")
val fqName = fqName
?: return@createLazyValue ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_FQNAME_FOR_JAVA_ANNOTATION, javaAnnotation.toString())
val annotationClass = JavaToKotlinClassMapper.mapJavaToKotlin(fqName, c.module.builtIns)
?: javaAnnotation.resolve()?.let { javaClass -> c.components.moduleClassResolver.resolveClass(javaClass) }
?: createTypeForMissingDependencies(fqName)
@@ -86,7 +88,7 @@ class LazyJavaAnnotationDescriptor(
// Try to load annotation arguments even if the annotation class is not found
?: c.components.module.builtIns.getArrayType(
Variance.INVARIANT,
ErrorUtils.createErrorType("Unknown array element type")
ErrorUtils.createErrorType(ErrorTypeKind.UNKNOWN_ARRAY_ELEMENT_TYPE_OF_ANNOTATION_ARGUMENT)
)
val values = elements.map { argument ->
@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.Variance.*
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.typeUtil.*
import org.jetbrains.kotlin.utils.sure
@@ -92,7 +94,7 @@ class JavaTypeResolver(
}
private fun transformJavaClassifierType(javaType: JavaClassifierType, attr: JavaTypeAttributes): KotlinType {
fun errorType() = ErrorUtils.createErrorType("Unresolved java class ${javaType.presentableText}")
fun errorType() = ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_JAVA_CLASS, javaType.presentableText)
val useFlexible = !attr.isForAnnotationParameter && attr.howThisTypeIsUsed != SUPERTYPE
val isRaw = javaType.isRaw
@@ -256,7 +258,9 @@ class JavaTypeResolver(
if (typeParameters.size != javaType.typeArguments.size) {
// Most of the time this means there is an error in the Java code
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.name.asString())) }.toList()
return typeParameters.map { p ->
TypeProjectionImpl(ErrorUtils.createErrorType(ErrorTypeKind.MISSED_TYPE_ARGUMENT_FOR_TYPE_PARAMETER, p.name.asString()))
}.toList()
}
return javaType.typeArguments.withIndex().map { indexedArgument ->
val (i, javaTypeArgument) = indexedArgument
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.load.java.lazy.types
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.load.java.components.TypeUsage
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
@@ -30,6 +29,8 @@ import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.TypeRefinement
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.typeUtil.builtIns
class RawTypeImpl private constructor(lowerBound: SimpleType, upperBound: SimpleType, disableAssertion: Boolean) :
@@ -149,7 +150,9 @@ internal class RawSubstitution(typeParameterUpperBoundEraser: TypeParameterUpper
) to false
}
if (type.isError) return ErrorUtils.createErrorType("Raw error type: ${type.constructor}") to false
if (type.isError) {
return ErrorUtils.createErrorType(ErrorTypeKind.ERROR_RAW_TYPE, type.constructor.toString()) to false
}
val memberScope = declaration.getMemberScope(this)
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.typeUtil.extractTypeParametersFromUpperBounds
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjectionOrMapped
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
@@ -16,7 +18,7 @@ import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
internal class TypeParameterUpperBoundEraser(rawSubstitution: RawSubstitution? = null) {
private val storage = LockBasedStorageManager("Type parameter upper bound erasion results")
private val erroneousErasedBound by lazy {
ErrorUtils.createErrorType("Can't compute erased upper bound of type parameter `$this`")
ErrorUtils.createErrorType(ErrorTypeKind.CANNOT_COMPUTE_ERASED_BOUND, this.toString())
}
private val rawSubstitution = rawSubstitution ?: RawSubstitution(this)
@@ -21,15 +21,14 @@ import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil
import org.jetbrains.kotlin.serialization.deserialization.FlexibleTypeDeserializer
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.SimpleType
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorTypeKind
object JavaFlexibleTypeDeserializer : FlexibleTypeDeserializer {
override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType {
if (flexibleId != JvmProtoBufUtil.PLATFORM_TYPE_ID) {
return ErrorUtils.createErrorType("Error java flexible type with id: $flexibleId. ($lowerBound..$upperBound)")
return ErrorUtils.createErrorType(ErrorTypeKind.ERROR_FLEXIBLE_TYPE, flexibleId, lowerBound.toString(), upperBound.toString())
}
if (proto.hasExtension(JvmProtoBuf.isRaw)) {
return RawTypeImpl(lowerBound, upperBound)
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.resolve.isInlineClass
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
@@ -18,12 +18,13 @@ import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.types.typeUtil.builtIns
private val FAKE_CONTINUATION_CLASS_DESCRIPTOR =
MutableClassDescriptor(
EmptyPackageFragmentDescriptor(ErrorUtils.getErrorModule(), COROUTINES_PACKAGE_FQ_NAME),
EmptyPackageFragmentDescriptor(ErrorUtils.errorModule, COROUTINES_PACKAGE_FQ_NAME),
ClassKind.INTERFACE, /* isInner = */ false, /* isExternal = */ false,
CONTINUATION_INTERFACE_FQ_NAME.shortName(), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS
).apply {
@@ -37,7 +37,7 @@ interface ModuleDescriptor : DeclarationDescriptor {
fun shouldSeeInternalsOf(targetModule: ModuleDescriptor): Boolean
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R {
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R? {
return visitor.visitModuleDeclaration(this, data)
}
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.getAbbreviation
import org.jetbrains.kotlin.types.model.AnnotationMarker
@@ -31,6 +31,8 @@ import org.jetbrains.kotlin.resolve.scopes.TypeIntersectionScope;
import org.jetbrains.kotlin.storage.NotNullLazyValue;
import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.error.ErrorTypeKind;
import org.jetbrains.kotlin.types.error.ErrorUtils;
import java.util.Collection;
import java.util.Collections;
@@ -221,7 +223,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
@Nullable
@Override
protected KotlinType defaultSupertypeIfEmpty() {
return ErrorUtils.createErrorType("Cyclic upper bounds");
return ErrorUtils.createErrorType(ErrorTypeKind.CYCLIC_UPPER_BOUNDS);
}
@Override
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.descriptors
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.parents
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeProjection
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
@@ -23,8 +23,9 @@ import org.jetbrains.kotlin.resolve.constants.KClassValue
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
import org.jetbrains.kotlin.resolve.descriptorUtil.declaresOrInheritsDefaultValue
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.ErrorUtils.UninferredParameterTypeConstructor
import org.jetbrains.kotlin.types.TypeUtils.CANT_INFER_FUNCTION_PARAM_TYPE
import org.jetbrains.kotlin.types.TypeUtils.CANNOT_INFER_FUNCTION_PARAM_TYPE
import org.jetbrains.kotlin.types.error.*
import org.jetbrains.kotlin.types.typeUtil.isUnresolvedType
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
internal class DescriptorRendererImpl(
@@ -153,13 +154,13 @@ internal class DescriptorRendererImpl(
}
private fun StringBuilder.renderSimpleType(type: SimpleType) {
if (type == CANT_INFER_FUNCTION_PARAM_TYPE || TypeUtils.isDontCarePlaceholder(type)) {
if (type == CANNOT_INFER_FUNCTION_PARAM_TYPE || TypeUtils.isDontCarePlaceholder(type)) {
append("???")
return
}
if (ErrorUtils.isUninferredParameter(type)) {
if (ErrorUtils.isUninferredTypeVariable(type)) {
if (uninferredTypeParameterAsName) {
append(renderError((type.constructor as UninferredParameterTypeConstructor).typeParameterDescriptor.name.toString()))
append(renderError((type.constructor as ErrorTypeConstructor).getParam(0)))
} else {
append("???")
}
@@ -239,11 +240,11 @@ internal class DescriptorRendererImpl(
when {
type.isError -> {
if (type is UnresolvedType && presentableUnresolvedTypes) {
append(type.presentableName)
if (isUnresolvedType(type) && presentableUnresolvedTypes) {
append(type.debugMessage)
} else {
if (type is ErrorType && !informativeErrorType) {
append(type.presentableName)
append(type.debugMessage)
} else {
append(type.constructor.toString()) // Debug name of an error type is more informative
}
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
import org.jetbrains.kotlin.types.error.ErrorUtils;
import java.util.*;
@@ -18,10 +18,10 @@ package org.jetbrains.kotlin.resolve.calls.inference
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.Variance.IN_VARIANCE
import org.jetbrains.kotlin.types.Variance.OUT_VARIANCE
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
import org.jetbrains.kotlin.types.model.CapturedTypeConstructorMarker
import org.jetbrains.kotlin.types.model.CapturedTypeMarker
import org.jetbrains.kotlin.types.TypeRefinement
import org.jetbrains.kotlin.types.error.ErrorScopeKind
import org.jetbrains.kotlin.types.typeUtil.builtIns
interface CapturedTypeConstructor : CapturedTypeConstructorMarker, TypeConstructor {
@@ -83,7 +84,8 @@ class CapturedType(
override val memberScope: MemberScope
get() = ErrorUtils.createErrorScope(
"No member resolution should be done on captured type, it used only during constraint system resolution", true
ErrorScopeKind.CAPTURED_TYPE_SCOPE,
throwExceptions = true
)
override val subTypeRepresentative: KotlinType
@@ -19,9 +19,10 @@ package org.jetbrains.kotlin.resolve.constants
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorScopeKind
import org.jetbrains.kotlin.types.error.ErrorUtils
interface CompileTimeConstant<out T> {
val isError: Boolean
@@ -198,7 +199,7 @@ class IntegerValueTypeConstant(
val unknownIntegerType = KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
TypeAttributes.Empty, typeConstructor, emptyList(), false,
ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true)
ErrorUtils.createErrorScope(ErrorScopeKind.INTEGER_LITERAL_TYPE_SCOPE, throwExceptions = true, typeConstructor.toString())
)
fun getType(expectedType: KotlinType): KotlinType =
@@ -23,13 +23,14 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
abstract class ConstantValue<out T>(open val value: T) {
@@ -120,7 +121,7 @@ class DoubleValue(value: Double) : ConstantValue<Double>(value) {
class EnumValue(val enumClassId: ClassId, val enumEntryName: Name) : ConstantValue<Pair<ClassId, Name>>(enumClassId to enumEntryName) {
override fun getType(module: ModuleDescriptor): KotlinType =
module.findClassAcrossModuleDependencies(enumClassId)?.takeIf(DescriptorUtils::isEnumClass)?.defaultType
?: ErrorUtils.createErrorType("Containing class for error-class based enum entry $enumClassId.$enumEntryName")
?: ErrorUtils.createErrorType(ErrorTypeKind.ERROR_ENUM_TYPE, enumClassId.toString(), enumEntryName.toString())
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitEnumValue(this, data)
@@ -139,7 +140,7 @@ abstract class ErrorValue : ConstantValue<Unit>(Unit) {
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitErrorValue(this, data)
class ErrorValueWithMessage(val message: String) : ErrorValue() {
override fun getType(module: ModuleDescriptor) = ErrorUtils.createErrorType(message)
override fun getType(module: ModuleDescriptor) = ErrorUtils.createErrorType(ErrorTypeKind.ERROR_CONSTANT_VALUE, message)
override fun toString() = message
}
@@ -188,7 +189,7 @@ class KClassValue(value: Value) : ConstantValue<KClassValue.Value>(value) {
is Value.NormalClass -> {
val (classId, arrayDimensions) = value.value
val descriptor = module.findClassAcrossModuleDependencies(classId)
?: return ErrorUtils.createErrorType("Unresolved type: $classId (arrayDimensions=$arrayDimensions)")
?: return ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_KCLASS_CONSTANT_VALUE, classId.toString(), arrayDimensions.toString())
// If this value refers to a class named test.Foo.Bar where both Foo and Bar have generic type parameters,
// we're constructing a type `test.Foo<*>.Bar<*>` below
@@ -266,7 +267,7 @@ class StringValue(value: String) : ConstantValue<String>(value) {
class UByteValue(byteValue: Byte) : UnsignedValueConstant<Byte>(byteValue) {
override fun getType(module: ModuleDescriptor): KotlinType {
return module.findClassAcrossModuleDependencies(StandardNames.FqNames.uByte)?.defaultType
?: ErrorUtils.createErrorType("Unsigned type UByte not found")
?: ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_UNSIGNED_TYPE, "UByte")
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitUByteValue(this, data)
@@ -279,7 +280,7 @@ class UByteValue(byteValue: Byte) : UnsignedValueConstant<Byte>(byteValue) {
class UShortValue(shortValue: Short) : UnsignedValueConstant<Short>(shortValue) {
override fun getType(module: ModuleDescriptor): KotlinType {
return module.findClassAcrossModuleDependencies(StandardNames.FqNames.uShort)?.defaultType
?: ErrorUtils.createErrorType("Unsigned type UShort not found")
?: ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_UNSIGNED_TYPE, "UShort")
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitUShortValue(this, data)
@@ -292,7 +293,7 @@ class UShortValue(shortValue: Short) : UnsignedValueConstant<Short>(shortValue)
class UIntValue(intValue: Int) : UnsignedValueConstant<Int>(intValue) {
override fun getType(module: ModuleDescriptor): KotlinType {
return module.findClassAcrossModuleDependencies(StandardNames.FqNames.uInt)?.defaultType
?: ErrorUtils.createErrorType("Unsigned type UInt not found")
?: ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_UNSIGNED_TYPE, "UInt")
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitUIntValue(this, data)
@@ -305,7 +306,7 @@ class UIntValue(intValue: Int) : UnsignedValueConstant<Int>(intValue) {
class ULongValue(longValue: Long) : UnsignedValueConstant<Long>(longValue) {
override fun getType(module: ModuleDescriptor): KotlinType {
return module.findClassAcrossModuleDependencies(StandardNames.FqNames.uLong)?.defaultType
?: ErrorUtils.createErrorType("Unsigned type ULong not found")
?: ErrorUtils.createErrorType(ErrorTypeKind.NOT_FOUND_UNSIGNED_TYPE, "ULong")
}
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R = visitor.visitULongValue(this, data)
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.checker.refineTypes
import org.jetbrains.kotlin.types.error.ErrorUtils
abstract class AbstractTypeConstructor(storageManager: StorageManager) : ClassifierBasedTypeConstructor() {
override fun getSupertypes() = supertypes().supertypesWithoutCycles
@@ -70,12 +71,12 @@ abstract class AbstractTypeConstructor(storageManager: StorageManager) : Classif
// The first one is used for computation of neighbours in supertypes graph (see Companion.computeNeighbours)
private class Supertypes(val allSupertypes: Collection<KotlinType>) {
// initializer is only needed as a stub for case when 'getSupertypes' is called while 'supertypes' are being calculated
var supertypesWithoutCycles: List<KotlinType> = listOf(ErrorUtils.ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES)
var supertypesWithoutCycles: List<KotlinType> = listOf(ErrorUtils.errorTypeForLoopInSupertypes)
}
private val supertypes = storageManager.createLazyValueWithPostCompute(
{ Supertypes(computeSupertypes()) },
{ Supertypes(listOf(ErrorUtils.ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES)) },
{ Supertypes(listOf(ErrorUtils.errorTypeForLoopInSupertypes)) },
{ supertypes ->
// It's important that loops disconnection begins in post-compute phase, because it guarantees that
// when we start calculation supertypes of supertypes (for computing neighbours), they start their disconnection loop process
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.types.error.ErrorUtils
abstract class ClassifierBasedTypeConstructor : TypeConstructor {
private var hashCode = 0
@@ -1,57 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
open class ErrorType @JvmOverloads internal constructor(
override val constructor: TypeConstructor,
override val memberScope: MemberScope,
override val arguments: List<TypeProjection> = emptyList(),
override val isMarkedNullable: Boolean = false,
open val presentableName: String = "???"
) : SimpleType() {
override val attributes: TypeAttributes
get() = TypeAttributes.Empty
override fun toString(): String =
constructor.toString() + if (arguments.isEmpty()) "" else arguments.joinToString(", ", "<", ">", -1, "...", null)
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType = this
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType =
ErrorType(constructor, memberScope, arguments, newNullability)
@TypeRefinement
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) = this
}
class UnresolvedType(
override val presentableName: String,
constructor: TypeConstructor,
memberScope: MemberScope,
arguments: List<TypeProjection>,
isMarkedNullable: Boolean
) : ErrorType(constructor, memberScope, arguments, isMarkedNullable) {
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType =
UnresolvedType(presentableName, constructor, memberScope, arguments, newNullability)
@TypeRefinement
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) = this
}
@@ -1,639 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.types;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
import org.jetbrains.kotlin.incremental.components.LookupLocation;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.platform.TargetPlatform;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner;
import org.jetbrains.kotlin.types.error.ErrorSimpleFunctionDescriptorImpl;
import org.jetbrains.kotlin.utils.Printer;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import static java.util.Collections.emptySet;
import static kotlin.collections.CollectionsKt.emptyList;
public class ErrorUtils {
private static final ModuleDescriptor ERROR_MODULE;
static {
ERROR_MODULE = new ModuleDescriptor() {
@Nullable
@Override
public <T> T getCapability(@NotNull ModuleCapability<T> capability) {
return null;
}
@NotNull
@Override
public Annotations getAnnotations() {
return Annotations.Companion.getEMPTY();
}
@NotNull
@Override
public Collection<FqName> getSubPackagesOf(@NotNull FqName fqName, @NotNull Function1<? super Name, Boolean> nameFilter) {
return emptyList();
}
@NotNull
@Override
public Name getName() {
return Name.special("<ERROR MODULE>");
}
@NotNull
@Override
public Name getStableName() {
return Name.special("<ERROR MODULE>");
}
@Nullable
@Override
public TargetPlatform getPlatform() {
return null;
}
@NotNull
@Override
public PackageViewDescriptor getPackage(@NotNull FqName fqName) {
throw new IllegalStateException("Should not be called!");
}
@NotNull
@Override
public List<ModuleDescriptor> getAllDependencyModules() {
return emptyList();
}
@NotNull
@Override
public List<ModuleDescriptor> getExpectedByModules() {
return emptyList();
}
@NotNull
@Override
public Set<ModuleDescriptor> getAllExpectedByModules() {
return emptySet();
}
@Override
public <R, D> R accept(@NotNull DeclarationDescriptorVisitor<R, D> visitor, D data) {
return null;
}
@Override
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
}
@Override
public boolean shouldSeeInternalsOf(@NotNull ModuleDescriptor targetModule) {
return false;
}
@NotNull
@Override
public DeclarationDescriptor getOriginal() {
return this;
}
@Nullable
@Override
public DeclarationDescriptor getContainingDeclaration() {
return null;
}
@NotNull
@Override
public KotlinBuiltIns getBuiltIns() {
return DefaultBuiltIns.getInstance();
}
@Override
public boolean isValid() {
return false;
}
@Override
public void assertValid() {
throw new InvalidModuleException("ERROR_MODULE is not a valid module");
}
};
}
/**
* @return true iff any of the types referenced in parameter types (including type parameters and extension receiver) of the function
* is an error type. Does not check the return type of the function.
*/
public static boolean containsErrorTypeInParameters(@NotNull FunctionDescriptor function) {
ReceiverParameterDescriptor receiverParameter = function.getExtensionReceiverParameter();
if (receiverParameter != null && containsErrorType(receiverParameter.getType())) {
return true;
}
for (ValueParameterDescriptor parameter : function.getValueParameters()) {
if (containsErrorType(parameter.getType())) {
return true;
}
}
for (TypeParameterDescriptor parameter : function.getTypeParameters()) {
for (KotlinType upperBound : parameter.getUpperBounds()) {
if (containsErrorType(upperBound)) {
return true;
}
}
}
return false;
}
public static class ErrorScope implements MemberScope {
private final String debugMessage;
private ErrorScope(@NotNull String debugMessage) {
this.debugMessage = debugMessage;
}
@Nullable
@Override
public ClassifierDescriptor getContributedClassifier(@NotNull Name name, @NotNull LookupLocation location) {
return createErrorClass(name.asString());
}
@Nullable
@Override
public DescriptorWithDeprecation<ClassifierDescriptor> getContributedClassifierIncludeDeprecated(
@NotNull Name name, @NotNull LookupLocation location
) {
return null;
}
@NotNull
@Override
public Set<? extends PropertyDescriptor> getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
return ERROR_PROPERTY_GROUP;
}
@NotNull
@Override
public Set<? extends SimpleFunctionDescriptor> getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
return Collections.singleton(createErrorFunction(this));
}
@NotNull
@Override
public Set<Name> getFunctionNames() {
return emptySet();
}
@NotNull
@Override
public Set<Name> getVariableNames() {
return emptySet();
}
@NotNull
@Override
public Set<Name> getClassifierNames() {
return emptySet();
}
@Override
public void recordLookup(@NotNull Name name, @NotNull LookupLocation location) {
}
@NotNull
@Override
public Collection<DeclarationDescriptor> getContributedDescriptors(
@NotNull DescriptorKindFilter kindFilter, @NotNull Function1<? super Name, Boolean> nameFilter
) {
return Collections.emptyList();
}
@Override
public boolean definitelyDoesNotContainName(@NotNull Name name) {
return false;
}
@Override
public String toString() {
return "ErrorScope{" + debugMessage + '}';
}
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println(getClass().getSimpleName(), ": ", debugMessage);
}
}
private static class ThrowingScope implements MemberScope {
private final String debugMessage;
private ThrowingScope(@NotNull String message) {
debugMessage = message;
}
@Nullable
@Override
public ClassifierDescriptor getContributedClassifier(@NotNull Name name, @NotNull LookupLocation location) {
throw new IllegalStateException(debugMessage+", required name: " + name);
}
@Nullable
@Override
public DescriptorWithDeprecation<ClassifierDescriptor> getContributedClassifierIncludeDeprecated(
@NotNull Name name, @NotNull LookupLocation location
) {
throw new IllegalStateException(debugMessage + ", required name: " + name);
}
@NotNull
@Override
public Collection<? extends PropertyDescriptor> getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
throw new IllegalStateException(debugMessage+", required name: " + name);
}
@NotNull
@Override
public Collection<? extends SimpleFunctionDescriptor> getContributedFunctions(
@NotNull Name name, @NotNull LookupLocation location
) {
throw new IllegalStateException(debugMessage+", required name: " + name);
}
@NotNull
@Override
public Collection<DeclarationDescriptor> getContributedDescriptors(
@NotNull DescriptorKindFilter kindFilter, @NotNull Function1<? super Name, Boolean> nameFilter
) {
throw new IllegalStateException(debugMessage);
}
@NotNull
@Override
public Set<Name> getFunctionNames() {
throw new IllegalStateException();
}
@NotNull
@Override
public Set<Name> getVariableNames() {
throw new IllegalStateException();
}
@Override
public Set<Name> getClassifierNames() {
throw new IllegalStateException();
}
@Override
public void recordLookup(@NotNull Name name, @NotNull LookupLocation location) {
throw new IllegalStateException();
}
@Override
public boolean definitelyDoesNotContainName(@NotNull Name name) {
return false;
}
@Override
public String toString() {
return "ThrowingScope{" + debugMessage + '}';
}
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println(getClass().getSimpleName(), ": ", debugMessage);
}
}
private static final ErrorClassDescriptor ERROR_CLASS = new ErrorClassDescriptor(Name.special("<ERROR CLASS>"));
private static class ErrorClassDescriptor extends ClassDescriptorImpl {
public ErrorClassDescriptor(@NotNull Name name) {
super(getErrorModule(), name,
Modality.OPEN, ClassKind.CLASS, Collections.<KotlinType>emptyList(), SourceElement.NO_SOURCE,
/* isExternal = */ false, LockBasedStorageManager.NO_LOCKS
);
ClassConstructorDescriptorImpl
errorConstructor = ClassConstructorDescriptorImpl.create(this, Annotations.Companion.getEMPTY(), true, SourceElement.NO_SOURCE);
errorConstructor.initialize(Collections.<ValueParameterDescriptor>emptyList(),
DescriptorVisibilities.INTERNAL);
MemberScope memberScope = createErrorScope(getName().asString());
errorConstructor.setReturnType(
new ErrorType(
createErrorTypeConstructorWithCustomDebugName("<ERROR>", this),
memberScope
)
);
initialize(memberScope, Collections.<ClassConstructorDescriptor>singleton(errorConstructor), errorConstructor);
}
@NotNull
@Override
public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
return this;
}
@Override
public String toString() {
return getName().asString();
}
@NotNull
@Override
public MemberScope getMemberScope(@NotNull List<? extends TypeProjection> typeArguments, @NotNull KotlinTypeRefiner kotlinTypeRefiner) {
return createErrorScope("Error scope for class " + getName() + " with arguments: " + typeArguments);
}
@NotNull
@Override
public MemberScope getMemberScope(@NotNull TypeSubstitution typeSubstitution, @NotNull KotlinTypeRefiner kotlinTypeRefiner) {
return createErrorScope("Error scope for class " + getName() + " with arguments: " + typeSubstitution);
}
}
@NotNull
public static ClassDescriptor createErrorClass(@NotNull String debugMessage) {
return new ErrorClassDescriptor(Name.special("<ERROR CLASS: " + debugMessage + ">"));
}
@NotNull
public static MemberScope createErrorScope(@NotNull String debugMessage) {
return createErrorScope(debugMessage, false);
}
@NotNull
public static MemberScope createErrorScope(@NotNull String debugMessage, boolean throwExceptions) {
if (throwExceptions) {
return new ThrowingScope(debugMessage);
}
return new ErrorScope(debugMessage);
}
// Do not move it into AbstractTypeConstructor.Companion because of cycle in initialization(see KT-13264)
public static final SimpleType ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES = createErrorType("<LOOP IN SUPERTYPES>");
private static final KotlinType ERROR_PROPERTY_TYPE = createErrorType("<ERROR PROPERTY TYPE>");
private static final PropertyDescriptor ERROR_PROPERTY = createErrorProperty();
private static final Set<PropertyDescriptor> ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY);
@NotNull
private static PropertyDescriptorImpl createErrorProperty() {
PropertyDescriptorImpl descriptor = PropertyDescriptorImpl.create(
ERROR_CLASS,
Annotations.Companion.getEMPTY(),
Modality.OPEN,
DescriptorVisibilities.PUBLIC,
true,
Name.special("<ERROR PROPERTY>"),
CallableMemberDescriptor.Kind.DECLARATION,
SourceElement.NO_SOURCE,
false, false, false, false, false, false
);
descriptor.setType(ERROR_PROPERTY_TYPE, Collections.<TypeParameterDescriptor>emptyList(), null, null,
Collections.<ReceiverParameterDescriptor>emptyList());
return descriptor;
}
@NotNull
private static SimpleFunctionDescriptor createErrorFunction(@NotNull ErrorScope ownerScope) {
ErrorSimpleFunctionDescriptorImpl function = new ErrorSimpleFunctionDescriptorImpl(ERROR_CLASS, ownerScope);
function.initialize(
null, null, Collections.<ReceiverParameterDescriptor>emptyList(),
Collections.<TypeParameterDescriptorImpl>emptyList(), // TODO
Collections.<ValueParameterDescriptor>emptyList(), // TODO
createErrorType("<ERROR FUNCTION RETURN TYPE>"),
Modality.OPEN,
DescriptorVisibilities.PUBLIC
);
return function;
}
@NotNull
public static SimpleType createErrorType(@NotNull String debugMessage) {
return createErrorTypeWithArguments(debugMessage, Collections.<TypeProjection>emptyList());
}
@NotNull
public static SimpleType createErrorTypeWithCustomDebugName(@NotNull String debugName) {
return createErrorTypeWithCustomConstructor(debugName, createErrorTypeConstructorWithCustomDebugName(debugName));
}
@NotNull
public static SimpleType createErrorTypeWithCustomConstructor(@NotNull String debugName, @NotNull TypeConstructor typeConstructor) {
return new ErrorType(typeConstructor, createErrorScope(debugName));
}
@NotNull
public static SimpleType createErrorTypeWithArguments(@NotNull String debugMessage, @NotNull List<TypeProjection> arguments) {
return new ErrorType(createErrorTypeConstructor(debugMessage), createErrorScope(debugMessage), arguments, false);
}
@NotNull
public static SimpleType createUnresolvedType(@NotNull String presentableName, @NotNull List<TypeProjection> arguments) {
return new UnresolvedType(presentableName, createErrorTypeConstructor(presentableName), createErrorScope(presentableName),
arguments, false);
}
@NotNull
public static TypeConstructor createErrorTypeConstructor(@NotNull String debugMessage) {
return createErrorTypeConstructorWithCustomDebugName("[ERROR : " + debugMessage + "]", ERROR_CLASS);
}
@NotNull
public static TypeConstructor createErrorTypeConstructorWithCustomDebugName(@NotNull String debugName) {
return createErrorTypeConstructorWithCustomDebugName(debugName, ERROR_CLASS);
}
@NotNull
private static TypeConstructor createErrorTypeConstructorWithCustomDebugName(
@NotNull final String debugName, @NotNull final ErrorClassDescriptor errorClass
) {
return new TypeConstructor() {
@NotNull
@Override
public List<TypeParameterDescriptor> getParameters() {
return emptyList();
}
@NotNull
@Override
public Collection<KotlinType> getSupertypes() {
return emptyList();
}
@Override
public boolean isFinal() {
return false;
}
@Override
public boolean isDenotable() {
return false;
}
@Nullable
@Override
public ClassifierDescriptor getDeclarationDescriptor() {
return errorClass;
}
@NotNull
@Override
public KotlinBuiltIns getBuiltIns() {
return DefaultBuiltIns.getInstance();
}
@Override
public String toString() {
return debugName;
}
@TypeRefinement
@Override
@NotNull
public TypeConstructor refine(@NotNull KotlinTypeRefiner kotlinTypeRefiner) {
return this;
}
};
}
public static boolean containsErrorType(@Nullable KotlinType type) {
if (type == null) return false;
if (KotlinTypeKt.isError(type)) return true;
for (TypeProjection projection : type.getArguments()) {
if (!projection.isStarProjection() && containsErrorType(projection.getType())) return true;
}
return false;
}
public static boolean isError(@Nullable DeclarationDescriptor candidate) {
if (candidate == null) return false;
return isErrorClass(candidate) || isErrorClass(candidate.getContainingDeclaration()) || candidate == ERROR_MODULE;
}
private static boolean isErrorClass(@Nullable DeclarationDescriptor candidate) {
return candidate instanceof ErrorClassDescriptor;
}
@NotNull
public static ModuleDescriptor getErrorModule() {
return ERROR_MODULE;
}
public static boolean isUninferredParameter(@Nullable KotlinType type) {
return type != null && type.getConstructor() instanceof UninferredParameterTypeConstructor;
}
public static boolean containsUninferredParameter(@Nullable KotlinType type) {
return TypeUtils.contains(type, new Function1<UnwrappedType, Boolean>() {
@Override
public Boolean invoke(UnwrappedType argumentType) {
return isUninferredParameter(argumentType);
}
});
}
@NotNull
public static KotlinType createUninferredParameterType(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
return createErrorTypeWithCustomConstructor("Scope for error type for not inferred parameter: " + typeParameterDescriptor.getName(),
new UninferredParameterTypeConstructor(typeParameterDescriptor));
}
public static class UninferredParameterTypeConstructor implements TypeConstructor {
private final TypeParameterDescriptor typeParameterDescriptor;
private final TypeConstructor errorTypeConstructor;
private UninferredParameterTypeConstructor(@NotNull TypeParameterDescriptor descriptor) {
typeParameterDescriptor = descriptor;
errorTypeConstructor = createErrorTypeConstructorWithCustomDebugName("CANT_INFER_TYPE_PARAMETER: " + descriptor.getName());
}
@NotNull
public TypeParameterDescriptor getTypeParameterDescriptor() {
return typeParameterDescriptor;
}
@NotNull
@Override
public List<TypeParameterDescriptor> getParameters() {
return errorTypeConstructor.getParameters();
}
@NotNull
@Override
public Collection<KotlinType> getSupertypes() {
return errorTypeConstructor.getSupertypes();
}
@Override
public boolean isFinal() {
return errorTypeConstructor.isFinal();
}
@Override
public boolean isDenotable() {
return errorTypeConstructor.isDenotable();
}
@Nullable
@Override
public ClassifierDescriptor getDeclarationDescriptor() {
return errorTypeConstructor.getDeclarationDescriptor();
}
@NotNull
@Override
public KotlinBuiltIns getBuiltIns() {
return DescriptorUtilsKt.getBuiltIns(typeParameterDescriptor);
}
@NotNull
@Override
public TypeConstructor refine(@NotNull KotlinTypeRefiner kotlinTypeRefiner) {
return this;
}
}
private ErrorUtils() {}
}
@@ -20,15 +20,18 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.error.ErrorUtils
class FunctionPlaceholders(private val builtIns: KotlinBuiltIns) {
fun createFunctionPlaceholderType(
argumentTypes: List<KotlinType>,
hasDeclaredArguments: Boolean
): KotlinType {
return ErrorUtils.createErrorTypeWithCustomConstructor(
"function placeholder type",
FunctionPlaceholderTypeConstructor(argumentTypes, hasDeclaredArguments, builtIns)
return ErrorUtils.createErrorType(
ErrorTypeKind.FUNCTION_PLACEHOLDER_TYPE,
FunctionPlaceholderTypeConstructor(argumentTypes, hasDeclaredArguments, builtIns),
argumentTypes.toString()
)
}
}
@@ -43,7 +46,8 @@ class FunctionPlaceholderTypeConstructor(
val hasDeclaredArguments: Boolean,
private val kotlinBuiltIns: KotlinBuiltIns
) : TypeConstructor {
private val errorTypeConstructor: TypeConstructor = ErrorUtils.createErrorTypeConstructorWithCustomDebugName("PLACEHOLDER_FUNCTION_TYPE" + argumentTypes)
private val errorTypeConstructor: TypeConstructor =
ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.FUNCTION_PLACEHOLDER_TYPE, argumentTypes.toString())
override fun getParameters(): List<TypeParameterDescriptor> {
return errorTypeConstructor.parameters
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.checker.StrictEqualityTypeChecker
import org.jetbrains.kotlin.types.error.ErrorType
import org.jetbrains.kotlin.types.model.FlexibleTypeMarker
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
@@ -28,6 +28,10 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.getKotlinTypeRefiner
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.error.ErrorScope
import org.jetbrains.kotlin.types.error.ErrorScopeKind
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.error.ThrowingScope
typealias RefinedTypeFactory = (KotlinTypeRefiner) -> SimpleType?
@@ -54,7 +58,9 @@ object KotlinTypeFactory {
refinerToUse
)
}
is TypeAliasDescriptor -> ErrorUtils.createErrorScope("Scope for abbreviation: ${descriptor.name}", true)
is TypeAliasDescriptor -> ErrorUtils.createErrorScope(
ErrorScopeKind.SCOPE_FOR_ABBREVIATION_TYPE, throwExceptions = true, descriptor.name.toString()
)
else -> {
if (constructor is IntersectionTypeConstructor) {
return constructor.createScopeForKotlinType()
@@ -192,7 +198,7 @@ object KotlinTypeFactory {
constructor,
emptyList(),
nullable,
ErrorUtils.createErrorScope("Scope for integer literal type", true)
ErrorUtils.createErrorScope(ErrorScopeKind.INTEGER_LITERAL_TYPE_SCOPE, throwExceptions = true, "unknown integer literal type")
)
}
@@ -220,7 +226,7 @@ private class SimpleTypeImpl(
}
init {
if (memberScope is ErrorUtils.ErrorScope) {
if (memberScope is ErrorScope && memberScope !is ThrowingScope) {
throw IllegalStateException("SimpleTypeImpl should not be created for error type: $memberScope\n$constructor")
}
}
@@ -5,10 +5,13 @@
package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
import org.jetbrains.kotlin.types.error.ErrorScopeKind
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.model.StubTypeMarker
import org.jetbrains.kotlin.types.error.ErrorUtils
class StubTypeForBuilderInference(
originalTypeVariable: NewTypeVariableConstructor,
@@ -18,7 +21,7 @@ class StubTypeForBuilderInference(
override fun materialize(newNullability: Boolean): AbstractStubType =
StubTypeForBuilderInference(originalTypeVariable, newNullability, constructor)
override val memberScope = originalTypeVariable.builtIns.anyType.memberScope
override val memberScope: MemberScope = originalTypeVariable.builtIns.anyType.memberScope
override fun toString(): String {
// BI means builder inference
@@ -54,7 +57,7 @@ class StubTypeForProvideDelegateReceiver(
}
abstract class AbstractStubType(val originalTypeVariable: NewTypeVariableConstructor, override val isMarkedNullable: Boolean) : SimpleType() {
override val memberScope = ErrorUtils.createErrorScope("Scope for stub type: $originalTypeVariable")
override val memberScope: MemberScope = ErrorUtils.createErrorScope(ErrorScopeKind.STUB_TYPE_SCOPE, originalTypeVariable.toString())
override val arguments: List<TypeProjection>
get() = emptyList()
@@ -75,6 +78,6 @@ abstract class AbstractStubType(val originalTypeVariable: NewTypeVariableConstru
companion object {
fun createConstructor(originalTypeVariable: NewTypeVariableConstructor) =
ErrorUtils.createErrorTypeConstructor("Constructor for stub type: $originalTypeVariable")
ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.STUB_TYPE, originalTypeVariable.toString())
}
}
@@ -8,10 +8,11 @@ package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.composeAnnotations
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.typeUtil.containsTypeAliasParameters
import org.jetbrains.kotlin.types.typeUtil.requiresTypeAliasExpansion
import org.jetbrains.kotlin.types.error.ErrorUtils
class TypeAliasExpander(
private val reportStrategy: TypeAliasExpansionReportStrategy,
@@ -188,7 +189,8 @@ class TypeAliasExpander(
reportStrategy.recursiveTypeAlias(typeDescriptor)
return TypeProjectionImpl(
Variance.INVARIANT,
ErrorUtils.createErrorType("Recursive type alias: ${typeDescriptor.name}")
ErrorUtils.createErrorType(
ErrorTypeKind.RECURSIVE_TYPE_ALIAS, typeDescriptor.name.toString())
)
}
@@ -28,6 +28,8 @@ import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructorKt;
import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor;
import org.jetbrains.kotlin.types.error.ErrorTypeKind;
import org.jetbrains.kotlin.types.error.ErrorUtils;
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
import org.jetbrains.kotlin.types.typesApproximation.CapturedTypeApproximationKt;
@@ -131,7 +133,7 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
try {
return unsafeSubstitute(new TypeProjectionImpl(howThisTypeIsUsed, type), null, 0).getType();
} catch (SubstitutionException e) {
return ErrorUtils.createErrorType(e.getMessage());
return ErrorUtils.createErrorType(ErrorTypeKind.UNABLE_TO_SUBSTITUTE_TYPE, e.getMessage());
}
}
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.FqNameUnsafe;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
@@ -25,13 +24,16 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner;
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor;
import org.jetbrains.kotlin.types.error.ErrorTypeKind;
import org.jetbrains.kotlin.types.error.ErrorUtils;
import org.jetbrains.kotlin.utils.SmartSet;
import java.util.*;
public class TypeUtils {
public static final SimpleType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE");
public static final SimpleType CANT_INFER_FUNCTION_PARAM_TYPE = ErrorUtils.createErrorType("Cannot be inferred");
public static final SimpleType DONT_CARE = ErrorUtils.createErrorType(ErrorTypeKind.DONT_CARE);
public static final SimpleType CANNOT_INFER_FUNCTION_PARAM_TYPE =
ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_LAMBDA_PARAMETER_TYPE);
public static class SpecialType extends DelegatingSimpleType {
private final String name;
@@ -207,7 +209,7 @@ public class TypeUtils {
Function1<KotlinTypeRefiner, SimpleType> refinedTypeFactory
) {
if (ErrorUtils.isError(classifierDescriptor)) {
return ErrorUtils.createErrorType("Unsubstituted type for " + classifierDescriptor);
return ErrorUtils.createErrorType(ErrorTypeKind.UNABLE_TO_SUBSTITUTE_TYPE, classifierDescriptor.toString());
}
TypeConstructor typeConstructor = classifierDescriptor.getTypeConstructor();
return makeUnsubstitutedType(typeConstructor, unsubstitutedMemberScope, refinedTypeFactory);
@@ -25,10 +25,14 @@ import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.*
import org.jetbrains.kotlin.types.error.ErrorType
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
import org.jetbrains.kotlin.types.model.TypeArgumentMarker
import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import org.jetbrains.kotlin.types.error.ErrorUtils
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
enum class TypeNullability {
NOT_NULL,
@@ -399,3 +403,11 @@ fun KotlinType.isStubTypeForBuilderInference(): Boolean =
this is StubTypeForBuilderInference || isDefNotNullStubType<StubTypeForBuilderInference>()
private inline fun <reified S : AbstractStubType> KotlinType.isDefNotNullStubType() = this is DefinitelyNotNullType && this.original is S
@OptIn(ExperimentalContracts::class)
fun isUnresolvedType(type: KotlinType): Boolean {
contract {
returns(true) implies (type is ErrorType)
}
return type is ErrorType && type.kind.isUnresolved
}
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.isInlineClass
import org.jetbrains.kotlin.resolve.substitutedUnderlyingType
import org.jetbrains.kotlin.resolve.unsubstitutedUnderlyingType
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.types.typeUtil.*
import org.jetbrains.kotlin.utils.addIfNotNull
@@ -33,6 +34,7 @@ import org.jetbrains.kotlin.types.typeUtil.isSignedOrUnsignedNumberType as class
import org.jetbrains.kotlin.types.typeUtil.isStubTypeForVariableInSubtyping as isSimpleTypeStubTypeForVariableInSubtyping
import org.jetbrains.kotlin.types.typeUtil.isStubTypeForBuilderInference as isSimpleTypeStubTypeForBuilderInference
import org.jetbrains.kotlin.types.typeUtil.isStubType as isSimpleTypeStubType
import org.jetbrains.kotlin.types.error.ErrorUtils
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSystemCommonBackendContext {
override fun TypeConstructorMarker.isDenotable(): Boolean {
@@ -87,12 +89,12 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker {
require(this is TypeConstructor && ErrorUtils.isError(declarationDescriptor), this::errorMessage)
return ErrorUtils.createErrorType("from type constructor(${toString()})")
return ErrorUtils.createErrorType(ErrorTypeKind.RESOLUTION_ERROR_TYPE, "from type constructor $this")
}
override fun KotlinTypeMarker.isUninferredParameter(): Boolean {
require(this is KotlinType, this::errorMessage)
return ErrorUtils.isUninferredParameter(this)
return ErrorUtils.isUninferredTypeVariable(this)
}
override fun SimpleTypeMarker.isStubType(): Boolean {
@@ -698,12 +700,11 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
}
override fun createErrorType(debugName: String): SimpleTypeMarker {
return ErrorUtils.createErrorType(debugName)
return ErrorUtils.createErrorType(ErrorTypeKind.RESOLUTION_ERROR_TYPE, debugName)
}
override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker {
require(constructor is TypeConstructor, constructor::errorMessage)
return ErrorUtils.createErrorTypeWithCustomConstructor(debugName, constructor)
override fun createUninferredType(constructor: TypeConstructorMarker): KotlinTypeMarker {
return ErrorUtils.createErrorType(ErrorTypeKind.UNINFERRED_TYPE_VARIABLE, constructor as TypeConstructor, constructor.toString())
}
override fun TypeConstructorMarker.isCapturedTypeConstructor(): Boolean {
@@ -18,8 +18,10 @@ package org.jetbrains.kotlin.types.checker
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import java.util.*
import kotlin.collections.LinkedHashSet
import org.jetbrains.kotlin.types.error.ErrorUtils
fun intersectWrappedTypes(types: Collection<KotlinType>) = intersectTypes(types.map { it.unwrap() })
@@ -46,7 +48,7 @@ fun intersectTypes(types: List<UnwrappedType>): UnwrappedType {
}
}
if (hasErrorType) {
return ErrorUtils.createErrorType("Intersection of error types: $types")
return ErrorUtils.createErrorType(ErrorTypeKind.INTERSECTION_OF_ERROR_TYPES, types.toString())
}
if (!hasFlexibleTypes) {
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.types.checker
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructor
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.*
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.types.FlexibleTypeBoundsChecker.areTypesMayBeLowerAn
import org.jetbrains.kotlin.types.model.CaptureStatus
import org.jetbrains.kotlin.types.model.CapturedTypeMarker
import org.jetbrains.kotlin.types.TypeRefinement
import org.jetbrains.kotlin.types.error.ErrorScopeKind
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.types.typeUtil.builtIns
@@ -210,7 +211,7 @@ class NewCapturedType(
override val arguments: List<TypeProjection> get() = listOf()
override val memberScope: MemberScope // todo what about foo().bar() where foo() return captured type?
get() = ErrorUtils.createErrorScope("No member resolution should be done on captured type!", true)
get() = ErrorUtils.createErrorScope(ErrorScopeKind.CAPTURED_TYPE_SCOPE, throwExceptions = true)
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
NewCapturedType(captureStatus, constructor, lowerType, newAttributes, isMarkedNullable, isProjectionNotNull)
@@ -0,0 +1,49 @@
/*
* 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.types.error
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.TypeProjection
import org.jetbrains.kotlin.types.TypeSubstitution
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
class ErrorClassDescriptor(name: Name) : ClassDescriptorImpl(
ErrorUtils.errorModule, name, Modality.OPEN, ClassKind.CLASS, emptyList(), SourceElement.NO_SOURCE, false, LockBasedStorageManager.NO_LOCKS
) {
init {
val errorConstructor = ClassConstructorDescriptorImpl.create(this, Annotations.EMPTY, true, SourceElement.NO_SOURCE)
.apply {
initialize(
emptyList(),
DescriptorVisibilities.INTERNAL
)
}
val memberScope = ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_CLASS, errorConstructor.name.toString(), "")
errorConstructor.returnType = ErrorType(
ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.ERROR_CLASS),
memberScope,
ErrorTypeKind.ERROR_CLASS
)
initialize(memberScope, setOf(errorConstructor), errorConstructor)
}
override fun substitute(substitutor: TypeSubstitutor): ClassDescriptor = this
override fun getMemberScope(typeArguments: List<TypeProjection>, kotlinTypeRefiner: KotlinTypeRefiner): MemberScope =
ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_CLASS, name.toString(), typeArguments.toString())
override fun getMemberScope(typeSubstitution: TypeSubstitution, kotlinTypeRefiner: KotlinTypeRefiner): MemberScope =
ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_CLASS, name.toString(), typeSubstitution.toString())
override fun toString(): String = name.asString()
}
@@ -0,0 +1,16 @@
/*
* 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.types.error
enum class ErrorEntity(val debugText: String) {
ERROR_CLASS("<Error class: %s>"),
ERROR_FUNCTION("<Error function>"),
ERROR_SCOPE("<Error scope>"),
ERROR_MODULE("<Error module>"),
ERROR_PROPERTY("<Error property>"),
ERROR_TYPE("[Error type: %s]"),
PARENT_OF_ERROR_SCOPE("<Fake parent for error lexical scope>"),
}
@@ -0,0 +1,88 @@
/*
* Copyright 2010-2018 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.types.error
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.Annotations.Companion.EMPTY
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeSubstitution
class ErrorFunctionDescriptor(containingDeclaration: ClassDescriptor) :
SimpleFunctionDescriptorImpl(
containingDeclaration, null, EMPTY, Name.special(ErrorEntity.ERROR_FUNCTION.debugText), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE
) {
init {
initialize(
null, null, emptyList(), emptyList(), emptyList(),
ErrorUtils.createErrorType(ErrorTypeKind.RETURN_TYPE_FOR_FUNCTION), Modality.OPEN, DescriptorVisibilities.PUBLIC
)
}
override fun createSubstitutedCopy(
newOwner: DeclarationDescriptor,
original: FunctionDescriptor?,
kind: CallableMemberDescriptor.Kind,
newName: Name?,
annotations: Annotations,
source: SourceElement
): FunctionDescriptorImpl = this
override fun copy(
newOwner: DeclarationDescriptor,
modality: Modality,
visibility: DescriptorVisibility,
kind: CallableMemberDescriptor.Kind,
copyOverrides: Boolean
): SimpleFunctionDescriptor = this
override fun newCopyBuilder(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> =
object : FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> {
override fun setOwner(owner: DeclarationDescriptor): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setModality(modality: Modality): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setVisibility(visibility: DescriptorVisibility): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setKind(kind: CallableMemberDescriptor.Kind): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setCopyOverrides(copyOverrides: Boolean): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setName(name: Name): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setSubstitution(substitution: TypeSubstitution): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setValueParameters(
parameters: List<ValueParameterDescriptor>
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun <V> putUserData(userDataKey: CallableDescriptor.UserDataKey<V>,
value: V
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setTypeParameters(
parameters: List<TypeParameterDescriptor>
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setReturnType(type: KotlinType): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setContextReceiverParameters(
contextReceiverParameters: List<ReceiverParameterDescriptor>
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setExtensionReceiverParameter(
extensionReceiverParameter: ReceiverParameterDescriptor?
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setDispatchReceiverParameter(
dispatchReceiverParameter: ReceiverParameterDescriptor?
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setOriginal(original: CallableMemberDescriptor?): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setSignatureChange(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setPreserveSourceElement(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setDropOriginalInContainingParts(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setHiddenToOvercomeSignatureClash(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setHiddenForResolutionEverywhereBesideSupercalls(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun setAdditionalAnnotations(
additionalAnnotations: Annotations
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor?> = this
override fun build(): SimpleFunctionDescriptor = this@ErrorFunctionDescriptor
}
override fun isSuspend(): Boolean = false
override fun <V> getUserData(key: CallableDescriptor.UserDataKey<V>): V? = null
override fun setOverriddenDescriptors(overriddenDescriptors: Collection<CallableMemberDescriptor?>) {}
}
@@ -0,0 +1,36 @@
/*
* 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.types.error
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.platform.TargetPlatform
object ErrorModuleDescriptor : ModuleDescriptor {
override val stableName: Name = Name.special(ErrorEntity.ERROR_MODULE.debugText)
override val platform: TargetPlatform? = null
override val allDependencyModules: List<ModuleDescriptor> = emptyList()
override val expectedByModules: List<ModuleDescriptor> = emptyList()
override val allExpectedByModules: Set<ModuleDescriptor> = emptySet()
override val annotations: Annotations get() = Annotations.EMPTY
override val builtIns: KotlinBuiltIns = DefaultBuiltIns.Instance
override val isValid: Boolean = false
override fun <T> getCapability(capability: ModuleCapability<T>): T? = null
override fun getSubPackagesOf(fqName: FqName, nameFilter: Function1<Name, Boolean>): Collection<FqName> = emptyList()
override fun getName(): Name = stableName
override fun getPackage(fqName: FqName): PackageViewDescriptor = throw IllegalStateException("Should not be called!")
override fun getOriginal(): DeclarationDescriptor = this
override fun getContainingDeclaration(): DeclarationDescriptor? = null
override fun shouldSeeInternalsOf(targetModule: ModuleDescriptor): Boolean = false
override fun assertValid() = throw InvalidModuleException("ERROR_MODULE is not a valid module")
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R? = null
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>) {}
}
@@ -0,0 +1,22 @@
/*
* 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.types.error
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.name.Name
class ErrorPropertyDescriptor : PropertyDescriptor by (
PropertyDescriptorImpl.create(
ErrorUtils.errorClass, Annotations.EMPTY, Modality.OPEN,
DescriptorVisibilities.PUBLIC, true, Name.special(ErrorEntity.ERROR_PROPERTY.debugText),
CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE,
false, false, false, false, false, false
).apply {
setType(ErrorUtils.errorPropertyType, emptyList(), null, null, emptyList())
}
)
@@ -0,0 +1,46 @@
/*
* 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.types.error
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.utils.Printer
open class ErrorScope(val kind: ErrorScopeKind, vararg formatParams: String) : MemberScope {
protected val debugMessage = kind.debugMessage.format(*formatParams)
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor =
ErrorClassDescriptor(Name.special(ErrorEntity.ERROR_CLASS.debugText.format(name)))
override fun getContributedClassifierIncludeDeprecated(
name: Name, location: LookupLocation
): DescriptorWithDeprecation<ClassifierDescriptor>? = null
override fun getContributedVariables(name: Name, location: LookupLocation): Set<PropertyDescriptor> = ErrorUtils.errorPropertyGroup
override fun getContributedFunctions(name: Name, location: LookupLocation): Set<SimpleFunctionDescriptor> =
setOf(ErrorFunctionDescriptor(ErrorUtils.errorClass))
override fun getContributedDescriptors(
kindFilter: DescriptorKindFilter, nameFilter: Function1<Name, Boolean>
): Collection<DeclarationDescriptor> = emptyList()
override fun getFunctionNames(): Set<Name> = emptySet()
override fun getVariableNames(): Set<Name> = emptySet()
override fun getClassifierNames(): Set<Name> = emptySet()
override fun recordLookup(name: Name, location: LookupLocation) {}
override fun definitelyDoesNotContainName(name: Name): Boolean = false
override fun toString(): String = "ErrorScope{$debugMessage}"
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName, ": ", debugMessage)
}
}
@@ -0,0 +1,23 @@
/*
* 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.types.error
enum class ErrorScopeKind(val debugMessage: String) {
/* Special type scopes */
CAPTURED_TYPE_SCOPE("No member resolution should be done on captured type, it used only during constraint system resolution"),
INTEGER_LITERAL_TYPE_SCOPE("Scope for integer literal type (%s)"),
ERASED_RECEIVER_TYPE_SCOPE("Error scope for erased receiver type"),
SCOPE_FOR_ABBREVIATION_TYPE("Scope for abbreviation %s"),
STUB_TYPE_SCOPE("Scope for stub type %s"),
NON_CLASSIFIER_SUPER_TYPE_SCOPE("A scope for common supertype which is not a normal classifier"),
ERROR_TYPE_SCOPE("Scope for error type %s"),
UNSUPPORTED_TYPE_SCOPE("Scope for unsupported type %s"),
/* Other scopes */
SCOPE_FOR_ERROR_CLASS("Error scope for class %s with arguments: %s"),
SCOPE_FOR_ERROR_RESOLUTION_CANDIDATE("Error resolution candidate for call %s"),
;
}
@@ -1,206 +0,0 @@
/*
* Copyright 2010-2018 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.types.error;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.types.ErrorUtils;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.TypeSubstitution;
import java.util.Collection;
import java.util.List;
public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorImpl {
// used for diagnostic only
@SuppressWarnings({"UnusedDeclaration", "FieldCanBeLocal"})
private final ErrorUtils.ErrorScope ownerScope;
public ErrorSimpleFunctionDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull ErrorUtils.ErrorScope ownerScope) {
super(containingDeclaration, null, Annotations.Companion.getEMPTY(), Name.special("<ERROR FUNCTION>"), Kind.DECLARATION, SourceElement.NO_SOURCE);
this.ownerScope = ownerScope;
}
@NotNull
@Override
protected FunctionDescriptorImpl createSubstitutedCopy(
@NotNull DeclarationDescriptor newOwner,
@Nullable FunctionDescriptor original,
@NotNull Kind kind,
@Nullable Name newName,
@NotNull Annotations annotations,
@NotNull SourceElement source
) {
return this;
}
@NotNull
@Override
public SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, DescriptorVisibility visibility, Kind kind, boolean copyOverrides) {
return this;
}
@NotNull
@Override
public CopyBuilder<? extends SimpleFunctionDescriptor> newCopyBuilder() {
return new CopyBuilder<SimpleFunctionDescriptor>() {
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setOwner(@NotNull DeclarationDescriptor owner) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setModality(@NotNull Modality modality) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setVisibility(@NotNull DescriptorVisibility visibility) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setKind(@NotNull Kind kind) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setCopyOverrides(boolean copyOverrides) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setName(@NotNull Name name) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setValueParameters(@NotNull List<ValueParameterDescriptor> parameters) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setSubstitution(@NotNull TypeSubstitution substitution) {
return this;
}
@NotNull
@Override
public <V> CopyBuilder<SimpleFunctionDescriptor> putUserData(
@NotNull UserDataKey<V> userDataKey,
V value
) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setTypeParameters(@NotNull List<TypeParameterDescriptor> parameters) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setReturnType(@NotNull KotlinType type) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setContextReceiverParameters(@NotNull List<ReceiverParameterDescriptor> contextReceiverParameters) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setExtensionReceiverParameter(@Nullable ReceiverParameterDescriptor extensionReceiverParameter) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setDispatchReceiverParameter(@Nullable ReceiverParameterDescriptor dispatchReceiverParameter) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setOriginal(@Nullable CallableMemberDescriptor original) {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setSignatureChange() {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setPreserveSourceElement() {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setDropOriginalInContainingParts() {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setHiddenToOvercomeSignatureClash() {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setHiddenForResolutionEverywhereBesideSupercalls() {
return this;
}
@NotNull
@Override
public CopyBuilder<SimpleFunctionDescriptor> setAdditionalAnnotations(@NotNull Annotations additionalAnnotations) {
return this;
}
@Nullable
@Override
public SimpleFunctionDescriptor build() {
return ErrorSimpleFunctionDescriptorImpl.this;
}
};
}
@Override
public boolean isSuspend() {
return false;
}
@Override
public <V> V getUserData(UserDataKey<V> key) {
return null;
}
@Override
public void setOverriddenDescriptors(@NotNull Collection<? extends CallableMemberDescriptor> overriddenDescriptors) {
// nop
}
}
@@ -0,0 +1,32 @@
/*
* 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.types.error
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
class ErrorType @JvmOverloads internal constructor(
override val constructor: TypeConstructor,
override val memberScope: MemberScope,
val kind: ErrorTypeKind,
override val arguments: List<TypeProjection> = emptyList(),
override val isMarkedNullable: Boolean = false,
private vararg val formatParams: String
) : SimpleType() {
val debugMessage = String.format(kind.debugMessage, *formatParams)
override val attributes: TypeAttributes
get() = TypeAttributes.Empty
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType = this
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType =
ErrorType(constructor, memberScope, kind, arguments, newNullability, *formatParams)
@TypeRefinement
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) = this
}
@@ -0,0 +1,31 @@
/*
* 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.types.error
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.TypeRefinement
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
class ErrorTypeConstructor(val kind: ErrorTypeKind, private vararg val formatParams: String) : TypeConstructor {
private val debugText = ErrorEntity.ERROR_TYPE.debugText.format(kind.debugMessage.format(*formatParams))
fun getParam(i: Int): String = formatParams[i]
override fun getParameters(): List<TypeParameterDescriptor> = emptyList()
override fun getSupertypes(): Collection<KotlinType> = emptyList()
override fun isFinal(): Boolean = false
override fun isDenotable(): Boolean = false
override fun getDeclarationDescriptor(): ClassifierDescriptor = ErrorUtils.errorClass
override fun getBuiltIns(): KotlinBuiltIns = DefaultBuiltIns.Instance
override fun toString(): String = debugText
@TypeRefinement
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner): TypeConstructor = this
}
@@ -0,0 +1,121 @@
/*
* 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.types.error
enum class ErrorTypeKind(val debugMessage: String, val isUnresolved: Boolean = false) {
/* Unresolved types */
UNRESOLVED_TYPE("Unresolved type for %s", true),
UNRESOLVED_TYPE_PARAMETER_TYPE("Unresolved type parameter type", true),
UNRESOLVED_CLASS_TYPE("Unresolved class %s", true),
UNRESOLVED_JAVA_CLASS("Unresolved java class %s", true),
UNRESOLVED_DECLARATION("Unresolved declaration %s", true),
UNRESOLVED_KCLASS_CONSTANT_VALUE("Unresolved type for %s (arrayDimensions=%s)", true),
UNRESOLVED_TYPE_ALIAS("Unresolved type alias %s"),
/* Return types */
RETURN_TYPE("Return type for %s cannot be resolved"),
RETURN_TYPE_FOR_FUNCTION("Return type for function cannot be resolved"),
RETURN_TYPE_FOR_PROPERTY("Return type for property %s cannot be resolved"),
RETURN_TYPE_FOR_CONSTRUCTOR("Return type for constructor %s cannot be resolved"),
IMPLICIT_RETURN_TYPE_FOR_FUNCTION("Implicit return type for function %s cannot be resolved"),
IMPLICIT_RETURN_TYPE_FOR_PROPERTY("Implicit return type for property %s cannot be resolved"),
IMPLICIT_RETURN_TYPE_FOR_PROPERTY_ACCESSOR("Implicit return type for property accessor %s cannot be resolved"),
ERROR_TYPE_FOR_DESTRUCTURING_COMPONENT("%s() return type"),
/* Recursion or cyclic */
RECURSIVE_TYPE("Recursive type"),
RECURSIVE_TYPE_ALIAS("Recursive type alias %s"),
RECURSIVE_ANNOTATION_TYPE("Recursive annotation's type"),
CYCLIC_UPPER_BOUNDS("Cyclic upper bounds"),
CYCLIC_SUPERTYPES("Cyclic supertypes"),
/* Resolution and type inference */
UNINFERRED_LAMBDA_CONTEXT_RECEIVER_TYPE("Cannot infer a lambda context receiver type"),
UNINFERRED_LAMBDA_PARAMETER_TYPE("Cannot infer a lambda parameter type"),
UNINFERRED_TYPE_VARIABLE("Cannot infer a type variable %s"),
RESOLUTION_ERROR_TYPE("Resolution error type (%s)"),
ERROR_EXPECTED_TYPE("Error expected type"),
ERROR_DATA_FLOW_TYPE("Error type for data flow"),
ERROR_WHILE_RECONSTRUCTING_BARE_TYPE("Failed to reconstruct type %s"),
UNABLE_TO_SUBSTITUTE_TYPE("Unable to substitute type (%s)"),
/* Special internal error types */
DONT_CARE("Special DONT_CARE type"),
STUB_TYPE("Stub type %s"),
FUNCTION_PLACEHOLDER_TYPE("Function placeholder type (arguments: %s)"),
TYPE_FOR_RESULT("Stubbed 'Result' type"),
TYPE_FOR_COMPILER_EXCEPTION("Error type for a compiler exception while analyzing %s"),
/* Inconsistent types */
ERROR_FLEXIBLE_TYPE("Error java flexible type with id %s. (%s..%s)"),
ERROR_RAW_TYPE("Error raw type %s"),
TYPE_WITH_MISMATCHED_TYPE_ARGUMENTS_AND_PARAMETERS("Inconsistent type %s (parameters.size = %s, arguments.size = %s)"),
ILLEGAL_TYPE_RANGE_FOR_DYNAMIC("Illegal type range for dynamic type %s..%s"),
/* Deserialization */
CANNOT_LOAD_DESERIALIZE_TYPE_PARAMETER("Unknown type parameter %s. Please try recompiling module containing \"%s\""),
CANNOT_LOAD_DESERIALIZE_TYPE_PARAMETER_BY_NAME("Couldn't deserialize type parameter %s in %s"),
INCONSISTENT_SUSPEND_FUNCTION("Inconsistent suspend function type in metadata with constructor %s"),
UNEXPECTED_FLEXIBLE_TYPE_ID("Unexpected id of a flexible type %s. (%s..%s)"),
UNKNOWN_TYPE("Unknown type"),
/* Stubs for not specified types */
NO_TYPE_SPECIFIED("No type specified for %s"),
NO_TYPE_FOR_LOOP_RANGE("Loop range has no type"),
NO_TYPE_FOR_LOOP_PARAMETER("Loop parameter has no type"),
MISSED_TYPE_FOR_PARAMETER("Missed a type for a value parameter %s"),
MISSED_TYPE_ARGUMENT_FOR_TYPE_PARAMETER("Missed a type argument for a type parameter %s"),
/* Illegal type usages */
PARSE_ERROR_ARGUMENT("Error type for parse error argument %s"),
STAR_PROJECTION_IN_CALL("Error type for star projection directly passing as a call type argument"),
PROHIBITED_DYNAMIC_TYPE("Dynamic type in a not allowed context"),
NOT_ANNOTATION_TYPE_IN_ANNOTATION_CONTEXT("Not an annotation type %s in the annotation context"),
UNIT_RETURN_TYPE_FOR_INC_DEC("Unit type returned by inc or dec"),
RETURN_NOT_ALLOWED("Return not allowed"),
/* Plugin related */
UNRESOLVED_PARCEL_TYPE("Unresolved 'Parcel' type", true),
KAPT_ERROR_TYPE("Kapt error type"),
SYNTHETIC_ELEMENT_ERROR_TYPE("Error type for synthetic element"),
AD_HOC_ERROR_TYPE_FOR_LIGHTER_CLASSES_RESOLVE("Error type in ad hoc resolve for lighter classes"),
/* Expressions related types */
ERROR_EXPRESSION_TYPE("Error expression type"),
ERROR_RECEIVER_TYPE("Error receiver type for %s"),
ERROR_CONSTANT_VALUE("Error constant value %s"),
EMPTY_CALLABLE_REFERENCE("Empty callable reference"),
UNSUPPORTED_CALLABLE_REFERENCE_TYPE("Unsupported callable reference type %s"),
TYPE_FOR_DELEGATION("Error delegation type for %s"),
/* Declaration related types */
UNAVAILABLE_TYPE_FOR_DECLARATION("Type is unavailable for declaration %s"),
ERROR_TYPE_PARAMETER("Error type parameter"),
ERROR_TYPE_PROJECTION("Error type projection"),
ERROR_SUPER_TYPE("Error super type"),
SUPER_TYPE_FOR_ERROR_TYPE("Supertype of error type %s"),
ERROR_PROPERTY_TYPE("Error property type"),
ERROR_CLASS("Error class"),
TYPE_FOR_ERROR_TYPE_CONSTRUCTOR("Type for error type constructor (%s)"),
INTERSECTION_OF_ERROR_TYPES("Intersection of error types %s"),
CANNOT_COMPUTE_ERASED_BOUND("Cannot compute erased upper bound of a type parameter %s"),
/* Couldn't load a type */
NOT_FOUND_UNSIGNED_TYPE("Unsigned type %s not found"),
ERROR_ENUM_TYPE("Not found the corresponding enum class for given enum entry %s.%s"),
NO_RECORDED_TYPE("Not found recorded type for %s"),
NOT_FOUND_DESCRIPTOR_FOR_FUNCTION("Descriptor not found for function %s"),
NOT_FOUND_DESCRIPTOR_FOR_CLASS("Cannot build class type, descriptor not found for builder %s"),
NOT_FOUND_DESCRIPTOR_FOR_TYPE_PARAMETER("Cannot build type parameter type, descriptor not found for builder %s"),
UNMAPPED_ANNOTATION_TARGET_TYPE("Type for unmapped Java annotation target to Kotlin one"), // java.lang.annotation.Target -> kotlin.annotation.Target
UNKNOWN_ARRAY_ELEMENT_TYPE_OF_ANNOTATION_ARGUMENT("Unknown type for an array element of a java annotation argument"),
NOT_FOUND_FQNAME_FOR_JAVA_ANNOTATION("No fqName for annotation %s"),
NOT_FOUND_FQNAME("No fqName for %s"),
/* Other error types */
TYPE_FOR_GENERATED_ERROR_EXPRESSION("Type for generated error expression"),
;
}
@@ -0,0 +1,102 @@
/*
* 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.types.error
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.contains
object ErrorUtils {
val errorModule: ModuleDescriptor = ErrorModuleDescriptor
val errorClass: ErrorClassDescriptor = ErrorClassDescriptor(Name.special(ErrorEntity.ERROR_CLASS.debugText.format("unknown class")))
// Do not move it into AbstractTypeConstructor.Companion because of cycle in initialization(see KT-13264)
val errorTypeForLoopInSupertypes: KotlinType = createErrorType(ErrorTypeKind.CYCLIC_SUPERTYPES)
val errorPropertyType: KotlinType = createErrorType(ErrorTypeKind.ERROR_PROPERTY_TYPE)
private val errorProperty: PropertyDescriptor = ErrorPropertyDescriptor()
val errorPropertyGroup: Set<PropertyDescriptor> = setOf(errorProperty)
/**
* @return true if any of the types referenced in parameter types (including type parameters and extension receiver) of the function
* is an error type. Does not check the return type of the function.
*/
fun containsErrorTypeInParameters(function: FunctionDescriptor): Boolean {
val receiverParameter = function.extensionReceiverParameter
if (receiverParameter != null && containsErrorType(receiverParameter.type))
return true
for (parameter in function.valueParameters) {
if (containsErrorType(parameter.type))
return true
}
for (parameter in function.typeParameters) {
for (upperBound in parameter.upperBounds) {
if (containsErrorType(upperBound))
return true
}
}
return false
}
@JvmStatic
fun createErrorScope(kind: ErrorScopeKind, vararg formatParams: String): ErrorScope =
createErrorScope(kind, throwExceptions = false, *formatParams)
@JvmStatic
fun createErrorScope(kind: ErrorScopeKind, throwExceptions: Boolean, vararg formatParams: String): ErrorScope =
if (throwExceptions) ThrowingScope(kind, *formatParams) else ErrorScope(kind, *formatParams)
@JvmStatic
fun createErrorType(kind: ErrorTypeKind, vararg formatParams: String): ErrorType =
createErrorTypeWithArguments(kind, emptyList(), *formatParams)
fun createErrorType(kind: ErrorTypeKind, typeConstructor: TypeConstructor, vararg formatParams: String): ErrorType =
createErrorTypeWithArguments(kind, emptyList(), typeConstructor, *formatParams)
fun createErrorTypeWithArguments(kind: ErrorTypeKind, arguments: List<TypeProjection>, vararg formatParams: String): ErrorType =
createErrorTypeWithArguments(kind, arguments, createErrorTypeConstructor(kind, *formatParams), *formatParams)
fun createErrorTypeWithArguments(
kind: ErrorTypeKind,
arguments: List<TypeProjection>,
typeConstructor: TypeConstructor,
vararg formatParams: String
): ErrorType = ErrorType(
typeConstructor, createErrorScope(ErrorScopeKind.ERROR_TYPE_SCOPE, typeConstructor.toString()),
kind, arguments, isMarkedNullable = false, *formatParams
)
fun createErrorTypeConstructor(kind: ErrorTypeKind, vararg formatParams: String): ErrorTypeConstructor =
ErrorTypeConstructor(kind, *formatParams)
fun containsErrorType(type: KotlinType?): Boolean {
if (type == null) return false
if (type.isError) return true
for (projection in type.arguments) {
if (!projection.isStarProjection && containsErrorType(projection.type))
return true
}
return false
}
@JvmStatic
fun isError(candidate: DeclarationDescriptor?): Boolean =
candidate != null && (isErrorClass(candidate) || isErrorClass(candidate.containingDeclaration) || candidate === errorModule)
private fun isErrorClass(candidate: DeclarationDescriptor?): Boolean = candidate is ErrorClassDescriptor
@JvmStatic
fun isUninferredTypeVariable(type: KotlinType?): Boolean {
if (type == null) return false
val constructor = type.constructor
return constructor is ErrorTypeConstructor && constructor.kind == ErrorTypeKind.UNINFERRED_TYPE_VARIABLE
}
fun containsUninferredTypeVariable(type: KotlinType): Boolean = type.contains(::isUninferredTypeVariable)
}
@@ -0,0 +1,41 @@
/*
* 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.types.error
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.utils.Printer
class ThrowingScope(kind: ErrorScopeKind, vararg formatParams: String) : ErrorScope(kind, *formatParams) {
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor =
throw IllegalStateException("$debugMessage, required name: $name")
override fun getContributedClassifierIncludeDeprecated(
name: Name, location: LookupLocation
): DescriptorWithDeprecation<ClassifierDescriptor> = throw IllegalStateException("$debugMessage, required name: $name")
override fun getContributedVariables(name: Name, location: LookupLocation): Set<PropertyDescriptor> =
throw IllegalStateException("$debugMessage, required name: $name")
override fun getContributedFunctions(name: Name, location: LookupLocation): Set<SimpleFunctionDescriptor> =
throw IllegalStateException("$debugMessage, required name: $name")
override fun getContributedDescriptors(
kindFilter: DescriptorKindFilter, nameFilter: Function1<Name, Boolean>
): Collection<DeclarationDescriptor> = throw IllegalStateException(debugMessage)
override fun getFunctionNames(): Set<Name> = throw IllegalStateException()
override fun getVariableNames(): Set<Name> = throw IllegalStateException()
override fun getClassifierNames(): Set<Name> = throw IllegalStateException()
override fun recordLookup(name: Name, location: LookupLocation) = throw IllegalStateException()
override fun definitelyDoesNotContainName(name: Name): Boolean = false
override fun toString(): String = "ThrowingScope{$debugMessage}"
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName, ": ", debugMessage)
}
}
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.constants.*
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
class AnnotationDeserializer(private val module: ModuleDescriptor, private val notFoundClasses: NotFoundClasses) {
@@ -18,6 +18,8 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotations
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedTypeParameterDescriptor
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.typeUtil.builtIns
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.util.*
@@ -89,7 +91,7 @@ class TypeDeserializer(
val constructor = typeConstructor(proto)
if (ErrorUtils.isError(constructor.declarationDescriptor)) {
return ErrorUtils.createErrorTypeWithCustomConstructor(constructor.toString(), constructor)
return ErrorUtils.createErrorType(ErrorTypeKind.TYPE_FOR_ERROR_TYPE_CONSTRUCTOR, constructor, constructor.toString())
}
val annotations = DeserializedAnnotations(c.storageManager) {
@@ -160,16 +162,18 @@ class TypeDeserializer(
proto.hasTypeParameter() ->
loadTypeParameter(proto.typeParameter)
?: return ErrorUtils.createErrorTypeConstructor(
"Unknown type parameter ${proto.typeParameter}. Please try recompiling module containing \"$containerPresentableName\""
ErrorTypeKind.CANNOT_LOAD_DESERIALIZE_TYPE_PARAMETER, proto.typeParameter.toString(), containerPresentableName
)
proto.hasTypeParameterName() -> {
val name = c.nameResolver.getString(proto.typeParameterName)
ownTypeParameters.find { it.name.asString() == name }
?: return ErrorUtils.createErrorTypeConstructor("Deserialized type parameter $name in ${c.containingDeclaration}")
?: return ErrorUtils.createErrorTypeConstructor(
ErrorTypeKind.CANNOT_LOAD_DESERIALIZE_TYPE_PARAMETER_BY_NAME, name, c.containingDeclaration.toString()
)
}
proto.hasTypeAliasName() ->
typeAliasDescriptors(proto.typeAliasName) ?: notFoundClass(proto.typeAliasName)
else -> return ErrorUtils.createErrorTypeConstructor("Unknown type")
else -> return ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.UNKNOWN_TYPE)
}
return classifier.typeConstructor
}
@@ -199,8 +203,7 @@ class TypeDeserializer(
else -> null
}
return result ?: ErrorUtils.createErrorTypeWithArguments(
"Bad suspend function in metadata with constructor: $functionTypeConstructor",
arguments
ErrorTypeKind.INCONSISTENT_SUSPEND_FUNCTION, arguments, functionTypeConstructor
)
}
@@ -291,7 +294,8 @@ class TypeDeserializer(
}
val projection = ProtoEnumFlags.variance(typeArgumentProto.projection)
val type = typeArgumentProto.type(c.typeTable) ?: return TypeProjectionImpl(ErrorUtils.createErrorType("No type recorded"))
val type = typeArgumentProto.type(c.typeTable)
?: return TypeProjectionImpl(ErrorUtils.createErrorType(ErrorTypeKind.NO_RECORDED_TYPE, typeArgumentProto.toString()))
return TypeProjectionImpl(projection, type(type))
}