Skip to content

Commit

Permalink
Fix embedded trimIndent call expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyhuo committed Sep 14, 2023
1 parent d4772ab commit f1b225f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kotlin.code.style=official

VERSION_NAME=1.8.20-1.0.0
VERSION_NAME=1.8.20-1.1.0

GROUP=com.bennyhuo.kotlin

Expand Down
4 changes: 2 additions & 2 deletions trimindent-compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {

testImplementation(kotlin("test-junit"))
testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")
testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:1.8.0.0")
testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:1.8.20-1.2.0")
}

val compileKotlin: KotlinCompile by tasks
Expand All @@ -27,4 +27,4 @@ compileKotlin.kotlinOptions.jvmTarget = "1.8"
buildConfig {
packageName("$group.trimindent")
buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${project.property("KOTLIN_PLUGIN_ID")}\"")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TrimIndentIrGenerator : IrGenerationExtension {
val extensionReceiver = irCall.extensionReceiver!!
if (extensionReceiver is IrConst<*> && extensionReceiver.kind == IrConstKind.String) {
extensionReceiver as IrConst<String>
return extensionReceiver.copyWithNewValue(extensionReceiver.value.trimIndent())
return super.visitExpression(extensionReceiver.copyWithNewValue(extensionReceiver.value.trimIndent()))
}

if (extensionReceiver is IrStringConcatenation) {
Expand Down Expand Up @@ -86,7 +86,7 @@ class TrimIndentIrGenerator : IrGenerationExtension {
}
}

return extensionReceiver.copyWithNewValues(args)
return super.visitExpression(extensionReceiver.copyWithNewValues(args))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class TrimIndentTest {
testBase("blankLine.kt")
}

@Test
fun embedded() {
testBase("embedded.kt")
}

private fun testBase(fileName: String) {
val loader = FileBasedModuleInfoLoader("testData/$fileName")
val sourceModuleInfos = loader.loadSourceModuleInfos()
Expand Down
78 changes: 78 additions & 0 deletions trimindent-compiler/testData/embedded.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SOURCE
// FILE: Main.kt [MainKt#main]
fun main() {
val list = listOf(1, 2, 3)
val list2 = listOf("a", "b", "c")
println("""
A:
${list.joinToString("\n") {
"""
- $it
${list2.joinToString("\n") { "* $it" }}
""".trimIndent()
}}
B:
${
list.joinToString("\n") {
"""
- $it
${list2.joinToString("\n") { "* $it" }}
""".trimIndent()
}
}
""".trimIndent())
}
// EXPECT
// FILE: MainKt.main.stdout
A:
- 1
* a
* b
* c
- 2
* a
* b
* c
- 3
* a
* b
* c
B:
- 1
* a
* b
* c
- 2
* a
* b
* c
- 3
* a
* b
* c
// FILE: Main.kt.ir
fun main() {
val list = listOf(1, 2, 3)
val list2 = listOf("a", "b", "c")
println("A:\n${list.joinToString(
separator = "\n"
) { it: Int ->
"- $it \n${list2.joinToString(
separator = "\n"
) { it: String ->
"* $it"
}
.prependIndent(" ")}"
}
.prependIndent(" ")}\nB: \n${list.joinToString(
separator = "\n"
) { it: Int ->
"- $it \n${list2.joinToString(
separator = "\n"
) { it: String ->
"* $it"
}
.prependIndent(" ")}"
}
.prependIndent(" ")}")
}

0 comments on commit f1b225f

Please sign in to comment.