mirror of
https://github.com/apple/pkl.git
synced 2026-01-13 23:23:37 +01:00
codegen-kotlin: Use same toString() representation for data classes and regular classes #223
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @odenix on GitHub (Oct 21, 2024).
codegen-kotlin generates data classes whenever possible and regular classes otherwise.
For data classes, the default
toString()implementation of data classes is used.Example:
For regular classes, a
toString()method is generated whose output somewhat resembles Pkl syntax.Example:
It would be more consistent to use the same
toString()representation for data classes and regular classes.This could be achieved in one of the following ways:
toString()methods for both data classes and regular classes.toString()methods for regular classes whose output matches that of data classes.(1) enables a
toString()representation that somewhat resembles Pkl syntax, whereas (2) generates less code.PS: codegen-java will face the same issue once it supports records.
@bioball commented on GitHub (Oct 22, 2024):
Good call-out, and agreed that their rendering should be consistent.
My instinct here is to copy the rendering of Kotlin data classes and Java records. These are data objects in the target language, and we don't need to add any special behavior here.
@odenix commented on GitHub (Oct 22, 2024):
Agreed. I'll send a PR after the 0.27 release.