Skip to content

Commit c53f465

Browse files
committed
Allow static class methods as main methods
1 parent a2b6023 commit c53f465

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

compiler/src/dotty/tools/dotc/config/JavaPlatform.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ class JavaPlatform extends Platform {
2222

2323
// The given symbol is a method with the right name and signature to be a runnable java program.
2424
def isMainMethod(sym: SymDenotation)(implicit ctx: Context): Boolean =
25-
(sym.name == nme.main) && (sym.info match {
26-
case MethodTpe(_, defn.ArrayOf(el) :: Nil, restpe) => el =:= defn.StringType && (restpe isRef defn.UnitClass)
27-
case _ => false
28-
})
25+
sym.name == nme.main &&
26+
(sym.owner.is(Module) || sym.owner.isClass && !sym.owner.is(Trait) && sym.is(JavaStatic)) && {
27+
sym.info match {
28+
case MethodTpe(_, defn.ArrayOf(el) :: Nil, restpe) => el =:= defn.StringType && (restpe isRef defn.UnitClass)
29+
case _ => false
30+
}
31+
}
2932

3033
/** Update classpath with a substituted subentry */
3134
def updateClassPath(subst: Map[ClassPath, ClassPath]): Unit = currentClassPath.get match {

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
230230

231231
allNonLocalClassesInSrc += cl
232232

233-
if (sym.isStatic && defType == DefinitionType.Module && ctx.platform.hasMainMethod(sym)) {
233+
if (sym.isStatic && ctx.platform.hasMainMethod(sym)) {
234234
_mainClasses += name
235235
}
236236

0 commit comments

Comments
 (0)