-
Notifications
You must be signed in to change notification settings - Fork 139
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
Conversation
36f1ef9
to
e6fae5c
Compare
There was a problem hiding this 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.
modules/build/src/main/scala/scala/build/internal/WrapperUtils.scala
Outdated
Show resolved
Hide resolved
modules/build/src/main/scala/scala/build/internal/ClassCodeWrapper.scala
Outdated
Show resolved
Hide resolved
modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala
Show resolved
Hide resolved
modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala
Show resolved
Hide resolved
modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala
Outdated
Show resolved
Hide resolved
modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala
Outdated
Show resolved
Hide resolved
The object.main() approach provides a migration format that works with all scala versions, so I don't think supporting |
e6fae5c
to
4793fd8
Compare
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
4793fd8
to
8812c89
Compare
There was a problem hiding this 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.
Should help with #3473