Skip to content

Commit 10e3990

Browse files
authored
Merge pull request #6980 from dotty-staging/fix-main-class
Specify main classes more precisely
2 parents 36707c7 + 8a37267 commit 10e3990

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

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

Lines changed: 2 additions & 6 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
@@ -12,6 +7,7 @@ import core.Contexts._, core.Symbols._
127
import core.SymbolLoader
138
import core.SymDenotations.SymDenotation
149
import core.StdNames.nme
10+
import core.Flags.Module
1511

1612
/** The platform dependent pieces of Global.
1713
*/
@@ -44,7 +40,7 @@ abstract class Platform {
4440
/** The given class has a main method. */
4541
final def hasMainMethod(sym: Symbol)(implicit ctx: Context): Boolean =
4642
sym.info.member(nme.main).hasAltWith {
47-
case x: SymDenotation => isMainMethod(x)
43+
case x: SymDenotation => isMainMethod(x) && (sym.is(Module) || x.isStatic)
4844
case _ => false
4945
}
5046
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ 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) && ctx.platform.hasMainMethod(sym)) {
234+
// If sym is an object, all main methods count, otherwise only @static ones count.
234235
_mainClasses += name
235236
}
236237

0 commit comments

Comments
 (0)