Extension functions & inference.
This commit is contained in:
committed by
Stanislav Erokhin
parent
845e116aa9
commit
eec96f1954
+2
-1
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.inference
|
||||
|
||||
import org.jetbrains.kotlin.builtins.createFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isBuiltinExtensionFunctionalType
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
@@ -435,7 +436,7 @@ internal fun createTypeForFunctionPlaceholder(
|
||||
|
||||
val functionPlaceholderTypeConstructor = functionPlaceholder.constructor as FunctionPlaceholderTypeConstructor
|
||||
|
||||
val isExtension = expectedType.isExtensionFunctionType
|
||||
val isExtension = expectedType.isBuiltinExtensionFunctionalType
|
||||
val newArgumentTypes = if (!functionPlaceholderTypeConstructor.hasDeclaredArguments) {
|
||||
val typeParamSize = expectedType.constructor.parameters.size
|
||||
// the first parameter is receiver (if present), the last one is return type,
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun <T> withS(x: T, sfn: suspend T.() -> Unit) = x
|
||||
|
||||
val test1 = withS(100) {}
|
||||
|
||||
fun <TT> test2(x: TT) = withS(x) {}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
public val test1: kotlin.Int
|
||||
public fun </*0*/ TT> test2(/*0*/ x: TT): TT
|
||||
public fun </*0*/ T> withS(/*0*/ x: T, /*1*/ sfn: suspend T.() -> kotlin.Unit): T
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun <T1, T2> withS2(x: T1, sfn1: suspend T1.() -> T2, sfn2: suspend T2.() -> Unit): T2 = null!!
|
||||
|
||||
val test1 = withS2(100, { toLong().toString() }, { length })
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public val test1: kotlin.String
|
||||
public fun </*0*/ T1, /*1*/ T2> withS2(/*0*/ x: T1, /*1*/ sfn1: suspend T1.() -> T2, /*2*/ sfn2: suspend T2.() -> kotlin.Unit): T2
|
||||
@@ -4431,6 +4431,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inference3.kt")
|
||||
public void testInference3() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference3.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inference4.kt")
|
||||
public void testInference4() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference4.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaInOverriddenValInitializer.kt")
|
||||
public void testLambdaInOverriddenValInitializer() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/lambdaInOverriddenValInitializer.kt");
|
||||
|
||||
@@ -87,9 +87,12 @@ fun isBuiltinFunctionClass(classId: ClassId): Boolean {
|
||||
}
|
||||
|
||||
val KotlinType.isNonExtensionFunctionType: Boolean
|
||||
get() = isBuiltinFunctionalType && !isTypeAnnotatedWithExtensionFunctionType
|
||||
get() = isFunctionType && !isTypeAnnotatedWithExtensionFunctionType
|
||||
|
||||
val KotlinType.isExtensionFunctionType: Boolean
|
||||
get() = isFunctionType && isTypeAnnotatedWithExtensionFunctionType
|
||||
|
||||
val KotlinType.isBuiltinExtensionFunctionalType: Boolean
|
||||
get() = isBuiltinFunctionalType && isTypeAnnotatedWithExtensionFunctionType
|
||||
|
||||
private val KotlinType.isTypeAnnotatedWithExtensionFunctionType: Boolean
|
||||
@@ -137,7 +140,7 @@ fun KotlinType.getReturnTypeFromFunctionType(): KotlinType {
|
||||
fun KotlinType.getValueParameterTypesFromFunctionType(): List<TypeProjection> {
|
||||
assert(isBuiltinFunctionalType) { "Not a function type: ${this}" }
|
||||
val arguments = arguments
|
||||
val first = if (isExtensionFunctionType) 1 else 0
|
||||
val first = if (isBuiltinExtensionFunctionalType) 1 else 0
|
||||
val last = arguments.size - 1
|
||||
assert(first <= last) { "Not an exact function type: ${this}" }
|
||||
return arguments.subList(first, last)
|
||||
|
||||
Reference in New Issue
Block a user