[Analysis API FE10] fix suspend function type mapping
This commit is contained in:
+7
-2
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.analysis.api.descriptors.utils
|
package org.jetbrains.kotlin.analysis.api.descriptors.utils
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.builtins.FAKE_CONTINUATION_CLASS_DESCRIPTOR
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
@@ -14,6 +15,7 @@ import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
|||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.checker.ClassicTypeSystemContext
|
import org.jetbrains.kotlin.types.checker.ClassicTypeSystemContext
|
||||||
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
||||||
|
import org.jetbrains.kotlin.types.error.ErrorTypeConstructor
|
||||||
import org.jetbrains.kotlin.types.error.ErrorTypeKind
|
import org.jetbrains.kotlin.types.error.ErrorTypeKind
|
||||||
import org.jetbrains.kotlin.types.error.ErrorUtils
|
import org.jetbrains.kotlin.types.error.ErrorUtils
|
||||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||||
@@ -75,6 +77,9 @@ internal class KtFe10TypeSystemCommonBackendContextForTypeMapping(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun TypeConstructorMarker.typeWithArguments(arguments: List<KotlinTypeMarker>): SimpleTypeMarker {
|
override fun TypeConstructorMarker.typeWithArguments(arguments: List<KotlinTypeMarker>): SimpleTypeMarker {
|
||||||
|
if (this is ErrorTypeConstructor) {
|
||||||
|
return ErrorUtils.createErrorType(kind, this, *formatParams)
|
||||||
|
}
|
||||||
require(this is TypeConstructor)
|
require(this is TypeConstructor)
|
||||||
require(parameters.size == arguments.size)
|
require(parameters.size == arguments.size)
|
||||||
|
|
||||||
@@ -110,10 +115,10 @@ internal class KtFe10TypeSystemCommonBackendContextForTypeMapping(
|
|||||||
val continuationFqName = StandardClassIds.Continuation.asSingleFqName()
|
val continuationFqName = StandardClassIds.Continuation.asSingleFqName()
|
||||||
val foundClasses = resolveSession.getTopLevelClassifierDescriptors(continuationFqName, NoLookupLocation.FROM_IDE)
|
val foundClasses = resolveSession.getTopLevelClassifierDescriptors(continuationFqName, NoLookupLocation.FROM_IDE)
|
||||||
return foundClasses.firstOrNull()?.typeConstructor
|
return foundClasses.firstOrNull()?.typeConstructor
|
||||||
?: ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.NOT_FOUND_FQNAME, continuationFqName.toString())
|
?: FAKE_CONTINUATION_CLASS_DESCRIPTOR.typeConstructor
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun functionNTypeConstructor(n: Int): TypeConstructorMarker {
|
override fun functionNTypeConstructor(n: Int): TypeConstructorMarker {
|
||||||
return builtIns.getKFunction(n).typeConstructor
|
return builtIns.getFunction(n).typeConstructor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
KtType: suspend (kotlin.Int) -> kotlin.Unit
|
||||||
|
PsiType: PsiType:Function2<? super Integer, ? super Continuation<? super Unit>, ? extends Object>
|
||||||
@@ -22,7 +22,10 @@ import org.jetbrains.kotlin.types.error.ErrorUtils
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
|
|
||||||
private val FAKE_CONTINUATION_CLASS_DESCRIPTOR =
|
// Continuation interface is not a part of built-ins anymore, it has been moved to stdlib.
|
||||||
|
// While it must be somewhere in the dependencies, but here we don't have a reference to the module,
|
||||||
|
// and it's rather complicated to inject it by now, so we just use a fake class descriptor.
|
||||||
|
val FAKE_CONTINUATION_CLASS_DESCRIPTOR =
|
||||||
MutableClassDescriptor(
|
MutableClassDescriptor(
|
||||||
EmptyPackageFragmentDescriptor(ErrorUtils.errorModule, COROUTINES_PACKAGE_FQ_NAME),
|
EmptyPackageFragmentDescriptor(ErrorUtils.errorModule, COROUTINES_PACKAGE_FQ_NAME),
|
||||||
ClassKind.INTERFACE, /* isInner = */ false, /* isExternal = */ false,
|
ClassKind.INTERFACE, /* isInner = */ false, /* isExternal = */ false,
|
||||||
@@ -51,9 +54,6 @@ fun transformSuspendFunctionToRuntimeFunctionType(suspendFunType: KotlinType): S
|
|||||||
suspendFunType.getValueParameterTypesFromFunctionType().map(TypeProjection::getType) +
|
suspendFunType.getValueParameterTypesFromFunctionType().map(TypeProjection::getType) +
|
||||||
KotlinTypeFactory.simpleType(
|
KotlinTypeFactory.simpleType(
|
||||||
TypeAttributes.Empty,
|
TypeAttributes.Empty,
|
||||||
// Continuation interface is not a part of built-ins anymore, it has been moved to stdlib.
|
|
||||||
// While it must be somewhere in the dependencies, but here we don't have a reference to the module,
|
|
||||||
// and it's rather complicated to inject it by now, so we just use a fake class descriptor.
|
|
||||||
FAKE_CONTINUATION_CLASS_DESCRIPTOR.typeConstructor,
|
FAKE_CONTINUATION_CLASS_DESCRIPTOR.typeConstructor,
|
||||||
listOf(suspendFunType.getReturnTypeFromFunctionType().asTypeProjection()), nullable = false
|
listOf(suspendFunType.getReturnTypeFromFunctionType().asTypeProjection()), nullable = false
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.types.TypeConstructor
|
|||||||
import org.jetbrains.kotlin.types.TypeRefinement
|
import org.jetbrains.kotlin.types.TypeRefinement
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||||
|
|
||||||
class ErrorTypeConstructor(val kind: ErrorTypeKind, private vararg val formatParams: String) : TypeConstructor {
|
class ErrorTypeConstructor(val kind: ErrorTypeKind, vararg val formatParams: String) : TypeConstructor {
|
||||||
private val debugText = ErrorEntity.ERROR_TYPE.debugText.format(kind.debugMessage.format(*formatParams))
|
private val debugText = ErrorEntity.ERROR_TYPE.debugText.format(kind.debugMessage.format(*formatParams))
|
||||||
|
|
||||||
fun getParam(i: Int): String = formatParams[i]
|
fun getParam(i: Int): String = formatParams[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user