FIR: Add context receivers from the containing class to constructors

This commit is contained in:
Denis.Zharkov
2022-03-09 15:37:53 +03:00
committed by teamcity
parent b2d5bf3eae
commit 202413c2f4
6 changed files with 8 additions and 33 deletions
@@ -528,6 +528,7 @@ class DeclarationsConverter(
)
//parse primary constructor
val primaryConstructorWrapper = convertPrimaryConstructor(
classNode,
primaryConstructor,
selfType.source,
classWrapper,
@@ -670,6 +671,7 @@ class DeclarationsConverter(
)
//parse primary constructor
convertPrimaryConstructor(
objectDeclaration,
primaryConstructor,
delegatedSelfType.source,
classWrapper,
@@ -760,6 +762,7 @@ class DeclarationsConverter(
)
superTypeRefs += enumClassWrapper.delegatedSuperTypeRef
convertPrimaryConstructor(
enumEntry,
null,
enumEntry.toFirSourceElement(),
enumClassWrapper,
@@ -822,6 +825,7 @@ class DeclarationsConverter(
* primaryConstructor branch
*/
private fun convertPrimaryConstructor(
classNode: LighterASTNode,
primaryConstructor: LighterASTNode?,
selfTypeSource: KtSourceElement?,
classWrapper: ClassWrapper,
@@ -896,6 +900,7 @@ class DeclarationsConverter(
this.valueParameters += valueParameters.map { it.firValueParameter }
delegatedConstructor = firDelegatedCall
this.body = null
this.contextReceivers.addAll(convertContextReceivers(classNode))
}.apply {
containingClassForStaticMemberAttr = currentDispatchReceiverType()!!.lookupTag
}, valueParameters
@@ -894,6 +894,7 @@ open class RawFirBuilder(
symbol = FirConstructorSymbol(callableIdForClassConstructor())
delegatedConstructor = firDelegatedCall
typeParameters += constructorTypeParametersFromConstructedClass(ownerTypeParameters)
this.contextReceivers.addAll(convertContextReceivers(owner.contextReceivers))
this@toFirConstructor?.extractAnnotationsTo(this)
this@toFirConstructor?.extractValueParametersTo(this, ValueParameterDeclaration.PRIMARY_CONSTRUCTOR)
this.body = body
@@ -1,15 +0,0 @@
// !LANGUAGE: +ContextReceivers
context(T) class A<T>
context(Collection<P>) class B<P>
fun Int.foo() {
A<Int>()
A<String>()
}
fun Collection<Int>.bar() {
B<Int>()
B<String>()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
context(T) class A<T>
@@ -1,18 +0,0 @@
// !LANGUAGE: +ContextReceivers
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Outer {
val x: Int = 1
}
context(Outer)
class Inner(arg: Any) {
fun bar() = x
}
fun f(outer: Outer) {
Inner(1)
with(outer) {
Inner(3)
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
// !DIAGNOSTICS: -UNUSED_PARAMETER