'SuspendFunction$n' should not be visible in member scopes (should be unresolved).
'SuspendFunction$n' class descriptors are created on demand by KotlinBuiltIns (and cached). On serialization, types constructed with 'SuspendFunction$n' are written as 'Function$n' with extra flag (SUSPEND_TYPE). On deserialization, corresponding 'SuspendFunction$n' classes are used.
This commit is contained in:
committed by
Stanislav Erokhin
parent
a70ac0160d
commit
80bd916f5d
+17
-1
@@ -17,6 +17,8 @@
|
||||
package org.jetbrains.kotlin.serialization
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
||||
import org.jetbrains.kotlin.builtins.getFunctionalClassKind
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -25,6 +27,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.Interner
|
||||
import java.io.ByteArrayOutputStream
|
||||
@@ -455,12 +458,25 @@ class DescriptorSerializer private constructor(
|
||||
}
|
||||
|
||||
private fun fillFromPossiblyInnerType(builder: ProtoBuf.Type.Builder, type: PossiblyInnerType) {
|
||||
val classifierDescriptor = type.classifierDescriptor
|
||||
val classifierDescriptor: ClassifierDescriptorWithTypeParameters
|
||||
val isSuspendType: Boolean
|
||||
|
||||
val originalClassifierDescriptor = type.classifierDescriptor
|
||||
if (originalClassifierDescriptor.getFunctionalClassKind() == FunctionClassDescriptor.Kind.SuspendFunction) {
|
||||
classifierDescriptor = originalClassifierDescriptor.builtIns.getFunction(originalClassifierDescriptor.declaredTypeParameters.size)
|
||||
isSuspendType = true
|
||||
}
|
||||
else {
|
||||
classifierDescriptor = originalClassifierDescriptor
|
||||
isSuspendType = false
|
||||
}
|
||||
|
||||
val classifierId = getClassifierId(classifierDescriptor)
|
||||
when (classifierDescriptor) {
|
||||
is ClassDescriptor -> builder.className = classifierId
|
||||
is TypeAliasDescriptor -> builder.typeAliasName = classifierId
|
||||
}
|
||||
builder.flags = Flags.getTypeFlags(isSuspendType)
|
||||
|
||||
for (projection in type.arguments) {
|
||||
builder.addArgument(typeArgument(projection))
|
||||
|
||||
Vendored
+1
-1
@@ -11,7 +11,7 @@ typealias Test4 = <!WRONG_MODIFIER_TARGET!>suspend<!> Action
|
||||
typealias Test5 = List<suspend () -> Unit>
|
||||
typealias Test6 = <!WRONG_MODIFIER_TARGET!>suspend<!> List<() -> Unit>
|
||||
typealias Test7 = <!WRONG_MODIFIER_TARGET!>suspend<!> SAM
|
||||
typealias Test8 = SuspendFunction0<Unit>
|
||||
typealias Test8 = <!WRONG_MODIFIER_TARGET!>suspend<!> <!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
|
||||
typealias Test9 = suspend (() -> Unit) -> Unit
|
||||
typealias Test10 = suspend (suspend () -> Unit) -> Unit
|
||||
typealias Test11 = suspend () -> (suspend () -> Unit)
|
||||
|
||||
Vendored
+1
-1
@@ -17,5 +17,5 @@ public typealias Test4 = Action
|
||||
public typealias Test5 = kotlin.collections.List<suspend () -> kotlin.Unit>
|
||||
public typealias Test6 = kotlin.collections.List<() -> kotlin.Unit>
|
||||
public typealias Test7 = SAM
|
||||
public typealias Test8 = suspend () -> kotlin.Unit
|
||||
public typealias Test8 = [ERROR : SuspendFunction0<Unit>]<kotlin.Unit>
|
||||
public typealias Test9 = suspend (() -> kotlin.Unit) -> kotlin.Unit
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
typealias Test1 = <!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
|
||||
typealias Test2 = kotlin.<!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
|
||||
typealias Test3 = kotlin.coroutines.<!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
public typealias Test1 = [ERROR : SuspendFunction0<Unit>]<kotlin.Unit>
|
||||
public typealias Test2 = [ERROR : kotlin.SuspendFunction0<Unit>]<kotlin.Unit>
|
||||
public typealias Test3 = [ERROR : kotlin.coroutines.SuspendFunction0<Unit>]<kotlin.Unit>
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
fun test1(): suspend () -> Unit = null!!
|
||||
fun test2(): suspend (Int, String) -> Int = null!!
|
||||
fun test3(): suspend Int.(String) -> Int = null!!
|
||||
fun test4(): List<suspend () -> Unit> = null!!
|
||||
fun test5(): suspend (suspend () -> Unit) -> Unit = null!!
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
public fun test1(): suspend () -> kotlin.Unit
|
||||
public fun test2(): suspend (kotlin.Int, kotlin.String) -> kotlin.Int
|
||||
public fun test3(): suspend kotlin.Int.(kotlin.String) -> kotlin.Int
|
||||
public fun test4(): kotlin.collections.List<suspend () -> kotlin.Unit>
|
||||
public fun test5(): suspend (suspend () -> kotlin.Unit) -> kotlin.Unit
|
||||
@@ -4466,6 +4466,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/noInvokeForSuspendFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("suspendFunctionNIsUnresolved.kt")
|
||||
public void testSuspendFunctionNIsUnresolved() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/suspendFunctionNIsUnresolved.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/tailCalls")
|
||||
|
||||
@@ -4805,6 +4805,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
doTestCompiledKotlin(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SuspendFunction.kt")
|
||||
public void testSuspendFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/SuspendFunction.kt");
|
||||
doTestCompiledKotlin(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Unit.kt")
|
||||
public void testUnit() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt");
|
||||
|
||||
+6
@@ -3038,6 +3038,12 @@ public class LoadKotlinWithTypeTableTestGenerated extends AbstractLoadKotlinWith
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SuspendFunction.kt")
|
||||
public void testSuspendFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/SuspendFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Unit.kt")
|
||||
public void testUnit() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt");
|
||||
|
||||
+6
@@ -3040,6 +3040,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SuspendFunction.kt")
|
||||
public void testSuspendFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/SuspendFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Unit.kt")
|
||||
public void testUnit() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt");
|
||||
|
||||
Reference in New Issue
Block a user