Skip to content

Commit

Permalink
Fix sanitization of keywords (arrow-kt#3016)
Browse files Browse the repository at this point in the history
  • Loading branch information
serras authored Mar 31, 2023
1 parent 0de655c commit 4dfdd62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fun String.plusIfNotBlank(prefix: String = "", postfix: String = "") =
/**
* Sanitizes each delimited section if it matches with Kotlin reserved keywords.
*/
fun KSName.asSanitizedString(delimiter: String = ".", separator: String = delimiter) =
asString().splitToSequence(delimiter).joinToString(separator) { if (kotlinKeywords.contains(it)) "`$it`" else it }
fun KSName.asSanitizedString(delimiter: String = ".") =
asString().splitToSequence(delimiter).joinToString(delimiter) { if (it in kotlinKeywords) "`$it`" else it }


private val kotlinKeywords = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,20 @@ class DSLTests {
""".compilationSucceeds()
}

@Test
fun `DSL for a class in a package including keywords, issue #2996`() {
"""
|package id.co.app_name.features.main.transaction.internal.outgoing.data.OutgoingInternalTransaction
|
|$imports
|
|@optics
|data class Source(val program: String) {
| companion object
|}
|
""".compilationSucceeds()
}

// Db.content.at(At.map(), One).set(db, None)
}

0 comments on commit 4dfdd62

Please sign in to comment.