FIR: Add context receivers from the containing class to constructors
This commit is contained in:
+5
@@ -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
|
||||
|
||||
-15
@@ -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
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
|
||||
context(T) class A<T>
|
||||
|
||||
-18
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user