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

Adding support for overriding functions in Kotlin #738

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

emarteca
Copy link
Contributor

@emarteca emarteca commented Dec 3, 2024

Adding support for override for generated kotlin functions that have the compatible signature of the function they should be overriding.
Right now just adding support for overriding toString.
This means that, if a Kotlin function with the signature fun toString(): String is generated, override is added to it so that it overrides the default toString.

This is specifically useful for allowing default printing of objects. If a Kotlin Result has an error type that overrides toString, then that toString is called to display the error, which is much more useful than the default toString that just prints the object address. With this PR, we can customize what's printed with the toString if the Result has a Rust-backed error type (by writing a valid to_string on the Rust side).

@emarteca emarteca marked this pull request as ready for review December 3, 2024 01:42
Copy link
Contributor

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not opposed to this way of solving this, but we already have the stringifier attribute, can we use that and have any method with stringifier automatically have its signature set to override fun toString()?

@emarteca
Copy link
Contributor Author

emarteca commented Dec 3, 2024

Oh, good point! I didn't find the stringifier attribute, I'll use that instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants