https://kotlinlang.org logo
#k2-early-adopters
Title
# k2-early-adopters
m

martmists

12/08/2023, 4:04 PM
I'm noticing that in K1, context receivers are placed before the function definition. Are there any plans to change this in K2? It leads to code that seems a bit confusing like
Copy code
context(Something)
@Annotation
fun myFunction() { ... }
especially with how intellij colors
context
the same as other keywords
plus one 1
s

s3rius

12/08/2023, 7:30 PM
You mean that it's placed before annotations?
k

kirillrakhman

12/09/2023, 11:32 AM
The canonical way to write this would be
Copy code
@Annotation
context(Something)
fun myFunction() { ... }
Not sure if being able to place the annotation in the middle is a bug or a feature. Did you write the function yourself or did the IDE generate it, e.g. for an override?
m

martmists

12/10/2023, 12:10 AM
This is the current behavior in K1:
whereas this is perfectly fine
k

kirillrakhman

12/13/2023, 12:09 PM
Could you please report an issue, this seems to be a bug.
m

martmists

12/13/2023, 2:50 PM
Seems already reported as KT-51258
k

kirillrakhman

12/13/2023, 2:51 PM
Correct, thank you.
j

Javier

12/13/2023, 4:49 PM
I still would like to know if annotating
context
is a valid use case too
You can annotate parameters individually, but you cannot annotate the group of them. So allowing annotating
context
could break the coherence there
k

kirillrakhman

12/13/2023, 4:51 PM
I don't think it's intended to be able to annotate the whole group. Most likely, the annotation will just be applied to the function/property.
👍 1