Skip to content

Commit

Permalink
Fix crash when last superclass entry has a delegate
Browse files Browse the repository at this point in the history
Summary: If the last entry is delegated, there must be a newline or Kotlin doesn't accept it (maybe due to infix methods in the initializer? who knows)

Reviewed By: cgrushko

Differential Revision: D34347730

fbshipit-source-id: 6d6bc460e3474e77c431a262064767638d133c89
  • Loading branch information
strulovich authored and facebook-github-bot committed Feb 20, 2022
1 parent 5e0054a commit 93c7dd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,9 @@ class KotlinInputAstVisitor(
builder.space()
val typeConstraintList = classOrObject.typeConstraintList
if (typeConstraintList != null) {
if (superTypes?.entries?.lastOrNull() is KtDelegatedSuperTypeEntry) {
builder.forcedBreak()
}
visit(typeConstraintList)
builder.space()
}
Expand Down
8 changes: 8 additions & 0 deletions core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,14 @@ class FormatterTest {
| }
|""".trimMargin())

@Test
fun `handle compound generic bounds on class with delegate`() =
assertFormatted(
"""
|class Foo<T>() : Bar by bar
|where T : Qux
|""".trimMargin())

@Test
fun `explicit type on property getter`() =
assertFormatted(
Expand Down

0 comments on commit 93c7dd9

Please sign in to comment.