Skip to content

Commit dafd1cb

Browse files
Nivaldo Bondançafacebook-github-bot
authored andcommitted
Fix issue with context receive in lambdas
Summary: Fixes issue reported by at #471 Formatting might be a bit odd, but the goal of this diff is solely to stop of the issue with running ktfmt. Reviewed By: strulovich Differential Revision: D58194198 fbshipit-source-id: 51123c1b3fef65c2c0803689c9173cb7c50cb41f
1 parent 26a24ae commit dafd1cb

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,9 @@ class KotlinInputAstVisitor(
22902290

22912291
override fun visitFunctionType(type: KtFunctionType) {
22922292
builder.sync(type)
2293+
2294+
type.contextReceiverList?.let { visitContextReceiverList(it) }
2295+
22932296
val receiver = type.receiver
22942297
if (receiver != null) {
22952298
visit(receiver)

core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7199,6 +7199,13 @@ class FormatterTest {
71997199
| context(SomethingElse)
72007200
|
72017201
| private class NestedClass {}
7202+
|
7203+
| fun <T> testSuspend(
7204+
| mock: T,
7205+
| block: suspend context(SomeContext) T.() -> Unit,
7206+
| ) = startCoroutine {
7207+
| T.block()
7208+
| }
72027209
|}
72037210
|"""
72047211
.trimMargin()
@@ -7216,6 +7223,13 @@ class FormatterTest {
72167223
|
72177224
| context(SomethingElse)
72187225
| private class NestedClass {}
7226+
|
7227+
| fun <T> testSuspend(
7228+
| mock: T,
7229+
| block:
7230+
| suspend context(SomeContext)
7231+
| T.() -> Unit,
7232+
| ) = startCoroutine { T.block() }
72197233
|}
72207234
|"""
72217235
.trimMargin()

0 commit comments

Comments
 (0)