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

improvement: Detect objects with main class in scripts #3479

Merged
merged 2 commits into from
Feb 14, 2025

Conversation

tgodzik
Copy link
Member

@tgodzik tgodzik commented Feb 5, 2025

Should help with #3473

Copy link
Contributor

@Gedochao Gedochao left a comment

Choose a reason for hiding this comment

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

I like the solution itself, especially as it solves a lot of use cases, even though it doesn't solve the problem fully. I left some comments on how I think we could improve this.

In the context of #3473, it's perhaps good to point out that this only fixes things for objects with a main method, but not for @main annotated methods which are top-level.

cc @philwalk, in case you have any thoughts on this.

@Gedochao Gedochao added the needs-minor-release This change should require a minor version bump. label Feb 10, 2025
@philwalk
Copy link
Contributor

this only fixes things for objects with a main method, but not for @main annotated methods which are top-level.

The object.main() approach provides a migration format that works with all scala versions, so I don't think supporting @main annotated methods is necessary.

@Gedochao Gedochao added this to the v1.7.0 milestone Feb 11, 2025
@tgodzik tgodzik force-pushed the detect-mains-inscript branch from e6fae5c to 4793fd8 Compare February 12, 2025 12:04
Prebiously, if user had a legacy script with main method then it would not be picked up at all. Now, when we detect the correct signature we try to run it.

This will work in case of `def main..` and when object extends App

The possibility of false positives is pretty low, since user would have to have their own App, String or Array types. We will also only use that object if there are no toplevel statements
@tgodzik tgodzik force-pushed the detect-mains-inscript branch from 4793fd8 to 8812c89 Compare February 12, 2025 12:24
@tgodzik tgodzik marked this pull request as ready for review February 12, 2025 12:24
@tgodzik tgodzik requested a review from Gedochao February 12, 2025 16:20
Copy link
Contributor

@Gedochao Gedochao left a comment

Choose a reason for hiding this comment

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

LGTM, just commented on some warning improvements.
otherwise should be good to merge.

@Gedochao Gedochao merged commit e4df95e into VirtusLab:main Feb 14, 2025
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-minor-release This change should require a minor version bump.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need an option for writing scripts that are compatible across all scala3 versions
3 participants