Skip to content

Commit

Permalink
Allow static class methods as main methods
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jul 26, 2019
1 parent a40bcfc commit 8b2737d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/dotc/config/JavaPlatform.scala
Expand Up @@ -22,10 +22,13 @@ class JavaPlatform extends Platform {

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

/** Update classpath with a substituted subentry */
def updateClassPath(subst: Map[ClassPath, ClassPath]): Unit = currentClassPath.get match {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala
Expand Up @@ -230,7 +230,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder

allNonLocalClassesInSrc += cl

if (sym.isStatic && defType == DefinitionType.Module && ctx.platform.hasMainMethod(sym)) {
if (sym.isStatic && ctx.platform.hasMainMethod(sym)) {
_mainClasses += name
}

Expand Down

0 comments on commit 8b2737d

Please sign in to comment.