Skip to content

Commit

Permalink
Support expect enum class without a body. (#263)
Browse files Browse the repository at this point in the history
Summary:
Currently the parser breaks when encountering these in mutliplatform
projects.

Note that `kotlinc` also supports empty enum definitions.

Pull Request resolved: #263

Reviewed By: davidtorosyan

Differential Revision: D33103316

Pulled By: hick209

fbshipit-source-id: 5fb27fc5f10b8c9d063318f2685467e84947cb85
  • Loading branch information
mpetrov authored and facebook-github-bot committed Dec 20, 2021
1 parent daf9488 commit e1324ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,9 @@ class KotlinInputAstVisitor(
/** Example `{ RED, GREEN; fun foo() { ... } }` for an enum class */
private fun visitEnumBody(enumClass: KtClass) {
val body = enumClass.body
if (body == null) {
return
}
builder.token("{", Doc.Token.RealOrImaginary.REAL, blockIndent, Optional.of(blockIndent))
builder.open(ZERO)
builder.block(blockIndent) {
Expand Down
6 changes: 6 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 @@ -3441,6 +3441,12 @@ class FormatterTest {
|}
|""".trimMargin())

@Test
fun `expect enum class`() =
assertFormatted("""
|expect enum class ExpectedEnum
|""".trimMargin())

@Test
fun `enum without trailing comma`() =
assertFormatted(
Expand Down

0 comments on commit e1324ac

Please sign in to comment.