Skip to content

Specify main classes more precisely #6980

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

Merged
merged 3 commits into from
Aug 4, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Aug 2, 2019

No description provided.

/** The given class has a main method.
* @param staticOnly only static main methods count
*/
final def hasMainMethod(sym: Symbol, staticOnly: Boolean = false)(implicit ctx: Context): Boolean =
Copy link
Member

Choose a reason for hiding this comment

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

The staticOnly parameter isn't used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I forgot to save.

sym.info.member(nme.main).hasAltWith {
case x: SymDenotation => isMainMethod(x)
case x: SymDenotation => isMainMethod(x) && (!staticOnly || x.isStatic)
Copy link
Member

Choose a reason for hiding this comment

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

What's the benefit of having a staticOnly parameter instead of directly checking sym.is(Module) here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. We can just test directly.

@@ -230,7 +230,8 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder

allNonLocalClassesInSrc += cl

if (sym.isStatic && ctx.platform.hasMainMethod(sym)) {
if (sym.isStatic && !sym.is(Trait) && ctx.platform.hasMainMethod(sym)) {
// If sym is an object, all main methods count, otherwise only @static ones count.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this comment be moved to hasMainMethod where the test is performed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's another caller of hasMainMethod in the backend. Not knowing what
this does or expects, I am not sure whether the change
is OK or not.

Copy link
Member

Choose a reason for hiding this comment

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

So the other caller is https://github.com/lampepfl/dotty/blob/95ae77c4748bd105de45601875b447ee1fe6a98b/compiler/src/dotty/tools/dotc/transform/CollectEntryPoints.scala#L66-L67
which will emit a warning if there's a main method in an object and also a main method in the companion class of the object, and we do want the warning even if the main method in the companion class is not static, since its mere presence means that the backend will not generate a static forwarder from the main in the object to the companion class.

Copy link
Member

Choose a reason for hiding this comment

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

The situation is very confusing because there's two source files called CollectEntryPoints and none of them actually work, I've made a separate PR to cleanup things a bit: 89801f9

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smarter Do you want to take this over, or should we merge as is? I don't have the time to do more work on this.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

I think this is good as is.

@odersky odersky merged commit 10e3990 into scala:master Aug 4, 2019
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.

3 participants