FIR: build functional type for SAM with receiver properly

This commit is contained in:
Jinseong Jeon
2021-01-04 13:25:03 -08:00
committed by Mikhail Glukhikh
parent f618763250
commit d53354057a
8 changed files with 16 additions and 9 deletions
@@ -27,5 +27,5 @@ FILE: extensionCallableReferences.kt
}
public final fun test_1(): R|kotlin/Unit| {
lval extensionValRef: R|kotlin/reflect/KProperty1<B, A>| = Q|B|::R|/extensionVal|
lval extensionFunRef: R|kotlin/reflect/KFunction1<B, A>| = Q|B|::R|/extensionFun|
lval extensionFunRef: R|@ExtensionFunctionType kotlin/reflect/KFunction1<B, A>| = Q|B|::R|/extensionFun|
}
@@ -36,7 +36,7 @@ FILE: referenceToExtension.kt
public final fun test_1(): R|kotlin/Unit| {
lval memberValRef: R|kotlin/reflect/KProperty1<GenericTest.B<*>, GenericTest.A<CapturedType(*)>>| = Q|GenericTest.B|::R|SubstitutionOverride</GenericTest.B.memberVal: R|GenericTest.A<CapturedType(*)>|>|
lval memberFunRef: R|kotlin/reflect/KFunction1<GenericTest.B<*>, GenericTest.A<CapturedType(*)>>| = Q|GenericTest.B|::R|SubstitutionOverride</GenericTest.B.memberFun: R|GenericTest.A<CapturedType(*)>|>|
lval memberFunRef: R|@ExtensionFunctionType kotlin/reflect/KFunction1<GenericTest.B<*>, GenericTest.A<CapturedType(*)>>| = Q|GenericTest.B|::R|SubstitutionOverride</GenericTest.B.memberFun: R|GenericTest.A<CapturedType(*)>|>|
}
public final fun test_2(): R|kotlin/Unit| {
@@ -82,12 +82,12 @@ FILE: referenceToExtension.kt
public final fun test_1(): R|kotlin/Unit| {
lval extensionValRef: R|kotlin/reflect/KProperty1<NoGenericTest.B, NoGenericTest.A>| = Q|NoGenericTest.B|::R|/NoGenericTest.extensionVal|
lval extensionFunRef: R|kotlin/reflect/KFunction1<NoGenericTest.B, NoGenericTest.A>| = Q|NoGenericTest.B|::R|/NoGenericTest.extensionFun|
lval extensionFunRef: R|@ExtensionFunctionType kotlin/reflect/KFunction1<NoGenericTest.B, NoGenericTest.A>| = Q|NoGenericTest.B|::R|/NoGenericTest.extensionFun|
}
public final fun test_2(): R|kotlin/Unit| {
lval memberValRef: R|kotlin/reflect/KProperty1<NoGenericTest.B, NoGenericTest.A>| = Q|NoGenericTest.B|::R|/NoGenericTest.B.memberVal|
lval memberFunRef: R|kotlin/reflect/KFunction1<NoGenericTest.B, NoGenericTest.A>| = Q|NoGenericTest.B|::R|/NoGenericTest.B.memberFun|
lval memberFunRef: R|@ExtensionFunctionType kotlin/reflect/KFunction1<NoGenericTest.B, NoGenericTest.A>| = Q|NoGenericTest.B|::R|/NoGenericTest.B.memberFun|
}
}
@@ -8,7 +8,7 @@ FILE: moreSpecificAmbiguousExtensions.kt
public final fun R|IB|.extFun(x: R|IA|): R|kotlin/Unit| {
}
public final fun test(): R|kotlin/Unit| {
lval extFun1: R|kotlin/reflect/KFunction2<IA, IB, kotlin/Unit>| = Q|IA|::R|/extFun|
lval extFun1: R|@ExtensionFunctionType kotlin/reflect/KFunction2<IA, IB, kotlin/Unit>| = Q|IA|::R|/extFun|
lval extFun2: <ERROR TYPE REF: No result type for initializer> = Q|IB|::<Unresolved reference: extFun>#
}
public final fun testWithExpectedType(): R|kotlin/Unit| {
@@ -34,6 +34,7 @@ class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : A
}
val Empty: ConeAttributes = ConeAttributes(emptyList())
val WithExtensionFunctionType: ConeAttributes = ConeAttributes(listOf(CompilerConeAttributes.ExtensionFunctionType))
internal val WithFlexibleNullability: ConeAttributes = ConeAttributes(listOf(CompilerConeAttributes.FlexibleNullability))
fun create(attributes: List<ConeAttribute<*>>): ConeAttributes {
@@ -78,7 +78,13 @@ fun createFunctionalType(
}
val functionalTypeId = ClassId(kind.packageFqName, kind.numberedClassName(receiverAndParameterTypes.size - 1))
return ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(functionalTypeId), receiverAndParameterTypes.toTypedArray(), isNullable = false)
val attributes = if (receiverType != null) ConeAttributes.WithExtensionFunctionType else ConeAttributes.Empty
return ConeClassLikeTypeImpl(
ConeClassLikeLookupTagImpl(functionalTypeId),
receiverAndParameterTypes.toTypedArray(),
isNullable = false,
attributes = attributes
)
}
fun createKPropertyType(
@@ -346,7 +346,8 @@ private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(): ConeLookupTagB
}
return createFunctionalType(
parameterTypes, receiverType = null,
parameterTypes,
receiverType = receiverTypeRef?.coneType,
rawReturnType = returnTypeRef.coneType,
isSuspend = this.isSuspend
)
@@ -61,7 +61,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
isExtensionFunction: Boolean
): SimpleTypeMarker {
val attributes = if (isExtensionFunction) // TODO: assert correct type constructor
ConeAttributes.create(listOf(CompilerConeAttributes.ExtensionFunctionType))
ConeAttributes.WithExtensionFunctionType
else ConeAttributes.Empty
@Suppress("UNCHECKED_CAST")
return when (constructor) {
@@ -1,6 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: SAM_CONVERSIONS
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR_ES6
fun interface FunWithReceiver {