Fix nullable strings in kotlin#50
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Kotlin type-name generator to correctly support nullable strings (DataType.stringNullable) and adds a regression test, while also enabling the Foojay toolchain resolver in Gradle settings.
Changes:
- Add Foojay toolchain resolver convention plugin to
settings.gradle.kts. - Update
GetTypeNameUseCaseto mapstringNullableto KotlinString(with?appended viacanBeNull). - Add a unit test to validate
DataType.stringNullablerenders asString?.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| settings.gradle.kts | Adds Foojay toolchain resolver plugin configuration. |
| cgen-lib/src/main/kotlin/generators/kotlin/GetTypeNameUseCase.kt | Extends the Kotlin type mapping to include stringNullable. |
| cgen-lib/src/test/java/generators/kotlin/GetTypeNameUseCaseTest.kt | Adds a test asserting nullable string maps to String?. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| DataType.float64, DataType.float64Nullable -> "Double" | ||
| DataType.bool, DataType.boolNullable -> "Boolean" | ||
| is DataType.string -> "String" | ||
| is DataType.string, DataType.stringNullable -> "String" |
There was a problem hiding this comment.
The when branch mixes a type-check (is DataType.string) with a value match (DataType.stringNullable) in the same condition list, which won’t compile. Since string/stringNullable are singleton objects, match them consistently (e.g., DataType.string, DataType.stringNullable -> "String"), or use is for both.
| is DataType.string, DataType.stringNullable -> "String" | |
| DataType.string, DataType.stringNullable -> "String" |
| val getArrayDataTypeUseCase = GetArrayDataTypeUseCase() | ||
| val useCase = GetTypeNameUseCase(getArrayDataTypeUseCase) |
There was a problem hiding this comment.
These helper fields are declared as public vals; in the existing tests in this package they’re typically private val to avoid leaking test internals and to align with JUnit test style in this codebase.
| val getArrayDataTypeUseCase = GetArrayDataTypeUseCase() | |
| val useCase = GetTypeNameUseCase(getArrayDataTypeUseCase) | |
| private val getArrayDataTypeUseCase = GetArrayDataTypeUseCase() | |
| private val useCase = GetTypeNameUseCase(getArrayDataTypeUseCase) |
| import generators.obj.syntaxParseTree.FileDataImpl | ||
| import org.junit.jupiter.api.Assertions | ||
| import org.junit.jupiter.api.Test |
There was a problem hiding this comment.
To match the surrounding Kotlin tests in this module, consider using a static import (Assertions.assertEquals -> import org.junit.jupiter.api.Assertions.assertEquals) and calling assertEquals(...) directly for consistency.
No description provided.