[Analysis API FE10] fix suspend function type mapping
diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeSystemCommonBackendContextForTypeMapping.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeSystemCommonBackendContextForTypeMapping.kt
index efe80fe..c430ae3 100644
--- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeSystemCommonBackendContextForTypeMapping.kt
+++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/KtFe10TypeSystemCommonBackendContextForTypeMapping.kt
@@ -5,6 +5,7 @@
 
 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.functions.FunctionClassDescriptor
 import org.jetbrains.kotlin.descriptors.*
@@ -14,6 +15,7 @@
 import org.jetbrains.kotlin.types.*
 import org.jetbrains.kotlin.types.checker.ClassicTypeSystemContext
 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.ErrorUtils
 import org.jetbrains.kotlin.types.model.KotlinTypeMarker
@@ -75,6 +77,9 @@
     }
 
     override fun TypeConstructorMarker.typeWithArguments(arguments: List<KotlinTypeMarker>): SimpleTypeMarker {
+        if (this is ErrorTypeConstructor) {
+            return ErrorUtils.createErrorType(kind, this, *formatParams)
+        }
         require(this is TypeConstructor)
         require(parameters.size == arguments.size)
 
@@ -110,10 +115,10 @@
         val continuationFqName = StandardClassIds.Continuation.asSingleFqName()
         val foundClasses = resolveSession.getTopLevelClassifierDescriptors(continuationFqName, NoLookupLocation.FROM_IDE)
         return foundClasses.firstOrNull()?.typeConstructor
-            ?: ErrorUtils.createErrorTypeConstructor(ErrorTypeKind.NOT_FOUND_FQNAME, continuationFqName.toString())
+            ?: FAKE_CONTINUATION_CLASS_DESCRIPTOR.typeConstructor
     }
 
     override fun functionNTypeConstructor(n: Int): TypeConstructorMarker {
-        return builtIns.getKFunction(n).typeConstructor
+        return builtIns.getFunction(n).typeConstructor
     }
 }
diff --git a/analysis/analysis-api/testData/components/psiTypeProvider/psiType/forDeclaration/suspendFunctionValueParameterNoStdlib.descriptors.txt b/analysis/analysis-api/testData/components/psiTypeProvider/psiType/forDeclaration/suspendFunctionValueParameterNoStdlib.descriptors.txt
new file mode 100644
index 0000000..20efb1b
--- /dev/null
+++ b/analysis/analysis-api/testData/components/psiTypeProvider/psiType/forDeclaration/suspendFunctionValueParameterNoStdlib.descriptors.txt
@@ -0,0 +1,2 @@
+KtType: suspend (kotlin.Int) -> kotlin.Unit
+PsiType: PsiType:Function2<? super Integer, ? super Continuation<? super Unit>, ? extends Object>
diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/suspendFunctionTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/suspendFunctionTypes.kt
index 0c4632f..31d030a 100644
--- a/core/descriptors/src/org/jetbrains/kotlin/builtins/suspendFunctionTypes.kt
+++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/suspendFunctionTypes.kt
@@ -22,7 +22,10 @@
 import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
 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(
         EmptyPackageFragmentDescriptor(ErrorUtils.errorModule, COROUTINES_PACKAGE_FQ_NAME),
         ClassKind.INTERFACE, /* isInner = */ false, /* isExternal = */ false,
@@ -51,9 +54,6 @@
             suspendFunType.getValueParameterTypesFromFunctionType().map(TypeProjection::getType) +
                 KotlinTypeFactory.simpleType(
                     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,
                     listOf(suspendFunType.getReturnTypeFromFunctionType().asTypeProjection()), nullable = false
                 ),
diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorTypeConstructor.kt
index e022dc7..ee20e36 100644
--- a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorTypeConstructor.kt
+++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorTypeConstructor.kt
@@ -14,7 +14,7 @@
 import org.jetbrains.kotlin.types.TypeRefinement
 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))
 
     fun getParam(i: Int): String = formatParams[i]