Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1820,9 +1820,9 @@ class KotlinInputAstVisitor(
* Example `context(logger: Logger, raise: Raise<Error>)`
*
* Note this also supports the legacy receiver format of `context(Logger, Raise<Error>)` for
* backward compatibility.
* backward compatibility and for function types
*/
override fun visitContextReceiverList(contextReceiverList: KtContextReceiverList) {
private fun handleContextReceiverList(contextReceiverList: KtContextReceiverList) {
builder.sync(contextReceiverList)
builder.token("context")
visitEachCommaSeparated(
Expand All @@ -1832,6 +1832,10 @@ class KotlinInputAstVisitor(
breakAfterPrefix = false,
breakBeforePostfix = false,
)
}

override fun visitContextReceiverList(contextReceiverList: KtContextReceiverList) {
handleContextReceiverList(contextReceiverList)
builder.forcedBreak()
}

Expand Down Expand Up @@ -2465,7 +2469,10 @@ class KotlinInputAstVisitor(
override fun visitFunctionType(type: KtFunctionType) {
builder.sync(type)

type.contextReceiverList?.let { visitContextReceiverList(it) }
type.contextReceiverList?.let {
handleContextReceiverList(it)
builder.space()
}

val receiver = type.receiver
if (receiver != null) {
Expand Down
8 changes: 2 additions & 6 deletions core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8571,9 +8571,7 @@ class FormatterTest {
|
| fun <T> testSuspend(
| mock: T,
| block:
| suspend context(SomeContext)
| T.() -> Unit,
| block: suspend context(SomeContext) T.() -> Unit,
| ) = startCoroutine { T.block() }
|}
|"""
Expand Down Expand Up @@ -8629,9 +8627,7 @@ class FormatterTest {
|
| fun <T> testSuspend(
| mock: T,
| block:
| suspend context(someContext: SomeContext)
| T.() -> Unit,
| block: suspend context(someContext: SomeContext) T.() -> Unit,
| ) = startCoroutine { T.block() }
|}
|"""
Expand Down