ktfmt icon indicating copy to clipboard operation
ktfmt copied to clipboard

Cannot handle formatting `context` keyword

Open Elforama opened this issue 2 years ago • 3 comments

When using context for context receivers, the formatter throws the following error:

error: expected token: 'context'; generated ( instead

The code it highlights for the error is:

val viewEffectMap: MutableMap<KClass<out ViewEffect>, context(Context, View) (effect: ViewEffect) -> Unit> = mutableMapOf()

This breaks usage of using this context receiver feature with formatting.

Elforama avatar Oct 19 '23 22:10 Elforama

I am seeing this with

public interface A<T> {
    
    // ...
     
    @SomeAnnotation
    public infix fun someFun(block: context(SomeScope<T>) T.() -> Unit): T = invoke(block)
}

JavierSegoviaCordoba avatar Dec 27 '23 10:12 JavierSegoviaCordoba

@bddckr, do you plan to maintain the context receivers/params integration next year?

JavierSegoviaCordoba avatar Dec 27 '23 10:12 JavierSegoviaCordoba

@JavierSegoviaCordoba Sorry for the late reply.

My team continues using ktfmt and context receivers, so I will keep the minimum working. I know there will likely be a few changes to stay current with the Kotlin changes.

However, I'm stretched a bit thin for at least the next half a year. Therefore, I may not get around to anything but the bare minimum. Someone else may be interested in getting more done - more test scenarios and more features should be covered in ktfmt eventually for context receivers/parameters.

bddckr avatar Jan 24 '24 14:01 bddckr

Fixed by https://github.com/facebook/ktfmt/commit/dafd1cbb34a049fd8606213f16ea63569f8e3d05

hick209 avatar Jun 12 '24 14:06 hick209