Skip to content

Commit 0660800

Browse files
committed
Specify main classes more precisely
1 parent b3fac38 commit 0660800

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/* NSC -- new Scala compiler
2-
* Copyright 2005-2012 LAMP/EPFL
3-
* @author Paul Phillips
4-
*/
5-
61
package dotty.tools
72
package dotc
83
package config
@@ -41,8 +36,10 @@ abstract class Platform {
4136
/** The given symbol is a method with the right name and signature to be a runnable program. */
4237
def isMainMethod(sym: SymDenotation)(implicit ctx: Context): Boolean
4338

44-
/** The given class has a main method. */
45-
final def hasMainMethod(sym: Symbol)(implicit ctx: Context): Boolean =
39+
/** The given class has a main method.
40+
* @param staticOnly only static main methods count
41+
*/
42+
final def hasMainMethod(sym: Symbol, staticOnly: Boolean = false)(implicit ctx: Context): Boolean =
4643
sym.info.member(nme.main).hasAltWith {
4744
case x: SymDenotation => isMainMethod(x)
4845
case _ => false

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

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

231231
allNonLocalClassesInSrc += cl
232232

233-
if (sym.isStatic && ctx.platform.hasMainMethod(sym)) {
233+
if (sym.isStatic && !sym.is(Trait) &&
234+
ctx.platform.hasMainMethod(sym, staticOnly = !sym.is(Module))) {
235+
// If sym is an object, all main methods count, otherwise only @static ones count.
234236
_mainClasses += name
235237
}
236238

0 commit comments

Comments
 (0)