From 066080066f322dbfda50b88bfb191ebd0a192bf5 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 2 Aug 2019 15:14:52 +0200 Subject: [PATCH 1/3] Specify main classes more precisely --- compiler/src/dotty/tools/dotc/config/Platform.scala | 11 ++++------- compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala | 4 +++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/Platform.scala b/compiler/src/dotty/tools/dotc/config/Platform.scala index 71e0d9cd107c..5df2843ad4dc 100644 --- a/compiler/src/dotty/tools/dotc/config/Platform.scala +++ b/compiler/src/dotty/tools/dotc/config/Platform.scala @@ -1,8 +1,3 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2012 LAMP/EPFL - * @author Paul Phillips - */ - package dotty.tools package dotc package config @@ -41,8 +36,10 @@ abstract class Platform { /** The given symbol is a method with the right name and signature to be a runnable program. */ def isMainMethod(sym: SymDenotation)(implicit ctx: Context): Boolean - /** The given class has a main method. */ - final def hasMainMethod(sym: Symbol)(implicit ctx: Context): Boolean = + /** 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 = sym.info.member(nme.main).hasAltWith { case x: SymDenotation => isMainMethod(x) case _ => false diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala index e9bf617a913f..6e7eededdbdb 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -230,7 +230,9 @@ 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, staticOnly = !sym.is(Module))) { + // If sym is an object, all main methods count, otherwise only @static ones count. _mainClasses += name } From f40e55c60b1a85fa3963746f45680d7fbc7c6088 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 2 Aug 2019 17:08:18 +0200 Subject: [PATCH 2/3] Add missing file --- compiler/src/dotty/tools/dotc/config/Platform.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/config/Platform.scala b/compiler/src/dotty/tools/dotc/config/Platform.scala index 5df2843ad4dc..ef7ba4c64dc6 100644 --- a/compiler/src/dotty/tools/dotc/config/Platform.scala +++ b/compiler/src/dotty/tools/dotc/config/Platform.scala @@ -41,7 +41,7 @@ abstract class Platform { */ final def hasMainMethod(sym: Symbol, staticOnly: Boolean = false)(implicit ctx: Context): Boolean = sym.info.member(nme.main).hasAltWith { - case x: SymDenotation => isMainMethod(x) + case x: SymDenotation => isMainMethod(x) && (!staticOnly || x.isStatic) case _ => false } } From 8a3726716599e367de89ba5d7c388dc2779bc579 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 3 Aug 2019 11:02:47 +0200 Subject: [PATCH 3/3] Drop staticOnly paraaeter --- compiler/src/dotty/tools/dotc/config/Platform.scala | 9 ++++----- compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/Platform.scala b/compiler/src/dotty/tools/dotc/config/Platform.scala index ef7ba4c64dc6..0dfbc060b6a6 100644 --- a/compiler/src/dotty/tools/dotc/config/Platform.scala +++ b/compiler/src/dotty/tools/dotc/config/Platform.scala @@ -7,6 +7,7 @@ import core.Contexts._, core.Symbols._ import core.SymbolLoader import core.SymDenotations.SymDenotation import core.StdNames.nme +import core.Flags.Module /** The platform dependent pieces of Global. */ @@ -36,12 +37,10 @@ abstract class Platform { /** The given symbol is a method with the right name and signature to be a runnable program. */ def isMainMethod(sym: SymDenotation)(implicit ctx: Context): Boolean - /** 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 = + /** The given class has a main method. */ + final def hasMainMethod(sym: Symbol)(implicit ctx: Context): Boolean = sym.info.member(nme.main).hasAltWith { - case x: SymDenotation => isMainMethod(x) && (!staticOnly || x.isStatic) + case x: SymDenotation => isMainMethod(x) && (sym.is(Module) || x.isStatic) case _ => false } } diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala index 6e7eededdbdb..cd3ff9ec6249 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -230,8 +230,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder allNonLocalClassesInSrc += cl - if (sym.isStatic && !sym.is(Trait) && - ctx.platform.hasMainMethod(sym, staticOnly = !sym.is(Module))) { + if (sym.isStatic && !sym.is(Trait) && ctx.platform.hasMainMethod(sym)) { // If sym is an object, all main methods count, otherwise only @static ones count. _mainClasses += name }