-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
/** 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 = |
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.
The staticOnly parameter isn't used
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.
Oops, I forgot to save.
sym.info.member(nme.main).hasAltWith { | ||
case x: SymDenotation => isMainMethod(x) | ||
case x: SymDenotation => isMainMethod(x) && (!staticOnly || x.isStatic) |
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.
What's the benefit of having a staticOnly parameter instead of directly checking sym.is(Module)
here ?
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.
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. |
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.
Should this comment be moved to hasMainMethod
where the test is performed?
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.
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.
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.
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.
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.
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
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.
@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.
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 think this is good as is.
No description provided.