[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
@@ -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))
}