summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2016-05-16 16:24:50 -0700
committerSom Snytt <som.snytt@gmail.com>2016-05-16 21:08:44 -0700
commit73ca44be579e5100706d174f18025fc4487e9cb9 (patch)
treec68b732b86ac053419d859b8cb107b24bac4586b /src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
parentb3f8332cf399cd15067c879c8297c25598045883 (diff)
downloadscala-73ca44be579e5100706d174f18025fc4487e9cb9.tar.gz
scala-73ca44be579e5100706d174f18025fc4487e9cb9.tar.bz2
scala-73ca44be579e5100706d174f18025fc4487e9cb9.zip
SI-4625 Recognize App in script
Cheap name test: if the script object extends "App", take it for a main-bearing parent. Note that if `-Xscript` is not `Main`, the default, then the source is taken as a snippet and there is no attempt to locate an existing `main` method.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index c04d305f9e..7af5c505de 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -380,11 +380,15 @@ self =>
case DefDef(_, nme.main, Nil, List(_), _, _) => true
case _ => false
}
+ def isApp(t: Tree) = t match {
+ case Template(ps, _, _) => ps.exists { case Ident(x) if x.decoded == "App" => true ; case _ => false }
+ case _ => false
+ }
/* For now we require there only be one top level object. */
var seenModule = false
val newStmts = stmts collect {
case t @ Import(_, _) => t
- case md @ ModuleDef(mods, name, template) if !seenModule && (md exists isMainMethod) =>
+ case md @ ModuleDef(mods, name, template) if !seenModule && (isApp(template) || md.exists(isMainMethod)) =>
seenModule = true
/* This slightly hacky situation arises because we have no way to communicate
* back to the scriptrunner what the name of the program is. Even if we were