Skip to content

Commit

Permalink
Support empty strings in default values (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
natario1 authored Aug 19, 2024
1 parent b3928c7 commit a7843f1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion knee-compiler-plugin/src/main/kotlin/utils/PoetUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fun IrValueParameter.defaultValueForCodegen(functionExpects: List<IrDeclarationW
if (expression is IrConst<*>) {
return when (val kind = expression.kind) {
is IrConstKind.Null -> CodeBlock.of("null")
is IrConstKind.String -> CodeBlock.of(kind.valueOf(expression))
is IrConstKind.String -> CodeBlock.of("%S", kind.valueOf(expression))
else -> CodeBlock.of("%L", kind.valueOf(expression))
// is IrConstKind.Boolean -> CodeBlock.of(kind.valueOf(expression).toString())
// is IrConstKind.Int -> CodeBlock.of(kind.valueOf(expression).toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ class DefaultValuesTests {
ConcreteClassWithDefaultValues().withNull()
}

@Test
fun testDefaultValue_emptyString() {
emptyStringDefaultValue()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ interface BaseInterfaceWithDefaultValues {
override fun withNull(foo: Int?) {

}
}

@Knee
fun emptyStringDefaultValue(foo: String = "") {
}

0 comments on commit a7843f1

Please sign in to comment.