Skip to content

Commit 79562cd

Browse files
kyay10meta-codesync[bot]
authored andcommitted
Remove forced breaking of contextual function types (Kotlin#613)
Summary: Fixes Kotlin#612 A rather simple change, ultimately. It seems that the previous behaviour was "intentional", but I think it's rather incorrect. Given that this is an experimental feature, I think changing it now is better than waiting for more complaints. Pull Request resolved: Kotlin#613 Reviewed By: cortinico Differential Revision: D105688236 Pulled By: hick209 fbshipit-source-id: 8574d15590ce498df70d07f3c06adbd9bfb44085
1 parent 9d54081 commit 79562cd

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1515
### Added
1616
- Support `ij_kotlin_indent_size` in editorconfig. (https://github.com/facebook/ktfmt/pull/604)
1717
- Support for lists within quoted blocks in KDoc comments (https://github.com/facebook/ktfmt/commit/68fa1585b759ad4b12ca4802bccd297f6a33b0f3)
18-
- Fix `ONLY_ADD` trailing commas strategy causing lines over MAX_WIDTH length (https://github.com/facebook/ktfmt/issues/610)
18+
- Fix `ONLY_ADD` trailing commas strategy causing lines over MAX_WIDTH length (https://github.com/facebook/ktfmt/issues/610)
19+
- Remove forced breaking of `context` function types (https://github.com/facebook/ktfmt/pull/613)
1920

2021
## [0.62]
2122
### Added

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,9 +1820,9 @@ class KotlinInputAstVisitor(
18201820
* Example `context(logger: Logger, raise: Raise<Error>)`
18211821
*
18221822
* Note this also supports the legacy receiver format of `context(Logger, Raise<Error>)` for
1823-
* backward compatibility.
1823+
* backward compatibility and for function types
18241824
*/
1825-
override fun visitContextReceiverList(contextReceiverList: KtContextReceiverList) {
1825+
private fun handleContextReceiverList(contextReceiverList: KtContextReceiverList) {
18261826
builder.sync(contextReceiverList)
18271827
builder.token("context")
18281828
visitEachCommaSeparated(
@@ -1832,6 +1832,10 @@ class KotlinInputAstVisitor(
18321832
breakAfterPrefix = false,
18331833
breakBeforePostfix = false,
18341834
)
1835+
}
1836+
1837+
override fun visitContextReceiverList(contextReceiverList: KtContextReceiverList) {
1838+
handleContextReceiverList(contextReceiverList)
18351839
builder.forcedBreak()
18361840
}
18371841

@@ -2465,7 +2469,10 @@ class KotlinInputAstVisitor(
24652469
override fun visitFunctionType(type: KtFunctionType) {
24662470
builder.sync(type)
24672471

2468-
type.contextReceiverList?.let { visitContextReceiverList(it) }
2472+
type.contextReceiverList?.let {
2473+
handleContextReceiverList(it)
2474+
builder.space()
2475+
}
24692476

24702477
val receiver = type.receiver
24712478
if (receiver != null) {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8571,9 +8571,7 @@ class FormatterTest {
85718571
|
85728572
| fun <T> testSuspend(
85738573
| mock: T,
8574-
| block:
8575-
| suspend context(SomeContext)
8576-
| T.() -> Unit,
8574+
| block: suspend context(SomeContext) T.() -> Unit,
85778575
| ) = startCoroutine { T.block() }
85788576
|}
85798577
|"""
@@ -8629,9 +8627,7 @@ class FormatterTest {
86298627
|
86308628
| fun <T> testSuspend(
86318629
| mock: T,
8632-
| block:
8633-
| suspend context(someContext: SomeContext)
8634-
| T.() -> Unit,
8630+
| block: suspend context(someContext: SomeContext) T.() -> Unit,
86358631
| ) = startCoroutine { T.block() }
86368632
|}
86378633
|"""

0 commit comments

Comments
 (0)