Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Float default values #13

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion knee-compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

dependencies {
compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable")
implementation("com.squareup:kotlinpoet:1.12.0")
implementation("com.squareup:kotlinpoet:1.18.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
}

Expand Down
4 changes: 2 additions & 2 deletions knee-compiler-plugin/src/main/kotlin/utils/PoetUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ fun IrValueParameter.defaultValueForCodegen(functionExpects: List<IrDeclarationW
return when (val kind = expression.kind) {
is IrConstKind.Null -> CodeBlock.of("null")
is IrConstKind.String -> CodeBlock.of("%S", kind.valueOf(expression))
is IrConstKind.Float -> CodeBlock.of("%LF", kind.valueOf(expression))
is IrConstKind.Long -> CodeBlock.of("%LL", 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())
// is IrConstKind.Double -> CodeBlock.of(kind.valueOf(expression).toString())
// is IrConstKind.Float -> CodeBlock.of(kind.valueOf(expression).toString() + "F")
// is IrConstKind.Long -> CodeBlock.of(kind.valueOf(expression).toString() + "L")
// else -> return null
}
} else if (expression is IrGetEnumValue && type is IrSimpleType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ class DefaultValuesTests {
enumDefaultValue()
}

@Test
fun testDefaultValue_float() {
floatDefaultValue()
}

@Test
fun testDefaultValue_long() {
floatDefaultValue()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ interface BaseInterfaceWithDefaultValues {
fun emptyStringDefaultValue(foo: String = "") {
}

@Knee
fun floatDefaultValue(foo: Float = 1F) {
}

@Knee
fun longDefaultValue(foo: Long = 1000L) {
}

@Knee
fun enumDefaultValue(foo: DefaultValuesEnum = DefaultValuesEnum.First) {
}
Expand Down