[AA] KT-55098 Render context receivers in declarations & function types

- `context(...)` is a modifier that must precede annotations and other
  modifiers, so for declarations it is rendered in
  `renderAnnotationsAndModifiers`.
- Ignore `@ContextFunctionTypeParams` in the annotation list of FE10
  types, as the annotation is an implementation detail of context
  receivers in K1 and shouldn't be rendered.

^KT-55098 fixed
This commit is contained in:
Marco Pennekamp
2022-12-02 16:12:07 +01:00
committed by Space Team
parent e2804693bf
commit 2cd16f055a
33 changed files with 380 additions and 30 deletions
@@ -0,0 +1,37 @@
interface Context1
interface Context2<A> {
fun getContextElement(): A
}
class Context2Impl<A>(value: A) : Context2<A> {
override fun getContextElement(): A
val value: A
}
context(Int, String)
class A {
constructor(int: Int)
}
context(Context1, c2@Context2<String>)
class B {
override fun toString(): String
}
context(Context2<A>)
class C<A> {
val a: A
get()
}
context(Context1)
@Deprecated(message = "Use `B` instead.")
class D
context(b@B, `fun`@A)
fun foo()
context(Context2<C<String>>)
fun bar(): ERROR
@@ -0,0 +1,36 @@
interface Context1
interface Context2<A> {
fun getContextElement(): A
}
class Context2Impl<A>(val value: A) : Context2<A> {
override fun getContextElement(): A = value
}
context(Int, String)
class A {
context(Double)
constructor(int: Int) {}
}
context(Context1, c2@Context2<String>)
class B {
override fun toString(): String = getContextElement()
}
context(Context2<A>)
class C<A> {
val a: A
get() = getContextElement()
}
context(Context1)
@Deprecated("Use `B` instead.")
class D
context(b@B, `fun`@A)
fun foo() = Unit
context(Context2<C<String>>)
fun bar() = with (Context2Impl(getContextElement().a)) { C() }
@@ -0,0 +1,37 @@
interface Context1
interface Context2<A> {
fun getContextElement(): A
}
class Context2Impl<A>(value: A) : Context2<A> {
override fun getContextElement(): A
val value: A
}
context(Int, String)
class A {
constructor(int: Int)
}
context(Context1, c2@Context2<String>)
class B {
override fun toString(): String
}
context(Context2<A>)
class C<A> {
val a: A
get()
}
context(Context1)
@Deprecated(message = "Use `B` instead.")
class D
context(b@B, `fun`@A)
fun foo()
context(Context2<C<String>>)
fun bar(): C<String>
@@ -0,0 +1,10 @@
interface A
interface B
val f1: context(A) () -> Unit = { }
val f2: context(B, A) Int.() -> Unit = { }
val f3: (Int) -> (context(A) (String) -> String) = { { "" } }
val f4: (context(A) B.(Int) -> Unit) -> (context(B) (Int) -> Unit) = { { } }
@@ -0,0 +1,11 @@
interface A
interface B
val f1: context(A) () -> Unit
val f2: context(B, A) Int.() -> Unit
val f3: (Int) -> context(A) (String) -> String
val f4: (context(A) B.(Int) -> Unit) -> context(B) (Int) -> Unit